From ea51f0fe046842c855684f5f10c02584879a120b Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Mon, 22 Jul 2013 20:20:41 +0200 Subject: [PATCH] Determine template_args only once per instance --- lib/email/message_builder.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb index 3d0687ee0f4..1c15e19f476 100644 --- a/lib/email/message_builder.rb +++ b/lib/email/message_builder.rb @@ -11,10 +11,23 @@ module Email end class MessageBuilder + attr_reader :template_args def initialize(to, opts=nil) @to = to @opts = opts || {} + + @template_args = {site_name: SiteSetting.title, + base_url: Discourse.base_url, + user_preferences_url: "#{Discourse.base_url}/user_preferences" }.merge!(@opts) + + if @template_args[:url].present? + if allow_reply_by_email? + @template_args[:respond_instructions] = I18n.t('user_notifications.reply_by_email', @template_args) + else + @template_args[:respond_instructions] = I18n.t('user_notifications.visit_link_to_respond', @template_args) + end + end end def subject @@ -35,22 +48,6 @@ module Email body end - def template_args - @template_args ||= { site_name: SiteSetting.title, - base_url: Discourse.base_url, - user_preferences_url: "#{Discourse.base_url}/user_preferences" }.merge!(@opts) - - if @template_args[:url].present? - if allow_reply_by_email? and - @template_args[:respond_instructions] = I18n.t('user_notifications.reply_by_email', @template_args) - else - @template_args[:respond_instructions] = I18n.t('user_notifications.visit_link_to_respond', @template_args) - end - end - - @template_args - end - def build_args { to: @to, subject: subject,