module CounterCulture::Extensions
Private Instance Methods
_update_counts_after_create()
click to toggle source
called by after_create callback
# File lib/counter_culture/extensions.rb, line 94 def _update_counts_after_create self.class.after_commit_counter_cache.each do |counter| # increment counter cache counter.change_counter_cache(self, :increment => true) end end
_update_counts_after_destroy()
click to toggle source
called by after_destroy callback
# File lib/counter_culture/extensions.rb, line 102 def _update_counts_after_destroy self.class.after_commit_counter_cache.each do |counter| # decrement counter cache counter.change_counter_cache(self, :increment => false) end end
_update_counts_after_update()
click to toggle source
called by after_update callback
# File lib/counter_culture/extensions.rb, line 110 def _update_counts_after_update self.class.after_commit_counter_cache.each do |counter| # figure out whether the applicable counter cache changed (this can happen # with dynamic column names) counter_cache_name_was = counter.counter_cache_name_for(counter.previous_model(self)) counter_cache_name = counter.counter_cache_name_for(self) if counter.first_level_relation_changed?(self) || (counter.delta_column && counter.attribute_changed?(self, counter.delta_column)) || counter_cache_name != counter_cache_name_was # increment the counter cache of the new value counter.change_counter_cache(self, :increment => true, :counter_column => counter_cache_name) # decrement the counter cache of the old value counter.change_counter_cache(self, :increment => false, :was => true, :counter_column => counter_cache_name_was) end end end
destroyed_for_counter_culture?()
click to toggle source
check if record is soft-deleted
# File lib/counter_culture/extensions.rb, line 130 def destroyed_for_counter_culture? if respond_to?(:paranoia_destroyed?) paranoia_destroyed? elsif defined?(Discard::Model) && self.class.include?(Discard::Model) discarded? else false end end