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



175
176
177
# File 'lib/rschema.rb', line 175

def key_subschema
  @key_subschema
end

#value_subschemaObject

Returns the value of attribute value_subschema

Returns:

  • (Object)

    the current value of value_subschema



175
176
177
# File 'lib/rschema.rb', line 175

def value_subschema
  @value_subschema
end

Instance Method Details

#inspectObject



195
196
197
# File 'lib/rschema.rb', line 195

def inspect
  "hash_of(#{key_subschema.inspect} => #{value_subschema.inspect})"
end

#schema_walk(value, mapper) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/rschema.rb', line 176

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