aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/deprecated_body.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-10-21 21:05:55 -0200
committerYehuda Katz <wycats@gmail.com>2009-11-01 02:23:48 +0100
commit418c3f801cd436f011b37fe69059073e69e05084 (patch)
tree6ae84921892f4ee1f056c2f2338f390c795f7325 /actionmailer/lib/action_mailer/deprecated_body.rb
parent03960048616593c249745d1e321dbcc7f0483c76 (diff)
downloadrails-418c3f801cd436f011b37fe69059073e69e05084.tar.gz
rails-418c3f801cd436f011b37fe69059073e69e05084.tar.bz2
rails-418c3f801cd436f011b37fe69059073e69e05084.zip
Another refactoring on AM. body is deprecated, use render instead.
Diffstat (limited to 'actionmailer/lib/action_mailer/deprecated_body.rb')
-rw-r--r--actionmailer/lib/action_mailer/deprecated_body.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/deprecated_body.rb b/actionmailer/lib/action_mailer/deprecated_body.rb
new file mode 100644
index 0000000000..982f098bc5
--- /dev/null
+++ b/actionmailer/lib/action_mailer/deprecated_body.rb
@@ -0,0 +1,44 @@
+module ActionMailer
+ # TODO Remove this module all together in a next release. Ensure that super
+ # hooks 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
+
+ def initialize_defaults(method_name)
+ @body ||= {}
+ 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[7,1])
+ 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[7,1])
+ @body.each { |k, v| instance_variable_set(:"@#{k}", v) }
+ 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])
+
+ options.delete(:body).each do |k, v|
+ instance_variable_set(:"@#{k}", v)
+ end
+ end
+
+ super
+ end
+ end
+end