module Impressionist::CounterCache
Attributes
entity[R]
impressionable_class[R]
Private Instance Methods
counter_caching?()
click to toggle source
# File lib/impressionist/counter_cache.rb, line 50 def counter_caching? impressionable_class. impressionist_counter_caching? end
exeception_rescuer() { || ... }
click to toggle source
Returns false, as it is only handling one exeception It would make updatable to fail thereafter it would not try to update cache_counter
# File lib/impressionist/counter_cache.rb, line 59 def exeception_rescuer begin yield rescue ActiveRecord::RecordNotFound exeception_to_log false end end
exeception_to_log()
click to toggle source
# File lib/impressionist/counter_cache.rb, line 68 def exeception_to_log impressionist_log("Couldn't find Widget with id=#{self.impressionable_id}") end
impressionable_counter_cache_updatable?()
click to toggle source
A valid impression must have a valid impressionable class be counter_caching have a record saved in the db then it should give it a try
# File lib/impressionist/counter_cache.rb, line 13 def impressionable_counter_cache_updatable? updatable? && impressionable_try end
impressionable_find()
click to toggle source
# File lib/impressionist/counter_cache.rb, line 42 def impressionable_find exeception_rescuer { @entity = impressionable_class.find(self.impressionable_id) } @entity end
impressionable_try()
click to toggle source
receives an entity(instance of a Model) and then tries to update counter_cache column entity is a impressionable instance model
# File lib/impressionist/counter_cache.rb, line 38 def impressionable_try entity.try(:update_impressionist_counter_cache) end
impressionist_log(str, mode=:error)
click to toggle source
# File lib/impressionist/counter_cache.rb, line 31 def impressionist_log(str, mode=:error) Rails.logger.send(mode.to_s, str) end
set_impressionable_class()
click to toggle source
# File lib/impressionist/counter_cache.rb, line 25 def set_impressionable_class klass = self.impressionable_type || false @impressionable_class = klass. to_s.safe_constantize || false end
updatable?()
click to toggle source
# File lib/impressionist/counter_cache.rb, line 17 def updatable? valid_impressionable_class? && impressionable_find end
valid_impressionable_class?()
click to toggle source
# File lib/impressionist/counter_cache.rb, line 21 def valid_impressionable_class? set_impressionable_class && counter_caching? end