diff options
author | hnatt <hnatt88@gmail.com> | 2015-10-29 21:20:08 +0200 |
---|---|---|
committer | hnatt <hnatt88@gmail.com> | 2015-10-29 21:20:08 +0200 |
commit | e71cfc109dd2204efe35f1ffa927bdc08bd9999b (patch) | |
tree | 603dac5921207e10d01522cbd24b86bb33af4d3c /actionmailer | |
parent | 38061a7becdcfb267a37bc200b846196bd32e2b1 (diff) | |
download | rails-e71cfc109dd2204efe35f1ffa927bdc08bd9999b.tar.gz rails-e71cfc109dd2204efe35f1ffa927bdc08bd9999b.tar.bz2 rails-e71cfc109dd2204efe35f1ffa927bdc08bd9999b.zip |
Reduce code duplication in ActionMailer::Base#register_observer and #register_interceptor
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index c9e7f7d0d3..00fa67e460 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -466,30 +466,26 @@ module ActionMailer # 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 - - Mail.register_observer(delivery_observer) + Mail.register_observer(class_from_value(observer)) end # Register an Interceptor which will be called before mail is sent. # 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 - - Mail.register_interceptor(delivery_interceptor) + Mail.register_interceptor(class_from_value(interceptor)) end + def class_from_value(value) + case value + when String, Symbol + value.to_s.camelize.constantize + else + value + end + end + private :class_from_value + # 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 |