Class: FeedbackEngine::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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 = ->() {}
end

Instance Attribute Details

#author_labelObject

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
  @author_label
end

#authorize_adminObject

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
  @authorize_admin
end

#button_labelObject

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
  @button_label
end

#current_userObject

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

#enabledObject

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

#kindsObject

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_sizeObject

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_screenshotsObject

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_pathObject

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_submitObject

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

#screenshotsObject

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

#sectionsObject

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_buttonObject

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
  @show_button
end

Instance Method Details

#feedbacks_endpointObject



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.

Returns:

  • (Boolean)


83
84
85
# File 'lib/feedback_engine/configuration.rb', line 83

def screenshots_enabled?
  screenshots && defined?(::ActiveStorage) ? true : false
end