Module: ActionController::Caching::Sweeping::ClassMethods

Defined in:
actionpack/lib/action_controller/caching/sweeping.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#cache_sweeper(*sweepers) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'actionpack/lib/action_controller/caching/sweeping.rb', line 36

def cache_sweeper(*sweepers)
  configuration = sweepers.extract_options!

  sweepers.each do |sweeper|
    ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
    sweeper_instance = (sweeper.is_a?(Symbol) ? Object.const_get(sweeper.to_s.classify) : sweeper).instance

    if sweeper_instance.is_a?(Sweeper)
      around_filter(sweeper_instance, :only => configuration[:only])
    else
      after_filter(sweeper_instance, :only => configuration[:only])
    end
  end
end