diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-11-23 14:29:56 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-11-23 14:29:56 -0700 |
commit | 65a61ab7c370d2894c11ce276725f723a5c9c111 (patch) | |
tree | 8f4fbe5d6b33810cf102346462c43936f98acba7 /actionmailer/lib/action_mailer/base.rb | |
parent | 14314ca18302f18c3d8bb7a63e9f71ac4c2290c2 (diff) | |
parent | ff5fcf65ec1f5963e5168786277eb4437c065524 (diff) | |
download | rails-65a61ab7c370d2894c11ce276725f723a5c9c111.tar.gz rails-65a61ab7c370d2894c11ce276725f723a5c9c111.tar.bz2 rails-65a61ab7c370d2894c11ce276725f723a5c9c111.zip |
Merge pull request #18446 from cloud8421/actionmailer-unregister-interceptor
ActionMailer::Base can unregister interceptor(s).
Diffstat (limited to 'actionmailer/lib/action_mailer/base.rb')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index cbd7cec70f..4c5d959e32 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -441,6 +441,8 @@ module ActionMailer helper ActionMailer::MailHelper + private_class_method :find_class #:nodoc: + class_attribute :default_params self.default_params = { mime_version: "1.0", @@ -460,16 +462,16 @@ module ActionMailer interceptors.flatten.compact.each { |interceptor| register_interceptor(interceptor) } end + # Unregister one or more Interceptors which would be called before mail is sent. + def unregister_interceptors(*interceptors) + interceptors.flatten.compact.each { |interceptor| unregister_interceptor(interceptor) } + end + # Register an Observer which will be notified when mail is delivered. # Either a class, string or symbol can be passed in as the Observer. # If a string or symbol is passed in it will be camelized and constantized. def register_observer(observer) - delivery_observer = case observer - when String, Symbol - observer.to_s.camelize.constantize - else - observer - end + delivery_observer = find_class(observer) Mail.register_observer(delivery_observer) end @@ -478,16 +480,20 @@ module ActionMailer # Either a class, string or symbol can be passed in as the Interceptor. # If a string or symbol is passed in it will be camelized and constantized. def register_interceptor(interceptor) - delivery_interceptor = case interceptor - when String, Symbol - interceptor.to_s.camelize.constantize - else - interceptor - end + delivery_interceptor = find_class(interceptor) Mail.register_interceptor(delivery_interceptor) end + # Unregister a previously registered interceptor. + # Either a class, string or symbol can be passed in as the Interceptor. + # If a string or symbol is passed in it will be camelized and constantized. + def unregister_interceptor(interceptor) + delivery_interceptor = find_class(interceptor) + + Mail.unregister_interceptor(delivery_interceptor) + end + # Returns the name of current mailer. This method is also being used as a path for a view lookup. # If this is an anonymous mailer, this method will return +anonymous+ instead. def mailer_name @@ -841,6 +847,15 @@ module ActionMailer m end + def self.find_class(klass_or_string_or_symbol) + case klass_or_string_or_symbol + when String, Symbol + klass_or_string_or_symbol.to_s.camelize.constantize + else + klass_or_string_or_symbol + end + end + protected # Used by #mail to set the content type of the message. |