Class: Arrest::NestedCollection
- Defined in:
- lib/arrest/attributes/nested_collection.rb
Instance Attribute Summary
Attributes inherited from Attribute
#actions, #dirty, #json_name, #name
Instance Method Summary collapse
- #from_hash(parent, value) ⇒ Object
-
#initialize(name, class_name, options) ⇒ NestedCollection
constructor
A new instance of NestedCollection.
- #to_hash(value) ⇒ Object
Methods inherited from Attribute
#clazz, #clazz=, #dirty?, #dirty_sensitive?, #mutable?, #read_only?
Constructor Details
#initialize(name, class_name, options) ⇒ NestedCollection
Returns a new instance of NestedCollection.
4 5 6 |
# File 'lib/arrest/attributes/nested_collection.rb', line 4 def initialize name, class_name, super name, class_name, end |
Instance Method Details
#from_hash(parent, value) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/arrest/attributes/nested_collection.rb', line 8 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| self.clazz.new(parent.context, v) end end |
#to_hash(value) ⇒ Object
16 17 18 19 20 |
# File 'lib/arrest/attributes/nested_collection.rb', line 16 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 |