Class: RSchema::GenericHashSchema

Inherits:
Struct
  • Object
show all
Defined in:
lib/rschema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#key_subschemaObject

Returns the value of attribute key_subschema

Returns:

  • (Object)

    the current value of key_subschema



137
138
139
# File 'lib/rschema.rb', line 137

def key_subschema
  @key_subschema
end

#value_subschemaObject

Returns the value of attribute value_subschema

Returns:

  • (Object)

    the current value of value_subschema



137
138
139
# File 'lib/rschema.rb', line 137

def value_subschema
  @value_subschema
end

Instance Method Details

#schema_walk(value, mapper) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rschema.rb', line 138

def schema_walk(value, mapper)
  if not value.is_a?(Hash)
    return RSchema::ErrorDetails.new('is not a Hash')
  end

  value.reduce({}) do |accum, (k, v)|
    # walk key
    k_walked, error = RSchema.walk(key_subschema, k, mapper)
    break RSchema::ErrorDetails.new({'has invalid key, where' => error.details}) if error

    # walk value
    v_walked, error = RSchema.walk(value_subschema, v, mapper)
    break RSchema::ErrorDetails.new({k => error.details}) if error

    accum[k_walked] = v_walked
    accum
  end
end