Module: RTM::Merging::Variant

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

Instance Method Summary collapse

Instance Method Details

#merge(other) ⇒ Object



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/rtm/activerecord/merging.rb', line 282

def merge(other)
  #The procedure for merging two variant items A and B is given below.
  # -> we will instead just modify a

  # 1. Create a new variant item, C.
  # 2. Set C's [value] property to the value of A's [value] property. B's value is equal to that of A and need not be taken into account.
  # 3. Set C's [datatype] property to the value of A's [datatype] property. B's value is equal to that of A and need not be taken into account.
  # 4. 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.
  # -> 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 [variants] property of the topic name item in their [parent] properties, and add C.
  #self.parent.variants.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