diff options
author | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-22 11:10:37 +0100 |
---|---|---|
committer | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-22 11:10:37 +0100 |
commit | bb9d71ff9e537597ff4d5962e7870ad99001f605 (patch) | |
tree | f31fafcde9884a207a9ed9fba5798b8a91ba7248 /actionmailer/lib/action_mailer/deprecated_api.rb | |
parent | 343ac48f45a433b2ef0dc67f9cd9d1245fb5ef2d (diff) | |
download | rails-bb9d71ff9e537597ff4d5962e7870ad99001f605.tar.gz rails-bb9d71ff9e537597ff4d5962e7870ad99001f605.tar.bz2 rails-bb9d71ff9e537597ff4d5962e7870ad99001f605.zip |
Move class methods to deprecated stuff.
Diffstat (limited to 'actionmailer/lib/action_mailer/deprecated_api.rb')
-rw-r--r-- | actionmailer/lib/action_mailer/deprecated_api.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/deprecated_api.rb b/actionmailer/lib/action_mailer/deprecated_api.rb index 32ea4162dc..430b0cef4a 100644 --- a/actionmailer/lib/action_mailer/deprecated_api.rb +++ b/actionmailer/lib/action_mailer/deprecated_api.rb @@ -73,6 +73,37 @@ module ActionMailer alias :controller_path :mailer_name end + module ClassMethods + def respond_to?(method_symbol, include_private = false) #:nodoc: + matches_dynamic_method?(method_symbol) || super + end + + def method_missing(method_symbol, *parameters) #:nodoc: + if match = matches_dynamic_method?(method_symbol) + case match[1] + when 'create' then new(match[2], *parameters).message + when 'deliver' then new(match[2], *parameters).deliver! + when 'new' then nil + else super + end + else + super + end + end + + private + + def matches_dynamic_method?(method_name) #:nodoc: + method_name = method_name.to_s + /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name) + end + end + + def initialize(*) + super() + @mail_was_called = false + end + def render(*args) options = args.last.is_a?(Hash) ? args.last : {} if options[:body] @@ -85,6 +116,23 @@ module ActionMailer super end + def process(method_name, *args) + initialize_defaults(method_name) + super + unless @mail_was_called + # Create e-mail parts + create_parts + + # Set the subject if not set yet + @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name], + :default => method_name.humanize) + + # Build the mail object itself + create_mail + end + end + + # Add a part to a multipart message, with the given content-type. The # part itself is yielded to the block so that other properties (charset, # body, headers, etc.) can be set on it. |