Module: ArResqueCounterCache::ActiveRecord::AssociationReflectionTweaks

Defined in:
lib/ar-resque-counter-cache/active_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



55
56
57
58
59
60
# File 'lib/ar-resque-counter-cache/active_record.rb', line 55

def self.included(base)
  base.class_eval do
    alias_method_chain :association_class, :async
    alias_method_chain :counter_cache_column, :async
  end
end

Instance Method Details

#association_class_with_asyncObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ar-resque-counter-cache/active_record.rb', line 33

def association_class_with_async
  if macro == :belongs_to && options[:async_counter_cache]
    if options[:polymorphic]
      Associations::AsyncBelongsToPolymorphicAssociation
    else
      Associations::AsyncBelongsToAssociation
    end
  else
    association_class_without_async
  end
end

#counter_cache_column_with_asyncObject



45
46
47
48
49
50
51
52
53
# File 'lib/ar-resque-counter-cache/active_record.rb', line 45

def counter_cache_column_with_async
  if options[:async_counter_cache] == true
    "#{active_record.name.demodulize.underscore.pluralize}_count"
  elsif options[:async_counter_cache]
    options[:async_counter_cache].to_s
  else
    counter_cache_column_without_async
  end
end