@@ -10,6 +10,8 @@ def initialize options = {}
1010 @deliver_emails_to = Array . wrap options [ :deliver_emails_to ]
1111 @subject_prefix = options [ :subject_prefix ] || ''
1212 @forward_emails_to = options . fetch :forward_emails_to
13+ @env_name = options . fetch :env_name , default_env_name
14+ @intercept_mail = options . fetch :intercept_mail? , default_intercept_mail?
1315
1416 add_env_info_to_subject_prefix
1517 sanitize_forward_emails_to
@@ -22,8 +24,13 @@ def delivering_email message
2224
2325 private
2426
27+ attr_reader :env_name
28+ def intercept_mail?
29+ @intercept_mail
30+ end
31+
2532 def normalize_recipients recipients
26- return Array . wrap ( recipients ) if production ?
33+ return Array . wrap ( recipients ) unless intercept_mail ?
2734
2835 return forward_emails_to if deliver_emails_to . empty?
2936
@@ -45,27 +52,27 @@ def add_subject_prefix message
4552 def sanitize_forward_emails_to
4653 self . forward_emails_to = Array . wrap forward_emails_to
4754
48- if forward_emails_to_empty? && ! production ?
55+ if forward_emails_to_empty? && intercept_mail ?
4956 raise "forward_emails_to should not be empty"
5057 end
5158 end
5259
5360 def add_env_info_to_subject_prefix
5461 return if subject_prefix . blank?
5562
56- _prefix = production ? ? subject_prefix : "#{ subject_prefix } #{ env . upcase } "
63+ _prefix = intercept_mail ? ? "#{ subject_prefix } #{ env_name . upcase } " : subject_prefix
5764 self . subject_prefix = "[#{ _prefix } ]"
5865 end
5966
6067 def forward_emails_to_empty?
6168 Array . wrap ( forward_emails_to ) . reject ( &:blank? ) . empty?
6269 end
6370
64- def production ?
65- env . production?
71+ def default_intercept_mail ?
72+ ! Rails . env . production?
6673 end
6774
68- def env
75+ def default_env_name
6976 Rails . env
7077 end
7178 end
0 commit comments