Module: DataMapper::CounterCacheable::ModelClassMethods
- Defined in:
- lib/dm-counter-cache.rb
Overview
ClassMethods
Instance Method Summary collapse
-
#counter_caches ⇒ Object
defined_counter_cache_callbacks_for?(attribute).
- #define_counter_cache_callbacks_for(relationship, counter_cache_attribute) ⇒ Object
-
#defined_counter_cache_callbacks_for?(attribute) ⇒ Boolean
register_counter_cache_callbacks_for(relationship, counter_cache_attribute).
Instance Method Details
#counter_caches ⇒ Object
defined_counter_cache_callbacks_for?(attribute)
61 62 63 |
# File 'lib/dm-counter-cache.rb', line 61 def counter_caches @_counter_caches ||= {} end |
#define_counter_cache_callbacks_for(relationship, counter_cache_attribute) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/dm-counter-cache.rb', line 48 def define_counter_cache_callbacks_for(relationship, counter_cache_attribute) return if defined_counter_cache_callbacks_for?(counter_cache_attribute) self.after(:create) { adjust_counter_cache_for(relationship, counter_cache_attribute, +1) } self.after(:destroy) { adjust_counter_cache_for(relationship, counter_cache_attribute, -1) } counter_caches[counter_cache_attribute] = true end |
#defined_counter_cache_callbacks_for?(attribute) ⇒ Boolean
register_counter_cache_callbacks_for(relationship, counter_cache_attribute)
57 58 59 |
# File 'lib/dm-counter-cache.rb', line 57 def defined_counter_cache_callbacks_for?(attribute) !counter_caches[attribute].nil? end |