aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/deprecated_body.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-19 01:15:57 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-19 01:36:07 +0100
commita0374582ff6d403a48b018df666b064f4c261f20 (patch)
treea6d774ef38fd42ee21e3572b3860a7556b5862dc /actionmailer/lib/action_mailer/deprecated_body.rb
parentc7255386cd3d6de037a9b08b635f9ac299608ac4 (diff)
downloadrails-a0374582ff6d403a48b018df666b064f4c261f20.tar.gz
rails-a0374582ff6d403a48b018df666b064f4c261f20.tar.bz2
rails-a0374582ff6d403a48b018df666b064f4c261f20.zip
Bring body(Hash) behavior back.
Diffstat (limited to 'actionmailer/lib/action_mailer/deprecated_body.rb')
-rw-r--r--actionmailer/lib/action_mailer/deprecated_body.rb38
1 files changed, 16 insertions, 22 deletions
diff --git a/actionmailer/lib/action_mailer/deprecated_body.rb b/actionmailer/lib/action_mailer/deprecated_body.rb
index 20b0989a85..5379b33a54 100644
--- a/actionmailer/lib/action_mailer/deprecated_body.rb
+++ b/actionmailer/lib/action_mailer/deprecated_body.rb
@@ -1,15 +1,13 @@
module ActionMailer
# TODO Remove this module all together in a next release. Ensure that super
- # hooks in ActionMailer::Base are removed as well.
+ # hooks and @assigns_set in ActionMailer::Base are removed as well.
module DeprecatedBody
- def self.included(base)
- base.class_eval do
- # Define the body of the message. This is either a Hash (in which case it
- # specifies the variables to pass to the template when it is rendered),
- # or a string, in which case it specifies the actual text of the message.
- adv_attr_accessor :body
- end
- end
+ extend ActionMailer::AdvAttrAccessor
+
+ # Define the body of the message. This is either a Hash (in which case it
+ # specifies the variables to pass to the template when it is rendered),
+ # or a string, in which case it specifies the actual text of the message.
+ adv_attr_accessor :body
def initialize_defaults(method_name)
@body ||= {}
@@ -18,32 +16,28 @@ module ActionMailer
def attachment(params, &block)
if params[:body]
ActiveSupport::Deprecation.warn('attachment :body => "string" is deprecated. To set the body of an attachment ' <<
- 'please use :data instead, like attachment :data => "string".', caller[0,10])
+ 'please use :data instead, like attachment :data => "string"', caller[0,10])
params[:data] = params.delete(:body)
end
end
def create_parts
- if String === @body
- ActiveSupport::Deprecation.warn('body is deprecated. To set the body with a text ' <<
- 'call render(:text => "body").', caller[0,10])
+ if String === @body && !defined?(@assigns_set)
+ ActiveSupport::Deprecation.warn('body(String) is deprecated. To set the body with a text ' <<
+ 'call render(:text => "body")', caller[0,10])
self.response_body = @body
- elsif @body.is_a?(Hash) && !@body.empty?
- ActiveSupport::Deprecation.warn('body is deprecated. To set assigns simply ' <<
- 'use instance variables', caller[0,10])
- @body.each { |k, v| instance_variable_set(:"@#{k}", v) }
+ elsif self.response_body
+ @body = self.response_body
end
end
def render(*args)
options = args.last.is_a?(Hash) ? args.last : {}
if options[:body]
- ActiveSupport::Deprecation.warn(':body is deprecated. To set assigns simply ' <<
- 'use instance variables', caller[0,1])
+ ActiveSupport::Deprecation.warn(':body in render deprecated. Please call body ' <<
+ 'with a hash instead', caller[0,1])
- options.delete(:body).each do |k, v|
- instance_variable_set(:"@#{k}", v)
- end
+ body options.delete(:body)
end
super