Class: Rico::Map

Inherits:
Collection show all
Defined in:
lib/rico/map.rb

Direct Known Subclasses

CappedSortedMap, SortedMap

Instance Attribute Summary

Attributes included from Object

#bucket, #key

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Collection

#add, #member?, #remove

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

#membersObject

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