Class: SuperFinder::CacheSweeper
- Inherits:
-
ActiveRecord::Observer
- Object
- ActiveRecord::Observer
- SuperFinder::CacheSweeper
- Defined in:
- lib/super_finder/cache_sweeper.rb
Instance Method Summary collapse
- #after_create(record) ⇒ Object
- #after_destroy(record) ⇒ Object
- #after_update(record) ⇒ Object
- #observed_classes ⇒ Object
- #refresh_cache!(record) ⇒ Object
Instance Method Details
#after_create(record) ⇒ Object
7 8 9 |
# File 'lib/super_finder/cache_sweeper.rb', line 7 def after_create(record) refresh_cache!(record) end |
#after_destroy(record) ⇒ Object
15 16 17 |
# File 'lib/super_finder/cache_sweeper.rb', line 15 def after_destroy(record) refresh_cache!(record) end |
#after_update(record) ⇒ Object
11 12 13 |
# File 'lib/super_finder/cache_sweeper.rb', line 11 def after_update(record) refresh_cache!(record) end |
#observed_classes ⇒ Object
35 36 37 |
# File 'lib/super_finder/cache_sweeper.rb', line 35 def observed_classes SuperFinder::Config.instance.models.map { |m| eval(m[:klass].name) } end |
#refresh_cache!(record) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/super_finder/cache_sweeper.rb', line 19 def refresh_cache!(record) models, scoper = SuperFinder::Config.instance.models, SuperFinder::Config.instance.scoper = models.find { |m| m[:klass].name == record.class.name } # do not rely on class in dev mode scope_id = nil if [:scope].nil? if scoper && scoper[:column] # looking for a global scope scope_id = record.attributes[scoper[:column].to_s] end end SuperFinder::CacheManager.instance.refresh!(record.class, scope_id) end |