From 04f1ce7950cb75407eff10bad6df6aa6414df197 Mon Sep 17 00:00:00 2001 From: hnatt Date: Thu, 29 Oct 2015 21:52:04 +0200 Subject: Refactor out defaults handling from ActionMailer::Base#mail --- actionmailer/lib/action_mailer/base.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'actionmailer') 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. -- cgit v1.2.3