-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathsolid_errors.rb
More file actions
62 lines (51 loc) · 1.7 KB
/
solid_errors.rb
File metadata and controls
62 lines (51 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
require_relative "solid_errors/version"
require_relative "solid_errors/sanitizer"
require_relative "solid_errors/subscriber"
require_relative "solid_errors/engine"
module SolidErrors
mattr_accessor :connects_to
mattr_accessor :base_controller_class, default: "::ActionController::Base"
mattr_writer :username
mattr_writer :password
mattr_accessor :send_emails, default: false
mattr_accessor :email_from, default: "solid_errors@noreply.com"
mattr_accessor :email_to
mattr_accessor :email_subject_prefix
mattr_accessor :destroy_after
mattr_writer :url_helper_name, :url_options
class << self
# use method instead of attr_accessor to ensure
# this works if ENV variable set after SolidErrors is loaded
def username
@username ||= ENV["SOLIDERRORS_USERNAME"] || @@username
end
# use method instead of attr_accessor to ensure
# this works if ENV variable set after SolidErrors is loaded
def password
@password ||= ENV["SOLIDERRORS_PASSWORD"] || @@password
end
def send_emails?
send_emails && email_to.present?
end
def url_helper_name
@url_helper_name ||= detect_url_helper_name
end
def url_options
@url_options ||= detect_url_options
end
private
def find_solid_errors_route
@solid_errors_route ||= Rails.application.routes.routes.find do |r|
r.name&.to_s&.end_with?("solid_errors")
end
end
def detect_url_helper_name
find_solid_errors_route&.name&.to_sym || :solid_errors
end
def detect_url_options
subdomain = find_solid_errors_route&.constraints&.dig(:subdomain)
subdomain.is_a?(String) ? { subdomain: subdomain } : {}
end
end
end