Class: I18nFeedback::Configuration
- Inherits:
-
Object
- Object
- I18nFeedback::Configuration
- Defined in:
- lib/i18n_feedback/configuration.rb
Overview
Host-tunable settings. Everything has a safe default, so a fresh install works with zero configuration in development; the hooks below let an app decide who sees the tool and how suggestions are attributed.
Instance Attribute Summary collapse
-
#author_label ⇒ Object
Turn a resolved user into a short label shown in the "already suggested" list.
-
#auto_inject ⇒ Object
Inject the widget into HTML responses automatically.
-
#available_locales ⇒ Object
The locales a suggestion may target.
-
#current_user ⇒ Object
Resolve the current user for attribution (optional).
-
#enabled ⇒ Object
Per-request gate, on top of the environment check.
-
#enabled_environments ⇒ Object
Environments the tool is active in.
-
#mount_path ⇒ Object
Where the engine is mounted.
-
#pill_label ⇒ Object
Text on the floating toggle pill.
-
#show_pill ⇒ Object
Show the floating toggle pill.
-
#toggle_param ⇒ Object
The query-string parameter that turns suggest mode on/off, so a host can link to it from anywhere: "?i18n_feedback=true" enables it, "false" exits.
Instance Method Summary collapse
- #environment_enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #suggestions_endpoint ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/i18n_feedback/configuration.rb', line 50 def initialize @enabled_environments = %w[development staging] @enabled = ->(_request) { true } @current_user = ->(_request) {} @author_label = ->(user) { user.respond_to?(:email) ? user.email : user&.to_s } @available_locales = -> { I18n.available_locales.map(&:to_s) } @auto_inject = true @mount_path = '/i18n_feedback' @show_pill = true @pill_label = 'Suggest edits' @toggle_param = 'i18n_feedback' end |
Instance Attribute Details
#author_label ⇒ Object
Turn a resolved user into a short label shown in the "already suggested" list. Receives whatever #current_user returned.
23 24 25 |
# File 'lib/i18n_feedback/configuration.rb', line 23 def @author_label end |
#auto_inject ⇒ Object
Inject the widget into HTML responses automatically. Set false to place it
yourself with <%= i18n_feedback_tag %> in your layout.
30 31 32 |
# File 'lib/i18n_feedback/configuration.rb', line 30 def auto_inject @auto_inject end |
#available_locales ⇒ Object
The locales a suggestion may target. Used to validate submissions.
26 27 28 |
# File 'lib/i18n_feedback/configuration.rb', line 26 def available_locales @available_locales end |
#current_user ⇒ Object
Resolve the current user for attribution (optional). Return an object responding to #id, or nil. Receives the Rack::Request.
19 20 21 |
# File 'lib/i18n_feedback/configuration.rb', line 19 def current_user @current_user end |
#enabled ⇒ Object
Per-request gate, on top of the environment check. Return false to hide the tool for this request. Receives the Rack::Request. Plug in an admin check, a feature flag, an allowlist, etc.
15 16 17 |
# File 'lib/i18n_feedback/configuration.rb', line 15 def enabled @enabled end |
#enabled_environments ⇒ Object
Environments the tool is active in. It is never active anywhere else, so a production deploy can't accidentally expose the key markers or the endpoint.
10 11 12 |
# File 'lib/i18n_feedback/configuration.rb', line 10 def enabled_environments @enabled_environments end |
#mount_path ⇒ Object
Where the engine is mounted. The widget posts suggestions to
"##mount_path/suggestions", so keep this in sync with the mount line in
your routes.
35 36 37 |
# File 'lib/i18n_feedback/configuration.rb', line 35 def mount_path @mount_path end |
#pill_label ⇒ Object
Text on the floating toggle pill.
42 43 44 |
# File 'lib/i18n_feedback/configuration.rb', line 42 def pill_label @pill_label end |
#show_pill ⇒ Object
Show the floating toggle pill. Set false to hide it and drive suggest mode from your own link instead (see #toggle_param).
39 40 41 |
# File 'lib/i18n_feedback/configuration.rb', line 39 def show_pill @show_pill end |
#toggle_param ⇒ Object
The query-string parameter that turns suggest mode on/off, so a host can link to it from anywhere: "?i18n_feedback=true" enables it, "false" exits. The choice is remembered in a cookie, so the rest of the app stays in suggest mode without the parameter.
48 49 50 |
# File 'lib/i18n_feedback/configuration.rb', line 48 def toggle_param @toggle_param end |
Instance Method Details
#environment_enabled? ⇒ Boolean
63 64 65 |
# File 'lib/i18n_feedback/configuration.rb', line 63 def environment_enabled? enabled_environments.map(&:to_s).include?(Rails.env.to_s) end |
#suggestions_endpoint ⇒ Object
67 68 69 |
# File 'lib/i18n_feedback/configuration.rb', line 67 def suggestions_endpoint "#{mount_path.chomp('/')}/suggestions" end |