Class: Arrest::NestedCollection

Inherits:
Attribute show all
Defined in:
lib/arrest/attributes/converter.rb

Instance Attribute Summary

Attributes inherited from Attribute

#clazz, #json_name, #name, #read_only

Instance Method Summary collapse

Constructor Details

#initialize(name, read_only, clazz) ⇒ NestedCollection

Returns a new instance of NestedCollection.



8
9
10
# File 'lib/arrest/attributes/converter.rb', line 8

def initialize name, read_only, clazz
  super name, read_only, clazz
end

Instance Method Details

#from_hash(parent, value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/arrest/attributes/converter.rb', line 12

def from_hash(parent, value)
  return nil unless value != nil
  raise "Expected an array but got #{value.class.name}" unless value.is_a?(Array)
  value.map do |v|
    @clazz.new(parent, v)
  end
end

#to_hash(value) ⇒ Object



20
21
22
23
24
# File 'lib/arrest/attributes/converter.rb', line 20

def to_hash value
  return nil unless value != nil
  raise "Expected an array but got #{value.class.name}" unless value.is_a?(Array)
  value.map(&:to_hash)
end