Module: Gorillib::Model::Reconcilable
- Defined in:
- lib/wu/model/reconcilable.rb
Instance Method Summary collapse
-
#adopt(obj) ⇒ Object
- asks the other object what attributes it has to give, via
#reconcilable_attrs
* if this instance has aadopt_foo
method, calls it; all further action (such as setting the consensus value) is done over there * otherwise, calls adopt_attribute(attr, val) to set the consensus value.
- asks the other object what attributes it has to give, via
- #conflicting_attribute!(attr, this_val, that_val) ⇒ Object
- #reconcilable_attributes ⇒ Object
Instance Method Details
#adopt(obj) ⇒ Object
- asks the other object what attributes it has to give, via
#reconcilable_attrs
- if this instance has a
adopt_foo
method, calls it; all further action (such as setting the consensus value) is done over there - otherwise, calls adopt_attribute(attr, val) to set the consensus value
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wu/model/reconcilable.rb', line 14 def adopt(obj) peace = true obj.reconcilable_attributes.each do |attr, val| if self.respond_to?("adopt_#{attr}") result = self.public_send("adopt_#{attr}", val, obj) else result = adopt_attribute(attr, val) end peace &&= result end peace end |
#conflicting_attribute!(attr, this_val, that_val) ⇒ Object
27 28 29 30 |
# File 'lib/wu/model/reconcilable.rb', line 27 def conflicting_attribute!(attr, this_val, that_val) warn " - conflicting values for #{attr}: had #{this_val.inspect} got #{that_val.inspect}" false end |
#reconcilable_attributes ⇒ Object
5 6 7 |
# File 'lib/wu/model/reconcilable.rb', line 5 def reconcilable_attributes compact_attributes.compact! end |