Class: Ideasbugs::Configuration
- Inherits:
-
Object
- Object
- Ideasbugs::Configuration
- Defined in:
- lib/ideasbugs/configuration.rb
Overview
Host-tunable settings. Everything has a safe default, so a fresh install works with zero configuration; the hooks below let an app decide who can send feedback, who can read it, and how submissions are attributed.
Constant Summary collapse
- DEFAULT_ADMIN_LAYOUT =
The gem's own dashboard layout. Compared against, so DashboardController can tell "the host left this alone" from "the host chose this".
'ideasbugs/application'
Instance Attribute Summary collapse
-
#admin_layout ⇒ Object
Layout used by the built-in dashboard.
-
#author_label ⇒ Object
Turn a resolved user into a short label stored alongside the feedback and shown in the dashboard.
-
#authorize_admin ⇒ Object
Per-request gate for the built-in dashboard (browse and triage feedback).
-
#base_controller_class ⇒ Object
The controller the DASHBOARD inherits from, as a String so it resolves lazily rather than at config time.
-
#button_label ⇒ Object
Text on the floating button.
-
#current_user ⇒ Object
Resolve the current user for attribution (optional).
-
#enabled ⇒ Object
Per-request gate for the widget and the submission endpoint.
-
#kinds ⇒ Object
The feedback types a user can pick from.
-
#max_screenshot_size ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
-
#max_screenshots ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
-
#mount_path ⇒ Object
Where the engine is mounted.
-
#on_submit ⇒ Object
Called with each saved feedback — notify Slack, send an email, open a ticket.
-
#rate_limit ⇒ Object
Per-IP throttle for the public submission endpoint, as keyword arguments for Rails' rate limiter (Rails 7.2+; ignored on 7.1).
-
#screenshots ⇒ Object
Allow screenshot uploads.
-
#sections ⇒ Object
Optional list of app areas ("Billing", "Dashboard", …) shown as a select in the widget.
-
#show_button ⇒ Object
Show the floating feedback button.
-
#storage_service ⇒ Object
The Active Storage service that stores screenshots, as a service name from the host's config/storage.yml.
-
#tenant ⇒ Object
Resolve the current tenant (optional, for multi-tenant apps).
Instance Method Summary collapse
- #feedbacks_endpoint ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#screenshots_enabled? ⇒ Boolean
Screenshots need Active Storage — both the config switch and the host actually having it loaded.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ideasbugs/configuration.rb', line 102 def initialize @enabled = ->(_request) { true } @authorize_admin = ->(_request) { Rails.env.development? } @admin_layout = DEFAULT_ADMIN_LAYOUT @base_controller_class = 'ActionController::Base' @current_user = ->(_request) {} @tenant = ->(_request) {} @author_label = ->(user) { user.respond_to?(:email) ? user.email : user&.to_s } @kinds = %w[bug feature other] @sections = [] @screenshots = true @max_screenshots = 3 @max_screenshot_size = 5 * 1024 * 1024 @storage_service = nil @rate_limit = { to: 10, within: 60 } @show_button = true @button_label = nil @mount_path = '/feedback' @on_submit = ->(_feedback) {} end |
Instance Attribute Details
#admin_layout ⇒ Object
Layout used by the built-in dashboard. Override this to render Ideasbugs inside your app's admin shell, e.g. "admin/application".
25 26 27 |
# File 'lib/ideasbugs/configuration.rb', line 25 def admin_layout @admin_layout end |
#author_label ⇒ Object
Turn a resolved user into a short label stored alongside the feedback and shown in the dashboard. Receives whatever #current_user returned.
57 58 59 |
# File 'lib/ideasbugs/configuration.rb', line 57 def @author_label end |
#authorize_admin ⇒ Object
Per-request gate for the built-in dashboard (browse and triage feedback). Receives the request. Defaults to development only — override it before deploying, e.g. with an admin check.
21 22 23 |
# File 'lib/ideasbugs/configuration.rb', line 21 def @authorize_admin end |
#base_controller_class ⇒ Object
The controller the DASHBOARD inherits from, as a String so it resolves
lazily rather than at config time. Default: a plain
'ActionController::Base', where authorize_admin is the only gate.
Name the controller your own admin already inherits from and the dashboard
adopts that whole stack — layout, helpers, authentication, and any request
context your before_actions set up. admin_layout covers only the layout,
which leaves a host layout calling its own helpers to raise NameError under
the engine's isolated namespace.
Only the dashboard uses it. The widget's endpoint stays on the engine's own public controller, so an admin base controller here can never demand a staff session from someone filing a report.
40 41 42 |
# File 'lib/ideasbugs/configuration.rb', line 40 def base_controller_class @base_controller_class end |
#button_label ⇒ Object
Text on the floating button. Leave nil to use the localized default
(the ideasbugs.button I18n key).
91 92 93 |
# File 'lib/ideasbugs/configuration.rb', line 91 def @button_label end |
#current_user ⇒ Object
Resolve the current user for attribution (optional). Return an object responding to #id, or nil. Receives the request.
44 45 46 |
# File 'lib/ideasbugs/configuration.rb', line 44 def current_user @current_user end |
#enabled ⇒ Object
Per-request gate for the widget and the submission endpoint. Return false to hide the widget and reject submissions for this request. Receives the request. Defaults to everyone — feedback collection is meant for real users in production.
16 17 18 |
# File 'lib/ideasbugs/configuration.rb', line 16 def enabled @enabled end |
#kinds ⇒ Object
The feedback types a user can pick from. Labels resolve through I18n
(ideasbugs.kinds.<kind>), so you can rename or add kinds freely.
61 62 63 |
# File 'lib/ideasbugs/configuration.rb', line 61 def kinds @kinds end |
#max_screenshot_size ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
73 74 75 |
# File 'lib/ideasbugs/configuration.rb', line 73 def max_screenshot_size @max_screenshot_size end |
#max_screenshots ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
73 74 75 |
# File 'lib/ideasbugs/configuration.rb', line 73 def max_screenshots @max_screenshots end |
#mount_path ⇒ Object
Where the engine is mounted. The widget posts to
"##mount_path/feedbacks", so keep this in sync with the mount line in
your routes.
96 97 98 |
# File 'lib/ideasbugs/configuration.rb', line 96 def mount_path @mount_path end |
#on_submit ⇒ Object
Called with each saved feedback — notify Slack, send an email, open a ticket. Runs inline after save; keep it fast or hand off to a job.
100 101 102 |
# File 'lib/ideasbugs/configuration.rb', line 100 def on_submit @on_submit end |
#rate_limit ⇒ Object
Per-IP throttle for the public submission endpoint, as keyword arguments for Rails' rate limiter (Rails 7.2+; ignored on 7.1). Read once when the controller loads — set it in an initializer. nil disables throttling.
82 83 84 |
# File 'lib/ideasbugs/configuration.rb', line 82 def rate_limit @rate_limit end |
#screenshots ⇒ Object
Allow screenshot uploads. Requires Active Storage in the host app; the widget hides the upload control when this is false or Active Storage is not set up.
70 71 72 |
# File 'lib/ideasbugs/configuration.rb', line 70 def screenshots @screenshots end |
#sections ⇒ Object
Optional list of app areas ("Billing", "Dashboard", …) shown as a select in the widget. Leave empty to hide the select entirely.
65 66 67 |
# File 'lib/ideasbugs/configuration.rb', line 65 def sections @sections end |
#show_button ⇒ Object
Show the floating feedback button. Set false to trigger the widget from
your own UI instead: any element with a data-ideasbugs-open
attribute opens the form.
87 88 89 |
# File 'lib/ideasbugs/configuration.rb', line 87 def @show_button end |
#storage_service ⇒ Object
The Active Storage service that stores screenshots, as a service name from the host's config/storage.yml. nil uses the environment default.
77 78 79 |
# File 'lib/ideasbugs/configuration.rb', line 77 def storage_service @storage_service end |
#tenant ⇒ Object
Resolve the current tenant (optional, for multi-tenant apps). Return an
opaque key — a GlobalID, an id, a subdomain, a slug — or nil. Receives
the request; shaped exactly like current_user/authorize_admin. nil (the
default) is a single, global board: today's behavior, unchanged. Each
submission is stamped with it and the dashboard scopes to it, so every
tenant gets its own board. The recommended key is a GlobalID
(record.to_gid.to_s), which also matches the has_feedback concern.
53 54 55 |
# File 'lib/ideasbugs/configuration.rb', line 53 def tenant @tenant end |
Instance Method Details
#feedbacks_endpoint ⇒ Object
123 124 125 |
# File 'lib/ideasbugs/configuration.rb', line 123 def feedbacks_endpoint "#{mount_path.chomp('/')}/feedbacks" end |
#screenshots_enabled? ⇒ Boolean
Screenshots need Active Storage — both the config switch and the host actually having it loaded.
129 130 131 |
# File 'lib/ideasbugs/configuration.rb', line 129 def screenshots_enabled? screenshots && defined?(::ActiveStorage) ? true : false end |