Class: Dry::Types::Hash::Strict

Inherits:
Schema show all
Defined in:
lib/dry/types/hash/schema.rb

Instance Attribute Summary

Attributes inherited from Schema

#member_types

Attributes inherited from Definition

#options, #primitive

Attributes included from Options

#meta, #options

Instance Method Summary collapse

Methods inherited from Schema

#initialize, #try

Methods inherited from Dry::Types::Hash

#schema, #strict, #symbolized

Methods inherited from Definition

[], #failure, #initialize, #name, #primitive?, #result, #success, #try

Methods included from Builder

#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|

Methods included from Options

#initialize, #with

Constructor Details

This class inherits a constructor from Dry::Types::Hash::Schema

Instance Method Details

#call(hash, meth = :call) ⇒ Object Also known as: []



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dry/types/hash/schema.rb', line 67

def call(hash, meth = :call)
  member_types.each_with_object({}) do |(key, type), result|
    begin
      value = hash.fetch(key)
      result[key] = type.__send__(meth, value)
    rescue TypeError
      raise SchemaError.new(key, value)
    rescue KeyError
      raise SchemaKeyError.new(key)
    end
  end
end