From ccecab3ba950a288b61a516bf9b6962e384aae0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
 <rafaelmfranca@gmail.com>
Date: Sun, 14 Oct 2012 20:00:57 -0300
Subject: Remove observers and sweepers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

They was extracted from a plugin.

See https://github.com/rails/rails-observers

[Rafael Mendonça França + Steve Klabnik]
---
 actionpack/lib/action_controller/caching.rb        |   7 +-
 .../lib/action_controller/caching/sweeping.rb      | 116 ---------------------
 actionpack/test/abstract_unit.rb                   |   1 -
 actionpack/test/controller/filters_test.rb         |  41 --------
 actionpack/test/controller/sweeper_test.rb         |  16 ---
 5 files changed, 2 insertions(+), 179 deletions(-)
 delete mode 100644 actionpack/lib/action_controller/caching/sweeping.rb
 delete mode 100644 actionpack/test/controller/sweeper_test.rb

(limited to 'actionpack')

diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index 462f147371..177da1c8a0 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -6,10 +6,10 @@ module ActionController
   # \Caching is a cheap way of speeding up slow applications by keeping the result of
   # calculations, renderings, and database calls around for subsequent requests.
   #
-  # You can read more about each approach and the sweeping assistance by clicking the
+  # You can read more about each approach and the by clicking the
   # modules below.
   #
-  # Note: To turn off all caching and sweeping, set
+  # Note: To turn off all caching, set
   #   config.action_controller.perform_caching = false.
   #
   # == \Caching stores
@@ -30,8 +30,6 @@ module ActionController
 
     eager_autoload do
       autoload :Fragments
-      autoload :Sweeper, 'action_controller/caching/sweeping'
-      autoload :Sweeping, 'action_controller/caching/sweeping'
     end
 
     module ConfigMethods
@@ -54,7 +52,6 @@ module ActionController
 
     include ConfigMethods
     include Fragments
-    include Sweeping if defined?(ActiveRecord)
 
     included do
       extend ConfigMethods
diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb
deleted file mode 100644
index 317ac74b40..0000000000
--- a/actionpack/lib/action_controller/caching/sweeping.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-module ActionController
-  module Caching
-    # Sweepers are the terminators of the caching world and responsible for expiring
-    # caches when Active Record objects change. They do this by being half-observers,
-    # half-filters and implementing callbacks for both roles.
-    #
-    #   class ListSweeper < ActionController::Caching::Sweeper
-    #     observe List, Item
-    #
-    #     def after_save(record)
-    #       list = record.is_a?(List) ? record : record.list
-    #       expire_page(controller: 'lists', action: %w( show public feed ), id: list.id)
-    #       expire_action(controller: 'lists', action: 'all')
-    #       list.shares.each { |share| expire_page(controller: 'lists', action: 'show', id: share.url_key) }
-    #     end
-    #   end
-    #
-    # The sweeper is assigned in the controllers that wish to have its job performed using
-    # the +cache_sweeper+ class method:
-    #
-    #   class ListsController < ApplicationController
-    #     caches_action :index, :show, :public, :feed
-    #     cache_sweeper :list_sweeper, only: [ :edit, :destroy, :share ]
-    #   end
-    #
-    # In the example above, four actions are cached and three actions are responsible for expiring those caches.
-    #
-    # You can also name an explicit class in the declaration of a sweeper, which is needed
-    # if the sweeper is in a module:
-    #
-    #   class ListsController < ApplicationController
-    #     caches_action :index, :show, :public, :feed
-    #     cache_sweeper OpenBar::Sweeper, only: [ :edit, :destroy, :share ]
-    #   end
-    module Sweeping
-      extend ActiveSupport::Concern
-
-      module ClassMethods # :nodoc:
-        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
-      end
-    end
-
-    if defined?(ActiveRecord) and defined?(ActiveRecord::Observer)
-      class Sweeper < ActiveRecord::Observer # :nodoc:
-        attr_accessor :controller
-
-        def initialize(*args)
-          super
-          @controller = nil
-        end
-
-        def before(controller)
-          self.controller = controller
-          callback(:before) if controller.perform_caching
-          true # before method from sweeper should always return true
-        end
-
-        def after(controller)
-          self.controller = controller
-          callback(:after) if controller.perform_caching
-        end
-
-        def around(controller)
-          before(controller)
-          yield
-          after(controller)
-        ensure
-          clean_up
-        end
-
-        protected
-          # gets the action cache path for the given options.
-          def action_path_for(options)
-            Actions::ActionCachePath.new(controller, options).path
-          end
-
-          # Retrieve instance variables set in the controller.
-          def assigns(key)
-            controller.instance_variable_get("@#{key}")
-          end
-
-        private
-          def clean_up
-            # Clean up, so that the controller can be collected after this request
-            self.controller = nil
-          end
-
-          def callback(timing)
-            controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
-            action_callback_method_name     = "#{controller_callback_method_name}_#{controller.action_name}"
-
-            __send__(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
-            __send__(action_callback_method_name)     if respond_to?(action_callback_method_name, true)
-          end
-
-          def method_missing(method, *arguments, &block)
-            return super unless @controller
-            @controller.__send__(method, *arguments, &block)
-          end
-      end
-    end
-  end
-end
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 4f5b2895c9..95bff0a204 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -25,7 +25,6 @@ require 'active_support/dependencies'
 require 'active_model'
 require 'active_record'
 require 'action_controller/caching'
-require 'action_controller/caching/sweeping'
 
 require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
 
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
index d203601771..1c59dd5953 100644
--- a/actionpack/test/controller/filters_test.rb
+++ b/actionpack/test/controller/filters_test.rb
@@ -499,18 +499,6 @@ class FilterTest < ActionController::TestCase
 
   end
 
-  class ::AppSweeper < ActionController::Caching::Sweeper; end
-  class SweeperTestController < ActionController::Base
-    cache_sweeper :app_sweeper
-    def show
-      render :text => 'hello world'
-    end
-
-    def error
-      raise StandardError.new
-    end
-  end
-
   class ImplicitActionsController < ActionController::Base
     before_filter :find_only, :only => :edit
     before_filter :find_except, :except => :edit
@@ -526,35 +514,6 @@ class FilterTest < ActionController::TestCase
     end
   end
 
-  def test_sweeper_should_not_ignore_no_method_error
-    sweeper = ActionController::Caching::Sweeper.send(:new)
-    assert_raise NoMethodError do
-      sweeper.send_not_defined
-    end
-  end
-
-  def test_sweeper_should_not_block_rendering
-    response = test_process(SweeperTestController)
-    assert_equal 'hello world', response.body
-  end
-
-  def test_sweeper_should_clean_up_if_exception_is_raised
-    assert_raise StandardError do
-      test_process(SweeperTestController, 'error')
-    end
-    assert_nil AppSweeper.instance.controller
-  end
-
-  def test_before_method_of_sweeper_should_always_return_true
-    sweeper = ActionController::Caching::Sweeper.send(:new)
-    assert sweeper.before(TestController.new)
-  end
-
-  def test_after_method_of_sweeper_should_always_return_nil
-    sweeper = ActionController::Caching::Sweeper.send(:new)
-    assert_nil sweeper.after(TestController.new)
-  end
-
   def test_non_yielding_around_filters_not_returning_false_do_not_raise
     controller = NonYieldingAroundFilterController.new
     controller.instance_variable_set "@filter_return_value", true
diff --git a/actionpack/test/controller/sweeper_test.rb b/actionpack/test/controller/sweeper_test.rb
deleted file mode 100644
index 0561efc62f..0000000000
--- a/actionpack/test/controller/sweeper_test.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require 'abstract_unit'
-
-
-class SweeperTest < ActionController::TestCase
-
-  class ::AppSweeper < ActionController::Caching::Sweeper; end
-
-  def test_sweeper_should_not_ignore_unknown_method_calls
-    sweeper = ActionController::Caching::Sweeper.send(:new)
-    assert_raise NameError do
-      sweeper.instance_eval do
-        some_method_that_doesnt_exist
-      end
-    end
-  end
-end
-- 
cgit v1.2.3