Class: ValueObjects::Base::Collection
- Inherits:
-
Object
- Object
- ValueObjects::Base::Collection
- Defined in:
- lib/value_objects/base.rb
Class Method Summary collapse
- .dump(values) ⇒ Object
- .inherited(subclass) ⇒ Object
- .load(values) ⇒ Object
- .new(attributes) ⇒ Object
Class Method Details
.dump(values) ⇒ Object
60 61 62 |
# File 'lib/value_objects/base.rb', line 60 def dump(values) values.map(&:to_hash) if values end |
.inherited(subclass) ⇒ Object
45 46 47 |
# File 'lib/value_objects/base.rb', line 45 def inherited(subclass) subclass.instance_variable_set(:@value_class, subclass.parent) end |
.load(values) ⇒ Object
56 57 58 |
# File 'lib/value_objects/base.rb', line 56 def load(values) (values.blank? ? [] : values.map { |value| @value_class.new(value) }) if values end |
.new(attributes) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/value_objects/base.rb', line 49 def new(attributes) # Data encoded with the 'application/x-www-form-urlencoded' media type cannot represent empty collections. # As a workaround, a dummy item can be added to the collection with it's key set to '-1'. # This dummy item will be ignored when initializing the value collection. attributes.map { |k, v| @value_class.new(v) if k != '-1' }.compact end |