Module: Ripple::Conflict::DocumentHooks::ClassMethods
- Defined in:
- lib/ripple/conflict/document_hooks.rb
Instance Attribute Summary collapse
-
#on_conflict_block ⇒ Proc
readonly
The registered conflict handler.
Instance Method Summary collapse
-
#expected_conflicts ⇒ Array<Symbol>
List of properties and associations that are expected to be in conflict.
-
#on_conflict(*expected_conflicts) {|siblings, conflicts| ... } ⇒ Object
Registers a conflict handler for this model.
Instance Attribute Details
#on_conflict_block ⇒ Proc (readonly)
Returns 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_conflicts ⇒ Array<Symbol>
Returns 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.
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 |