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.
Instance Attribute Summary collapse
-
#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).
-
#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.
-
#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.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ideasbugs/configuration.rb', line 75 def initialize @enabled = ->(_request) { true } @authorize_admin = ->(_request) { Rails.env.development? } @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 @rate_limit = { to: 10, within: 60 } @show_button = true @button_label = nil @mount_path = '/feedback' @on_submit = ->(_feedback) {} end |
Instance Attribute Details
#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.
34 35 36 |
# File 'lib/ideasbugs/configuration.rb', line 34 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.
17 18 19 |
# File 'lib/ideasbugs/configuration.rb', line 17 def @authorize_admin end |
#button_label ⇒ Object
Text on the floating button. Leave nil to use the localized default
(the ideasbugs.button I18n key).
64 65 66 |
# File 'lib/ideasbugs/configuration.rb', line 64 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.
21 22 23 |
# File 'lib/ideasbugs/configuration.rb', line 21 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.
12 13 14 |
# File 'lib/ideasbugs/configuration.rb', line 12 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.
38 39 40 |
# File 'lib/ideasbugs/configuration.rb', line 38 def kinds @kinds end |
#max_screenshot_size ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
50 51 52 |
# File 'lib/ideasbugs/configuration.rb', line 50 def max_screenshot_size @max_screenshot_size end |
#max_screenshots ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
50 51 52 |
# File 'lib/ideasbugs/configuration.rb', line 50 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.
69 70 71 |
# File 'lib/ideasbugs/configuration.rb', line 69 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.
73 74 75 |
# File 'lib/ideasbugs/configuration.rb', line 73 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.
55 56 57 |
# File 'lib/ideasbugs/configuration.rb', line 55 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.
47 48 49 |
# File 'lib/ideasbugs/configuration.rb', line 47 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.
42 43 44 |
# File 'lib/ideasbugs/configuration.rb', line 42 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.
60 61 62 |
# File 'lib/ideasbugs/configuration.rb', line 60 def @show_button 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.
30 31 32 |
# File 'lib/ideasbugs/configuration.rb', line 30 def tenant @tenant end |
Instance Method Details
#feedbacks_endpoint ⇒ Object
93 94 95 |
# File 'lib/ideasbugs/configuration.rb', line 93 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.
99 100 101 |
# File 'lib/ideasbugs/configuration.rb', line 99 def screenshots_enabled? screenshots && defined?(::ActiveStorage) ? true : false end |