Sha256: 9d6a96cdb9d8b1f2505ad38e697898f911b13f161ad7d49cb75b905afd566442

Contents?: true

Size: 695 Bytes

Versions: 10

Compression:

Stored size: 695 Bytes

Contents

require 'rubygems'
gem 'activerecord'
require 'active_record'

module CacheAdvance
  class ActiveRecordSweeper < ::ActiveRecord::Observer

    def self.initialize_observed(classes)
      observe(classes)
    end

    def reload_sweeper
      observed_classes.each do |klass| 
        klass.name.constantize.add_observer(self)
      end
    end

    def after_create(object)
      expire_caches_for(object)
    end

    alias_method :after_update, :after_create
    alias_method :after_destroy, :after_create

    protected
    
    def expire_caches_for(object)
      class_symbol = object.class.name.underscore.to_sym
      CacheAdvance::Caches.expire_for_class(class_symbol)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
aub-cache_advance-1.0.0 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.1 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.2 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.3 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.4 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.5 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.6 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.7 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.8 lib/cache_advance/active_record_sweeper.rb
aub-cache_advance-1.0.9 lib/cache_advance/active_record_sweeper.rb