diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-26 12:03:32 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-26 12:05:35 +0000 |
commit | 4df9cc29c15634de8de5912d2b40766f04e58c03 (patch) | |
tree | 6c12e7208e685b8e270c1210bc257e7fae2ab376 /actionmailer/lib/action_mailer | |
parent | 7d86352f83079458dd04df2ee5e1b38179c3aac3 (diff) | |
download | rails-4df9cc29c15634de8de5912d2b40766f04e58c03.tar.gz rails-4df9cc29c15634de8de5912d2b40766f04e58c03.tar.bz2 rails-4df9cc29c15634de8de5912d2b40766f04e58c03.zip |
Support underscored symbols in Action Mailer config
We allow the use of underscored symbols to represent classes throughout
other parts of Rails so it seems incongruous that it's not supported in
`register_interceptor` and `register_observer`.
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 5af0217973..76814d336b 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -444,18 +444,31 @@ module ActionMailer 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. + # 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 = (observer.is_a?(String) ? observer.constantize : observer) + delivery_observer = case observer + when String, Symbol + observer.to_s.camelize.constantize + else + observer + end + 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 + # 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. # it will be <tt>constantize</tt>d. def register_interceptor(interceptor) - delivery_interceptor = (interceptor.is_a?(String) ? interceptor.constantize : interceptor) + delivery_interceptor = case interceptor + when String, Symbol + interceptor.to_s.camelize.constantize + else + interceptor + end + Mail.register_interceptor(delivery_interceptor) end |