Class: CounterCulture::Reconciler

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(counter, options = {}) ⇒ Reconciler

Returns a new instance of Reconciler.



13
14
15
16
17
18
# File 'lib/counter_culture/reconciler.rb', line 13

def initialize(counter, options={})
  @counter, @options = counter, options

  @changes = []
  @reconciled = false
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



8
9
10
# File 'lib/counter_culture/reconciler.rb', line 8

def changes
  @changes
end

#counterObject (readonly)

Returns the value of attribute counter.



8
9
10
# File 'lib/counter_culture/reconciler.rb', line 8

def counter
  @counter
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/counter_culture/reconciler.rb', line 8

def options
  @options
end

Instance Method Details

#reconcile!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/counter_culture/reconciler.rb', line 20

def reconcile!
  return false if @reconciled

  if options[: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, options, associated_model_class).perform
  end

  @reconciled = true
end