Class: Rico::Map
- Inherits:
-
Collection
- Object
- Collection
- Rico::Map
- Defined in:
- lib/rico/map.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes included from Object
Class Method Summary collapse
-
.resolve(robject) ⇒ Object
Resolve conflict between one or more RObject siblings.
Instance Method Summary collapse
-
#members ⇒ Object
Obtains the items in the array.
Methods inherited from Collection
Methods included from Object
#data, #exists?, #initialize, #mutate
Class Method Details
.resolve(robject) ⇒ Object
Resolve conflict between one or more RObject siblings
robjects - array of RObjects to merge
Returns a single RObject result or nil
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rico/map.rb', line 20 def self.resolve(robject) siblings = robject.siblings values = siblings.map {|r| (r.data["_values"] || {}) } deletions = siblings.map {|r| Array(r.data["_deletes"]) }.flatten result = values.inject({}) {|res, h| res.merge(h) }.reject {|k,v| deletions.include? k } obj = robject.dup obj.siblings = [obj.siblings.first] obj.data = { "_values" => result, "_deletes" => deletions } obj end |
Instance Method Details
#members ⇒ Object
Obtains the items in the array
Returns the data in the object as an array
9 10 11 12 13 |
# File 'lib/rico/map.rb', line 9 def members assert_type(::Hash) do data["_values"] || {} end end |