Permalink
Browse files

Remove observers.

Generally, observers aren't used by a lot of people, and they're
arguably not even a good idea in the first place.
  • Loading branch information...
1 parent 5c07be5 commit a0a79bb49aa3565413b858d5147ccd5502583517 @steveklabnik committed Aug 10, 2012
Showing with 13 additions and 1,880 deletions.
  1. +2 −18 actionmailer/lib/action_mailer/base.rb
  2. +0 −1 actionmailer/lib/action_mailer/railtie.rb
  3. +0 −32 actionmailer/test/base_test.rb
  4. +2 −5 actionpack/lib/action_controller/caching.rb
  5. +0 −2 actionpack/lib/action_controller/caching/pages.rb
  6. +0 −113 actionpack/lib/action_controller/caching/sweeping.rb
  7. +0 −1 actionpack/test/abstract_unit.rb
  8. +0 −41 actionpack/test/controller/filters_test.rb
  9. +0 −16 actionpack/test/controller/sweeper_test.rb
  10. +0 −2 activemodel/lib/active_model.rb
  11. +0 −152 activemodel/lib/active_model/observer_array.rb
  12. +0 −374 activemodel/lib/active_model/observing.rb
  13. +0 −220 activemodel/test/cases/observer_array_test.rb
  14. +0 −181 activemodel/test/cases/observing_test.rb
  15. +0 −27 activemodel/test/models/observers.rb
  16. +0 −1 activerecord/lib/active_record.rb
  17. +0 −2 activerecord/lib/active_record/model.rb
  18. +0 −126 activerecord/lib/active_record/observer.rb
  19. +1 −1 activerecord/lib/active_record/persistence.rb
  20. +0 −11 activerecord/lib/active_record/railtie.rb
  21. +3 −6 activerecord/lib/active_record/relation.rb
  22. +0 −15 activerecord/lib/rails/generators/active_record/observer/observer_generator.rb
  23. +0 −4 activerecord/lib/rails/generators/active_record/observer/templates/observer.rb
  24. +1 −1 activerecord/test/cases/dirty_test.rb
  25. +0 −256 activerecord/test/cases/lifecycle_test.rb
  26. +0 −81 activerecord/test/cases/transaction_callbacks_test.rb
  27. +0 −3 guides/code/getting_started/config/application.rb
  28. +1 −1 railties/lib/rails/engine.rb
  29. +0 −2 railties/lib/rails/generators.rb
  30. +1 −1 railties/lib/rails/generators/actions.rb
  31. +2 −2 railties/lib/rails/generators/named_base.rb
  32. +0 −12 railties/lib/rails/generators/rails/observer/USAGE
  33. +0 −7 railties/lib/rails/generators/rails/observer/observer_generator.rb
  34. +0 −13 railties/lib/rails/generators/test_unit/observer/observer_generator.rb
  35. +0 −9 railties/lib/rails/generators/test_unit/observer/templates/unit_test.rb
  36. +0 −53 railties/test/application/configuration_test.rb
  37. +0 −17 railties/test/application/console_test.rb
  38. +0 −22 railties/test/application/rake_test.rb
  39. +0 −22 railties/test/generators/namespaced_generators_test.rb
  40. +0 −27 railties/test/generators/observer_generator_test.rb
@@ -219,14 +219,11 @@ module ActionMailer #:nodoc:
#
# <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
#
- # = Observing and Intercepting Mails
+ # = Intercepting Mails
#
- # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
+ # Action Mailer provides hooks into the Mail interceptor methods. These allow you to
# register classes that are called during the mail delivery life cycle.
#
- # An observer class must implement the <tt>:delivered_email(message)</tt> method which will be
- # called once for every email sent after the email has been sent.
- #
# An interceptor class must implement the <tt>:delivering_email(message)</tt> method which will be
# called before the email is sent, allowing you to make modifications to the email before it hits
# the delivery agents. Your class should make any needed modifications directly to the passed
@@ -389,24 +386,11 @@ class Base < AbstractController::Base
}.freeze
class << self
- # Register one or more Observers which will be notified when mail is delivered.
- def register_observers(*observers)
- observers.flatten.compact.each { |observer| register_observer(observer) }
- end
-
# Register one or more Interceptors which will be called before mail is sent.
def register_interceptors(*interceptors)
interceptors.flatten.compact.each { |interceptor| register_interceptor(interceptor) }
end
- # Register an Observer which will be notified when mail is delivered.
- # Either a class or a string can be passed in as the Observer. If a string is passed in
- # it will be <tt>constantize</tt>d.
- def register_observer(observer)
- delivery_observer = (observer.is_a?(String) ? observer.constantize : observer)
- Mail.register_observer(delivery_observer)
- end
-
# Register an Interceptor which will be called before mail is sent.
# Either a class or a string can be passed in as the Interceptor. If a string is passed in
# it will be <tt>constantize</tt>d.
@@ -29,7 +29,6 @@ class Railtie < Rails::Railtie
include app.routes.mounted_helpers
register_interceptors(options.delete(:interceptors))
- register_observers(options.delete(:observers))
options.each { |k,v| send("#{k}=", v) }
end
@@ -505,38 +505,6 @@ def stub_queue(klass, queue)
# Before and After hooks
- class MyObserver
- def self.delivered_email(mail)
- end
- end
-
- class MySecondObserver
- def self.delivered_email(mail)
- end
- end
-
- test "you can register an observer to the mail object that gets informed on email delivery" do
- ActionMailer::Base.register_observer(MyObserver)
- mail = BaseMailer.welcome
- MyObserver.expects(:delivered_email).with(mail)
- mail.deliver
- end
-
- test "you can register an observer using its stringified name to the mail object that gets informed on email delivery" do
- ActionMailer::Base.register_observer("BaseTest::MyObserver")
- mail = BaseMailer.welcome
- MyObserver.expects(:delivered_email).with(mail)
- mail.deliver
- end
-
- test "you can register multiple observers to the mail object that both get informed on email delivery" do
- ActionMailer::Base.register_observers("BaseTest::MyObserver", MySecondObserver)
- mail = BaseMailer.welcome
- MyObserver.expects(:delivered_email).with(mail)
- MySecondObserver.expects(:delivered_email).with(mail)
- mail.deliver
- end
-
class MyInterceptor
def self.delivering_email(mail)
end
@@ -8,10 +8,10 @@ module ActionController #:nodoc:
# Action Controller affords you three approaches in varying levels of granularity:
# Page, Action, Fragment.
#
- # 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
@@ -35,8 +35,6 @@ module Caching
autoload :Actions
autoload :Fragments
autoload :Pages
- autoload :Sweeper, 'action_controller/caching/sweeping'
- autoload :Sweeping, 'action_controller/caching/sweeping'
end
module ConfigMethods
@@ -60,7 +58,6 @@ def cache_configured?
include ConfigMethods
include Pages, Actions, Fragments
- include Sweeping if defined?(ActiveRecord)
included do
extend ConfigMethods
@@ -32,8 +32,6 @@ module Caching
# end
# end
#
- # Additionally, you can expire caches using Sweepers that act on changes in the model to determine when a cache is supposed to be
- # expired.
module Pages
extend ActiveSupport::Concern
@@ -1,113 +0,0 @@
-module ActionController #:nodoc:
- module Caching
- # Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change.
- # They do this by being half-observers, half-filters and implementing callbacks for both roles. A Sweeper example:
- #
- # 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 <tt>cache_sweeper</tt> 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
@@ -25,7 +25,6 @@
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
@@ -499,18 +499,6 @@ def filter_three
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 @@ def find_except
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
@@ -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
@@ -40,8 +40,6 @@ module ActiveModel
autoload :Model
autoload :Name, 'active_model/naming'
autoload :Naming
- autoload :Observer, 'active_model/observing'
- autoload :Observing
autoload :SecurePassword
autoload :Serialization
autoload :TestCase
Oops, something went wrong.

2 comments on commit a0a79bb

👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍

+1

Please sign in to comment.