Module: Ripple::Conflict::DocumentHooks::ClassMethods

Defined in:
lib/ripple/conflict/document_hooks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#on_conflict_blockProc (readonly)

Returns the registered conflict handler.

Returns:

  • (Proc)

    the registered conflict handler



8
9
10
# File 'lib/ripple/conflict/document_hooks.rb', line 8

def on_conflict_block
  @on_conflict_block
end

Instance Method Details

#expected_conflictsArray<Symbol>

Returns list of properties and associations that are expected to be in conflict.

Returns:

  • (Array<Symbol>)

    list of properties and associations that are expected to be in conflict.



40
41
42
# File 'lib/ripple/conflict/document_hooks.rb', line 40

def expected_conflicts
  @expected_conflicts ||= []
end

#on_conflict(*expected_conflicts) {|siblings, conflicts| ... } ⇒ Object

Registers a conflict handler for this model.

The block is instance_eval’d in the context of a partially resolved model instance. Thus, you should apply your resolution logic directly to self. Before calling your block, Ripple attempts some basic resolution on your behalf:

  • Any property or association for which all siblings agree will be set to the common value.

  • created_at will be set to the minimum value.

  • updated_at will be set to the maximum value.

  • All other properties and associations will be set to the default: nil or the default value for a property, nil for a one association, and an empty array for a many association.

Note that any conflict you do not resolve is a potential source of data loss (since ripple sets it to a default such as nil). It is recommended (but not required) that you pass the list of expected conflicts, as that informs ripple of what conflicts your block handles. If it detects conflicts for any other properties or associations, a NotImplementedError will be raised.

Parameters:

  • expected_conflicts (Array<Symbol>)

    the list of properties and associations you expect to be in conflict.

Yields:

  • the conflict handler block

Yield Parameters:

  • siblings (Array<Ripple::Document>)

    the sibling documents

  • conflicts (Array<Symbol>)

    the properties and associations that could not be resolved by ripple’s basic resolution logic.



33
34
35
36
# File 'lib/ripple/conflict/document_hooks.rb', line 33

def on_conflict(*expected_conflicts, &block)
  @expected_conflicts = expected_conflicts
  @on_conflict_block = block
end