Skip to content

Commit 7fddfb5

Browse files
committed
Use mattr_accessor for most things, since they can't be string from ENV variables anyway
1 parent b407f2a commit 7fddfb5

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

lib/solid_errors.rb

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,27 @@ module SolidErrors
1010
mattr_accessor :base_controller_class, default: "::ActionController::Base"
1111
mattr_writer :username
1212
mattr_writer :password
13-
mattr_writer :send_emails
14-
mattr_writer :email_from
15-
mattr_writer :email_to
16-
mattr_writer :email_subject_prefix
17-
mattr_writer :destroy_after
13+
mattr_accessor :send_emails, default: false
14+
mattr_accessor :email_from, default: "[email protected]"
15+
mattr_accessor :email_to
16+
mattr_accessor :email_subject_prefix
17+
mattr_accessor :destroy_after
1818

1919
class << self
2020
# use method instead of attr_accessor to ensure
21-
# this works if variable set after SolidErrors is loaded
21+
# this works if ENV variable set after SolidErrors is loaded
2222
def username
2323
@username ||= ENV["SOLIDERRORS_USERNAME"] || @@username
2424
end
2525

26+
# use method instead of attr_accessor to ensure
27+
# this works if ENV variable set after SolidErrors is loaded
2628
def password
2729
@password ||= ENV["SOLIDERRORS_PASSWORD"] || @@password
2830
end
2931

3032
def send_emails?
31-
@send_emails ||= ENV["SOLIDERRORS_SEND_EMAILS"] || @@send_emails || false
32-
end
33-
34-
def email_from
35-
@email_from ||= ENV["SOLIDERRORS_EMAIL_FROM"] || @@email_from || "[email protected]"
36-
end
37-
38-
def email_to
39-
@email_to ||= ENV["SOLIDERRORS_EMAIL_TO"] || @@email_to
40-
end
41-
42-
def email_subject_prefix
43-
@email_subject_prefix ||= ENV["SOLIDERRORS_EMAIL_SUBJECT_PREFIX"] || @@email_subject_prefix
44-
end
45-
46-
def destroy_after
47-
@destroy_after ||= ENV["SOLIDERRORS_DESTROY_AFTER"] || @@destroy_after
33+
send_emails && email_to.present?
4834
end
4935
end
5036
end

0 commit comments

Comments
 (0)