Created
March 13, 2015 15:09
-
-
Save aflatter/a8951c484c839bd0afd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An empty hash does not result in creating a new instance of the type. | |
# Required because that's what we get back from the relation. | |
class OptionalCoercer | |
def initialize(type) | |
@type = type | |
end | |
def call(value) | |
return unless value | |
value.values.any? ? type.new(value) : nil | |
end | |
def success?(primitive, value) | |
value.is_a?(primitive) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment