aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorhnatt <hnatt88@gmail.com>2015-10-29 21:52:04 +0200
committerhnatt <hnatt88@gmail.com>2015-10-29 21:52:04 +0200
commit04f1ce7950cb75407eff10bad6df6aa6414df197 (patch)
treed094b6747724690887f494421c9c08f1ece26a74 /actionmailer
parent8c566b9a94c99ef218a0778310ab8ffc306aff1d (diff)
downloadrails-04f1ce7950cb75407eff10bad6df6aa6414df197.tar.gz
rails-04f1ce7950cb75407eff10bad6df6aa6414df197.tar.bz2
rails-04f1ce7950cb75407eff10bad6df6aa6414df197.zip
Refactor out defaults handling from ActionMailer::Base#mail
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb24
1 files changed, 15 insertions, 9 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 9f26a3874c..320e9740e7 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -802,15 +802,7 @@ module ActionMailer
# At the beginning, do not consider class default for content_type
content_type = headers[:content_type]
- # Call all the procs (if any)
- default_values = {}
- self.class.default.each do |k,v|
- default_values[k] = v.is_a?(Proc) ? instance_eval(&v) : v
- end
-
- # Handle defaults
- headers = headers.reverse_merge(default_values)
- headers[:subject] ||= default_i18n_subject
+ headers = apply_defaults(headers)
# Apply charset at the beginning so all fields are properly quoted
m.charset = charset = headers[:charset]
@@ -840,6 +832,20 @@ module ActionMailer
m
end
+ def apply_defaults(headers)
+ default_values = self.class.default.map do |key, value|
+ [
+ key,
+ value.is_a?(Proc) ? instance_eval(&value) : value
+ ]
+ end.to_h
+
+ headers_with_defaults = headers.reverse_merge(default_values)
+ headers_with_defaults[:subject] ||= default_i18n_subject
+ headers_with_defaults
+ end
+ private :apply_defaults
+
protected
# Used by #mail to set the content type of the message.