Created
March 24, 2016 12:42
-
-
Save flash-gordon/d3e561b3a803f36b3e93 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Dry | |
module Types | |
class Hash < Definition | |
class Safe < Hash | |
def call(hash, meth = :call) | |
member_types.each_with_object({}) do |(key, type), result| | |
if hash.key?(key) | |
result[key] = type.__send__(meth, hash[key]) | |
elsif type.is_a?(Default) | |
result[key] = type.evaluate | |
elsif type.is_a?(Optional) | |
result[key] = type[nil] | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment