~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/lib/action_controller/caching/sweeper.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'active_record'
 
2
 
 
3
module ActionController #:nodoc:
 
4
  module Caching
 
5
    class Sweeper < ActiveRecord::Observer #:nodoc:
 
6
      attr_accessor :controller
 
7
 
 
8
      def before(controller)
 
9
        self.controller = controller
 
10
        callback(:before) if controller.perform_caching
 
11
      end
 
12
 
 
13
      def after(controller)
 
14
        callback(:after) if controller.perform_caching
 
15
        # Clean up, so that the controller can be collected after this request
 
16
        self.controller = nil
 
17
      end
 
18
 
 
19
      protected
 
20
        # gets the action cache path for the given options.
 
21
        def action_path_for(options)
 
22
          ActionController::Caching::Actions::ActionCachePath.path_for(controller, options)
 
23
        end
 
24
 
 
25
        # Retrieve instance variables set in the controller.
 
26
        def assigns(key)
 
27
          controller.instance_variable_get("@#{key}")
 
28
        end
 
29
 
 
30
      private
 
31
        def callback(timing)
 
32
          controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
 
33
          action_callback_method_name     = "#{controller_callback_method_name}_#{controller.action_name}"
 
34
 
 
35
          __send__(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
 
36
          __send__(action_callback_method_name)     if respond_to?(action_callback_method_name, true)
 
37
        end
 
38
 
 
39
        def method_missing(method, *arguments, &block)
 
40
          return if @controller.nil?
 
41
          @controller.__send__(method, *arguments, &block)
 
42
        end
 
43
    end
 
44
  end
 
45
end