Class: FeedbackEngine::Configuration
- Inherits:
-
Object
- Object
- FeedbackEngine::Configuration
- Defined in:
- lib/feedback_engine/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.
-
#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.
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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/feedback_engine/configuration.rb', line 61 def initialize @enabled = ->(_request) { true } @authorize_admin = ->(_request) { Rails.env.development? } @current_user = ->(_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 @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.
25 26 27 |
# File 'lib/feedback_engine/configuration.rb', line 25 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/feedback_engine/configuration.rb', line 17 def @authorize_admin end |
#button_label ⇒ Object
Text on the floating button. Leave nil to use the localized default
(the feedback_engine.button I18n key).
50 51 52 |
# File 'lib/feedback_engine/configuration.rb', line 50 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/feedback_engine/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/feedback_engine/configuration.rb', line 12 def enabled @enabled end |
#kinds ⇒ Object
The feedback types a user can pick from. Labels resolve through I18n
(feedback_engine.kinds.<kind>), so you can rename or add kinds freely.
29 30 31 |
# File 'lib/feedback_engine/configuration.rb', line 29 def kinds @kinds end |
#max_screenshot_size ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
41 42 43 |
# File 'lib/feedback_engine/configuration.rb', line 41 def max_screenshot_size @max_screenshot_size end |
#max_screenshots ⇒ Object
Upload limits, enforced server-side and mirrored in the widget.
41 42 43 |
# File 'lib/feedback_engine/configuration.rb', line 41 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.
55 56 57 |
# File 'lib/feedback_engine/configuration.rb', line 55 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.
59 60 61 |
# File 'lib/feedback_engine/configuration.rb', line 59 def on_submit @on_submit 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.
38 39 40 |
# File 'lib/feedback_engine/configuration.rb', line 38 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.
33 34 35 |
# File 'lib/feedback_engine/configuration.rb', line 33 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-feedback-engine-open
attribute opens the form.
46 47 48 |
# File 'lib/feedback_engine/configuration.rb', line 46 def @show_button end |
Instance Method Details
#feedbacks_endpoint ⇒ Object
77 78 79 |
# File 'lib/feedback_engine/configuration.rb', line 77 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.
83 84 85 |
# File 'lib/feedback_engine/configuration.rb', line 83 def screenshots_enabled? screenshots && defined?(::ActiveStorage) ? true : false end |