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



156
157
158
# File 'lib/rschema.rb', line 156

def key_subschema
  @key_subschema
end

#value_subschemaObject

Returns the value of attribute value_subschema

Returns:

  • (Object)

    the current value of value_subschema



156
157
158
# File 'lib/rschema.rb', line 156

def value_subschema
  @value_subschema
end

Instance Method Details

#schema_walk(value, mapper) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/rschema.rb', line 157

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

  value.reduce({}) do |accum, (k, v)|
    # walk key
    k_walked, error = RSchema.walk(key_subschema, k, mapper)
    break error.extend_key_path('.keys') if error

    # walk value
    v_walked, error = RSchema.walk(value_subschema, v, mapper)
    break error.extend_key_path(k) if error

    accum[k_walked] = v_walked
    accum
  end
end