Class: Ripple::Conflict::Resolver
- Includes:
- Translation
- Defined in:
- lib/ripple/conflict/resolver.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(robject, model_class) ⇒ Resolver
constructor
A new instance of Resolver.
- #resolve ⇒ Object
- #siblings ⇒ Object
Methods included from Translation
Constructor Details
#initialize(robject, model_class) ⇒ Resolver
Returns a new instance of Resolver.
25 26 27 28 |
# File 'lib/ripple/conflict/resolver.rb', line 25 def initialize(robject, model_class) @robject = robject @model_class = model_class end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/ripple/conflict/resolver.rb', line 8 def document @document end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
8 9 10 |
# File 'lib/ripple/conflict/resolver.rb', line 8 def model_class @model_class end |
Class Method Details
.to_proc ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ripple/conflict/resolver.rb', line 12 def self.to_proc @to_proc ||= lambda do |robject| possible_model_classes = robject.siblings.map { |s| s.data && s.data['_type'] }.compact.uniq return nil unless possible_model_classes.size == 1 resolver = new(robject, possible_model_classes.first.constantize) resolver.resolve resolver.document.robject end end |
Instance Method Details
#resolve ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ripple/conflict/resolver.rb', line 30 def resolve assert_conflict_block basic_resolver.perform assert_no_unexpected_conflicts document.instance_exec(siblings, basic_resolver.remaining_conflicts, &on_conflict_block) document.update_robject end |
#siblings ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ripple/conflict/resolver.rb', line 38 def siblings @siblings ||= @robject.siblings.map do |s| @model_class.send(:instantiate, s).tap do |record| # TODO: make the deleted conditional explicit by putting logic in # RObject to know it has loaded a deleted sibling. # Here we assume it is deleted if the data is nil because # that's the only way we know of that the data can be nil. record.instance_variable_set(:@deleted, true) if s.data.nil? end end end |