Class: Rico::Array

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

Direct Known Subclasses

List, Set

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
31
32
33
34
35
36
# File 'lib/rico/array.rb', line 20

def self.resolve(robject)
  siblings = robject.siblings
  values = siblings.map {|r| Array(r.data["_values"]) }
  deletions = siblings.map {|r| Array(r.data["_deletes"]) }.flatten

  result = []
  values.each do |v|
    result += (v - result)
  end

  result -= deletions

  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/array.rb', line 9

def members
  assert_type(::Array) do
    data["_values"] || []
  end
end