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

Defined in:
lib/action_controller/caching.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#cache_sweeper(*sweepers) ⇒ Object



564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/action_controller/caching.rb', line 564

def cache_sweeper(*sweepers)
  return unless perform_caching
  configuration = sweepers.last.is_a?(Hash) ? sweepers.pop : {}
  sweepers.each do |sweeper|
    ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
    sweeper_instance = Object.const_get(Inflector.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