Class: CounterCulture::Reconciler
- Inherits:
-
Object
- Object
- CounterCulture::Reconciler
- Defined in:
- lib/counter_culture/reconciler.rb
Defined Under Namespace
Classes: Reconciliation
Constant Summary collapse
- ACTIVE_RECORD_VERSION =
Gem.loaded_specs["activerecord"].version
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(counter, options = {}) ⇒ Reconciler
constructor
A new instance of Reconciler.
- #reconcile! ⇒ Object
Constructor Details
#initialize(counter, options = {}) ⇒ Reconciler
Returns a new instance of Reconciler.
15 16 17 18 19 20 |
# File 'lib/counter_culture/reconciler.rb', line 15 def initialize(counter, ={}) @counter, @options = counter, @changes = [] @reconciled = false end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
10 11 12 |
# File 'lib/counter_culture/reconciler.rb', line 10 def changes @changes end |
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
10 11 12 |
# File 'lib/counter_culture/reconciler.rb', line 10 def counter @counter end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/counter_culture/reconciler.rb', line 10 def @options end |
Instance Method Details
#reconcile! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/counter_culture/reconciler.rb', line 22 def reconcile! return false if @reconciled if [:skip_unsupported] return false if (foreign_key_values || (counter_cache_name.is_a?(Proc) && !column_names) || delta_magnitude.is_a?(Proc)) else raise "Fixing counter caches is not supported when using :foreign_key_values; you may skip this relation with :skip_unsupported => true" if foreign_key_values raise "Must provide :column_names option for relation #{relation.inspect} when :column_name is a Proc; you may skip this relation with :skip_unsupported => true" if counter_cache_name.is_a?(Proc) && !column_names raise "Fixing counter caches is not supported when :delta_magnitude is a Proc; you may skip this relation with :skip_unsupported => true" if delta_magnitude.is_a?(Proc) end Array(associated_model_classes).each do |associated_model_class| Reconciliation.new(counter, changes, , associated_model_class).perform end @reconciled = true end |