Module: RTM::Merging::Association

Includes:
MergeReifiable
Defined in:
lib/rtm/activerecord/merging.rb

Instance Method Summary collapse

Instance Method Details

#merge(other) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rtm/activerecord/merging.rb', line 46

def merge(other)
  # The procedure for merging two association items A and B is given below.

  # 1. Create a new association item, C.
  # -> we will instead just modify a

  # 2. Set C's [type] property to the value of A's [type] property. B's value is equal to that of A and need not be taken into account.
  # 3. Set C's [scope] property to the value of A's [scope] property. B's value is equal to that of A and need not be taken into account.
  # 4. Set C's [roles] property to the value of A's [roles] property. B's value is equal to that of A and need not be taken into account.
  # -> nothing to do till here

  # 5. Set C's [reifier] property to the value of A's [reifier] property if it is not null, and to the value of B's [reifier] property if A's property is null. If both A and B have non-null values, the topic items shall be merged, and the topic item resulting from the merge set as the value of C's [reifier] property.
  self.merge_reifiable other

  # 6. Set C's [item identifiers] property to the union of the values of A's and B's [item identifiers] properties.
  self.merge_item_identifiers other

  # 7. Remove A and B from the [associations] property of the topic map item in their [parent] properties, and add C.
  #self.parent.associations.remove other

  # let the wrapper point to the new object
  #other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
  self.merge_rewrap other

  self
end