Module: RTM::Merging::Role
- Includes:
- MergeReifiable
- Defined in:
- lib/rtm/activerecord/merging.rb
Instance Method Summary collapse
Instance Method Details
#merge(other) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rtm/activerecord/merging.rb', line 77 def merge(other) # The procedure for merging two association role items A and B is given below. # -> we will instead just modify a # 1. Create a new association role item, C. # 2. Set C's [player] property to the value of A's [player] property. B's value is equal to that of A and need not be taken into account. # 3. 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. # -> nothing to do till here # 4. 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 # 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. Remove A and B from the [roles] property of the association item in their [parent] properties, and add C. #self.parent.roles.remove other #puts "#{self.parent.object_id} and #{other.parent.object_id}" # 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 |