Class: Apiwork::Contract::Object::Deserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/contract/object/deserializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shape) ⇒ Deserializer

Returns a new instance of Deserializer.



13
14
15
# File 'lib/apiwork/contract/object/deserializer.rb', line 13

def initialize(shape)
  @shape = shape
end

Class Method Details

.deserialize(shape, hash) ⇒ Object



8
9
10
# File 'lib/apiwork/contract/object/deserializer.rb', line 8

def deserialize(shape, hash)
  new(shape).deserialize(hash)
end

Instance Method Details

#deserialize(hash) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/apiwork/contract/object/deserializer.rb', line 17

def deserialize(hash)
  deserialized = hash.dup

  @shape.params.each do |name, param_options|
    next unless deserialized.key?(name)

    value = deserialized[name]

    deserialized[name] = deserialize_value(value, param_options)
  end

  deserialized
end