Class: BugReportsClient::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bug_reports_client/configuration.rb

Overview

Holds all host-app configuration for the engine. Every setting has a sensible default (mostly environment-variable backed) so a typical host only needs to set source in its initializer:

BugReportsClient.configure do |config|
config.source = "myapp"
end

Wording is intentionally NOT configured here - all user-facing copy lives in i18n (see config/locales/en.yml) and form fields are defined in the form schema YAML, so this class only carries behavioural settings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bug_reports_client/configuration.rb', line 53

def initialize
  @api_url = ENV.fetch("BUG_REPORT_API_URL", "http://localhost:3002/api")
  @api_key = ENV["BUG_REPORT_API_KEY"]
  @webhook_secret = ENV["BUG_REPORT_WEBHOOK_SECRET"]
  # A dedicated variable takes precedence: APP_HOST is commonly shared
  # with other host-app concerns (mailers, OIDC issuers) in formats the
  # engine cannot assume, so hosts can isolate the engine with
  # BUG_REPORT_APP_HOST - or set config.app_host explicitly.
  @app_host = ENV["BUG_REPORT_APP_HOST"] || ENV["APP_HOST"]
  @app_name = nil
  @source = nil
  @mount_path = "/bug_reports"
  @callback_url = nil
  @parent_controller = "::ApplicationController"
  @current_user_method = :current_user
  @authenticate_method = :authenticate_user!
  @user_class = "User"
  @reporter_email_method = :email
  @reporter_name_method = :name
  @reporter_external = ->(_user) { false }
  @admin_check = ->(_user) { false }
  @ask_severity = true
  @default_severity = "medium"
  @screenshots_enabled = true
  @max_screenshots = 5
  @screenshot_content_types = %w[image/png image/jpeg image/gif image/webp]
  @max_screenshot_size = 10 * 1024 * 1024
  @form_schema_path = nil
  @issue_template_path = nil
  @error_reporting_enabled = false
  @error_ignore = []
  @error_throttle_period = 300
end

Instance Attribute Details

#admin_checkObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def admin_check
  @admin_check
end

#api_keyObject

Connection to the bug-reports API.



15
16
17
# File 'lib/bug_reports_client/configuration.rb', line 15

def api_key
  @api_key
end

#api_urlObject

Connection to the bug-reports API.



15
16
17
# File 'lib/bug_reports_client/configuration.rb', line 15

def api_url
  @api_url
end

#app_hostObject

Identity of this app. source must match the ApiKey name registered on the API and a key in its repo mapping. app_host is the public HTTPS origin of this app, used to build the callback URL and screenshot links.



20
21
22
# File 'lib/bug_reports_client/configuration.rb', line 20

def app_host
  @app_host
end

#app_nameObject

Identity of this app. source must match the ApiKey name registered on the API and a key in its repo mapping. app_host is the public HTTPS origin of this app, used to build the callback URL and screenshot links.



20
21
22
# File 'lib/bug_reports_client/configuration.rb', line 20

def app_name
  @app_name
end

#ask_severityObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def ask_severity
  @ask_severity
end

#authenticate_methodObject

Integration with the host's controllers and user model. authenticate_method is the host method the engine calls to enforce login. Set it to nil when the parent_controller already authenticates globally (e.g. its own before_action :authenticate_user!, which the engine inherits) so authentication does not run twice per request.



31
32
33
# File 'lib/bug_reports_client/configuration.rb', line 31

def authenticate_method
  @authenticate_method
end

#callback_urlObject

The URL the API calls back when a report's GitHub issue is closed. Must be public HTTPS in production - the API refuses private hosts.



89
90
91
92
93
94
# File 'lib/bug_reports_client/configuration.rb', line 89

def callback_url
  @callback_url || begin
    raise ConfigurationError, "BugReportsClient: set config.app_host (or APP_HOST) so the callback URL can be built" if app_host.blank?
    File.join(app_host, mount_path, "webhook")
  end
end

#current_user_methodObject

Integration with the host's controllers and user model. authenticate_method is the host method the engine calls to enforce login. Set it to nil when the parent_controller already authenticates globally (e.g. its own before_action :authenticate_user!, which the engine inherits) so authentication does not run twice per request.



31
32
33
# File 'lib/bug_reports_client/configuration.rb', line 31

def current_user_method
  @current_user_method
end

#default_severityObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def default_severity
  @default_severity
end

#error_ignoreObject

Automatic error capture (Sentry-style 500 reporting). Opt-in per host; error_ignore lists extra exception class names to skip (classes Rails maps to non-5xx responses are skipped automatically), and the throttle limits how often one fingerprint is posted from this app.



45
46
47
# File 'lib/bug_reports_client/configuration.rb', line 45

def error_ignore
  @error_ignore
end

#error_reporting_enabledObject

Automatic error capture (Sentry-style 500 reporting). Opt-in per host; error_ignore lists extra exception class names to skip (classes Rails maps to non-5xx responses are skipped automatically), and the throttle limits how often one fingerprint is posted from this app.



45
46
47
# File 'lib/bug_reports_client/configuration.rb', line 45

def error_reporting_enabled
  @error_reporting_enabled
end

#error_throttle_periodObject

Automatic error capture (Sentry-style 500 reporting). Opt-in per host; error_ignore lists extra exception class names to skip (classes Rails maps to non-5xx responses are skipped automatically), and the throttle limits how often one fingerprint is posted from this app.



45
46
47
# File 'lib/bug_reports_client/configuration.rb', line 45

def error_throttle_period
  @error_throttle_period
end

#form_schema_pathObject

Optional overrides for the form definition and GitHub issue template. When nil, the engine looks for config/bug_report_form.yml and config/bug_report_issue.md in the host app, then falls back to its own defaults.



51
52
53
# File 'lib/bug_reports_client/configuration.rb', line 51

def form_schema_path
  @form_schema_path
end

#issue_template_pathObject

Optional overrides for the form definition and GitHub issue template. When nil, the engine looks for config/bug_report_form.yml and config/bug_report_issue.md in the host app, then falls back to its own defaults.



51
52
53
# File 'lib/bug_reports_client/configuration.rb', line 51

def issue_template_path
  @issue_template_path
end

#max_screenshot_sizeObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def max_screenshot_size
  @max_screenshot_size
end

#max_screenshotsObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def max_screenshots
  @max_screenshots
end

#mount_pathObject

Where the engine is mounted, used to derive the default callback URL.



23
24
25
# File 'lib/bug_reports_client/configuration.rb', line 23

def mount_path
  @mount_path
end

#parent_controllerObject

Integration with the host's controllers and user model. authenticate_method is the host method the engine calls to enforce login. Set it to nil when the parent_controller already authenticates globally (e.g. its own before_action :authenticate_user!, which the engine inherits) so authentication does not run twice per request.



31
32
33
# File 'lib/bug_reports_client/configuration.rb', line 31

def parent_controller
  @parent_controller
end

#reporter_email_methodObject

Integration with the host's controllers and user model. authenticate_method is the host method the engine calls to enforce login. Set it to nil when the parent_controller already authenticates globally (e.g. its own before_action :authenticate_user!, which the engine inherits) so authentication does not run twice per request.



31
32
33
# File 'lib/bug_reports_client/configuration.rb', line 31

def reporter_email_method
  @reporter_email_method
end

#reporter_externalObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def reporter_external
  @reporter_external
end

#reporter_name_methodObject

Integration with the host's controllers and user model. authenticate_method is the host method the engine calls to enforce login. Set it to nil when the parent_controller already authenticates globally (e.g. its own before_action :authenticate_user!, which the engine inherits) so authentication does not run twice per request.



31
32
33
# File 'lib/bug_reports_client/configuration.rb', line 31

def reporter_name_method
  @reporter_name_method
end

#screenshot_content_typesObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def screenshot_content_types
  @screenshot_content_types
end

#screenshots_enabledObject

Behavioural flags. reporter_external and admin_check are procs receiving the current user; ask_severity hides the severity picker (consumer-facing apps) and submits default_severity instead.



37
38
39
# File 'lib/bug_reports_client/configuration.rb', line 37

def screenshots_enabled
  @screenshots_enabled
end

#sourceObject

Identity of this app. source must match the ApiKey name registered on the API and a key in its repo mapping. app_host is the public HTTPS origin of this app, used to build the callback URL and screenshot links.



20
21
22
# File 'lib/bug_reports_client/configuration.rb', line 20

def source
  @source
end

#user_classObject

Integration with the host's controllers and user model. authenticate_method is the host method the engine calls to enforce login. Set it to nil when the parent_controller already authenticates globally (e.g. its own before_action :authenticate_user!, which the engine inherits) so authentication does not run twice per request.



31
32
33
# File 'lib/bug_reports_client/configuration.rb', line 31

def user_class
  @user_class
end

#webhook_secretObject

Connection to the bug-reports API.



15
16
17
# File 'lib/bug_reports_client/configuration.rb', line 15

def webhook_secret
  @webhook_secret
end

Instance Method Details

#admin?(user) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/bug_reports_client/configuration.rb', line 115

def admin?(user)
  !!admin_check.call(user)
end

#external_reporter?(user) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/bug_reports_client/configuration.rb', line 111

def external_reporter?(user)
  !!reporter_external.call(user)
end

#reporter_email_for(user) ⇒ Object

Reporter attribute readers accept either a method name (symbol) or a proc, so hosts without e.g. a name method can supply a lambda.



103
104
105
# File 'lib/bug_reports_client/configuration.rb', line 103

def reporter_email_for(user)
  resolve(reporter_email_method, user)
end

#reporter_name_for(user) ⇒ Object



107
108
109
# File 'lib/bug_reports_client/configuration.rb', line 107

def reporter_name_for(user)
  resolve(reporter_name_method, user)
end

#source!Object

Raises:



96
97
98
99
# File 'lib/bug_reports_client/configuration.rb', line 96

def source!
  raise ConfigurationError, "BugReportsClient: config.source is required (must match your API key name)" if source.blank?
  source
end