lib/ripple/conflict/resolver.rb in ripple-1.0.0.beta vs lib/ripple/conflict/resolver.rb in ripple-1.0.0.beta2
- old
+ new
@@ -9,11 +9,11 @@
delegate :expected_conflicts, :on_conflict_block, :to => :model_class
def self.to_proc
@to_proc ||= lambda do |robject|
- possible_model_classes = robject.siblings.map { |s| s.data['_type'] }.uniq
+ 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
@@ -34,10 +34,18 @@
document.instance_exec(siblings, basic_resolver.remaining_conflicts, &on_conflict_block)
document.update_robject
end
def siblings
- @siblings ||= @robject.siblings.map { |s| @model_class.send(:instantiate, s) }
+ @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
def document
# pick a sibling robject to use as the basis of the document to resolve
# which one doesn't really matter.