Skip to content

Commit

Permalink
Remove observers.
Browse files Browse the repository at this point in the history
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
steveklabnik committed Aug 10, 2012
1 parent 5c07be5 commit a0a79bb
Show file tree
Hide file tree
Showing 40 changed files with 13 additions and 1,880 deletions.
20 changes: 2 additions & 18 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion actionmailer/lib/action_mailer/railtie.rb
Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions actionmailer/test/base_test.rb
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions actionpack/lib/action_controller/caching.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -60,7 +58,6 @@ def cache_configured?

include ConfigMethods
include Pages, Actions, Fragments
include Sweeping if defined?(ActiveRecord)

included do
extend ConfigMethods
Expand Down
2 changes: 0 additions & 2 deletions actionpack/lib/action_controller/caching/pages.rb
Expand Up @@ -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

Expand Down
113 changes: 0 additions & 113 deletions actionpack/lib/action_controller/caching/sweeping.rb

This file was deleted.

1 change: 0 additions & 1 deletion actionpack/test/abstract_unit.rb
Expand Up @@ -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

Expand Down
41 changes: 0 additions & 41 deletions actionpack/test/controller/filters_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 0 additions & 16 deletions actionpack/test/controller/sweeper_test.rb

This file was deleted.

2 changes: 0 additions & 2 deletions activemodel/lib/active_model.rb
Expand Up @@ -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
Expand Down

2 comments on commit a0a79bb

@isaacsanders
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@obrok
Copy link

@obrok obrok commented on a0a79bb Aug 10, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.