Class: Dry::Types::Hash::Symbolized

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

Overview

Symbolized hash will turn string key names into symbols.

Instance Attribute Summary

Attributes inherited from Schema

#member_types

Attributes inherited from Definition

#options, #primitive

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from Weak

new, #try

Methods inherited from Schema

#call, #coerce, #initialize, #resolve_missing_value, #try, #try_coerce

Methods included from MaybeTypes

#resolve_missing_value

Methods inherited from Dry::Types::Hash

#permissive, #resolve_missing_value, #schema, #strict, #strict_with_defaults, #symbolized, #weak

Methods inherited from Definition

[], #call, #constrained?, #default?, #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, #meta, #with

Constructor Details

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

Instance Method Details

#resolve(hash) ⇒ Object (private)



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/dry/types/hash/schema.rb', line 206

def resolve(hash)
  result = {}
  member_types.each do |key, type|
    keyname =
      if hash.key?(key)
        key
      elsif hash.key?(string_key = key.to_s)
        string_key
      end

    if keyname
      result[key] = yield(type, key, hash[keyname])
    else
      resolve_missing_value(result, key, type)
    end
  end
  result
end