Class: Testimonials::Configuration
- Inherits:
-
Object
- Object
- Testimonials::Configuration
- Defined in:
- lib/testimonials/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 gets prompted, who can triage, and how submissions are attributed.
Instance Attribute Summary collapse
-
#admin_layout ⇒ Object
Layout used by the built-in dashboard.
-
#app_name ⇒ Object
Shown in the widget ("Enjoying %app?") and interpolated into the default questions.
-
#authorize_admin ⇒ Object
Per-request gate for the built-in dashboard.
-
#avatars ⇒ Object
Headshot upload for guests on the public collection page.
-
#consent_text ⇒ Object
Consent line stored verbatim with each submission.
-
#current_user ⇒ Object
Resolve the current user for attribution (optional).
-
#enabled ⇒ Object
Per-request gate for the widget and the submission endpoints.
-
#max_avatar_size ⇒ Object
Returns the value of attribute max_avatar_size.
-
#max_prompts ⇒ Object
Auto-prompt throttling.
-
#max_video_seconds ⇒ Object
Returns the value of attribute max_video_seconds.
-
#max_video_size ⇒ Object
Returns the value of attribute max_video_size.
-
#mount_path ⇒ Object
Where the engine is mounted.
-
#nps ⇒ Object
NPS surveys ("How likely are you to recommend…", 0–10).
-
#nps_reprompt_after ⇒ Object
Returns the value of attribute nps_reprompt_after.
-
#on_detractor ⇒ Object
Called with each NPS response scored 0–6.
-
#on_submit ⇒ Object
Called with each saved Testimonials::Testimonial or Testimonials::NpsResponse — notify Slack, send an email.
-
#prompt_events ⇒ Object
The throttling ledger itself (testimonials_prompt_events).
-
#public_api ⇒ Object
Unauthenticated read access to the JSON API (approved + consented records only).
-
#public_collection ⇒ Object
The standalone collection page at "##mount_path/new" — for links you send to customers outside the app.
-
#questions ⇒ Object
Guiding prompts shown above the message field and while recording — they fight blank-page paralysis, they are not form fields.
-
#rate_limit ⇒ Object
Per-IP throttle for the public endpoints, as keyword arguments for Rails' rate limiter (Rails 7.2+; ignored on 7.1).
-
#reprompt_after ⇒ Object
Auto-prompt throttling.
-
#storage_service ⇒ Object
The Active Storage service that stores uploads — video, its poster frame, guest avatars — as a service name from the host's config/storage.yml (e.g. a dedicated bucket or folder).
-
#tenant ⇒ Object
Resolve the current tenant (optional, for multi-tenant apps).
-
#user_display ⇒ Object
Turn a resolved user into the attribution stored with a submission.
-
#video ⇒ Object
Video testimonials (recording and upload).
Instance Method Summary collapse
- #avatars_enabled? ⇒ Boolean
- #events_endpoint ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #nps_endpoint ⇒ Object
- #testimonials_endpoint ⇒ Object
-
#video_enabled? ⇒ Boolean
Video and avatars need Active Storage — both the config switch and the host actually having it loaded.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/testimonials/configuration.rb', line 116 def initialize @app_name = nil @enabled = ->(_request) { true } @authorize_admin = ->(_request) { Rails.env.development? } @admin_layout = 'testimonials/application' @current_user = ->(_request) {} @tenant = ->(_request) {} @user_display = lambda { |user| { name: user.try(:name), email: user.try(:email) } } @questions = nil @video = true @max_video_seconds = 120 @max_video_size = 50 * 1024 * 1024 @avatars = true @max_avatar_size = 5 * 1024 * 1024 @storage_service = nil @reprompt_after = 90 * 24 * 60 * 60 @max_prompts = 3 @prompt_events = true @consent_text = nil @public_collection = true @public_api = false @nps = true @nps_reprompt_after = 90 * 24 * 60 * 60 @on_submit = ->(_record) {} @on_detractor = ->(_nps_response) {} @rate_limit = { to: 5, within: 60 } @mount_path = '/testimonials' end |
Instance Attribute Details
#admin_layout ⇒ Object
Layout used by the built-in dashboard. Override this to render Testimonials inside your app's admin shell, e.g. "admin/application".
22 23 24 |
# File 'lib/testimonials/configuration.rb', line 22 def admin_layout @admin_layout end |
#app_name ⇒ Object
Shown in the widget ("Enjoying %app?") and interpolated into the default questions. nil resolves to the Rails application name.
10 11 12 |
# File 'lib/testimonials/configuration.rb', line 10 def app_name @app_name end |
#authorize_admin ⇒ Object
Per-request gate for the built-in dashboard. Defaults to development only — override it before deploying, e.g. with an admin check.
18 19 20 |
# File 'lib/testimonials/configuration.rb', line 18 def @authorize_admin end |
#avatars ⇒ Object
Headshot upload for guests on the public collection page. Requires Active Storage.
56 57 58 |
# File 'lib/testimonials/configuration.rb', line 56 def avatars @avatars end |
#consent_text ⇒ Object
Consent line stored verbatim with each submission. nil uses the localized default.
83 84 85 |
# File 'lib/testimonials/configuration.rb', line 83 def @consent_text end |
#current_user ⇒ Object
Resolve the current user for attribution (optional). Return an object responding to #id, or nil. Receives the request.
26 27 28 |
# File 'lib/testimonials/configuration.rb', line 26 def current_user @current_user end |
#enabled ⇒ Object
Per-request gate for the widget and the submission endpoints. Return false to hide the widget and reject submissions for this request.
14 15 16 |
# File 'lib/testimonials/configuration.rb', line 14 def enabled @enabled end |
#max_avatar_size ⇒ Object
Returns the value of attribute max_avatar_size.
57 58 59 |
# File 'lib/testimonials/configuration.rb', line 57 def max_avatar_size @max_avatar_size end |
#max_prompts ⇒ Object
Auto-prompt throttling. A user who dismissed the widget is not
auto-prompted again within reprompt_after; a user auto-prompted
max_prompts times without submitting is never auto-prompted again;
a user who submitted a testimonial is done for good. Explicit opens
(clicking your link) always work.
70 71 72 |
# File 'lib/testimonials/configuration.rb', line 70 def max_prompts @max_prompts end |
#max_video_seconds ⇒ Object
Returns the value of attribute max_video_seconds.
52 53 54 |
# File 'lib/testimonials/configuration.rb', line 52 def max_video_seconds @max_video_seconds end |
#max_video_size ⇒ Object
Returns the value of attribute max_video_size.
52 53 54 |
# File 'lib/testimonials/configuration.rb', line 52 def max_video_size @max_video_size end |
#mount_path ⇒ Object
Where the engine is mounted. The widget posts to paths under it, so
keep this in sync with the mount line in your routes.
114 115 116 |
# File 'lib/testimonials/configuration.rb', line 114 def mount_path @mount_path end |
#nps ⇒ Object
NPS surveys ("How likely are you to recommend…", 0–10). Promoters (9–10) are offered the testimonial form right after scoring.
95 96 97 |
# File 'lib/testimonials/configuration.rb', line 95 def nps @nps end |
#nps_reprompt_after ⇒ Object
Returns the value of attribute nps_reprompt_after.
96 97 98 |
# File 'lib/testimonials/configuration.rb', line 96 def nps_reprompt_after @nps_reprompt_after end |
#on_detractor ⇒ Object
Called with each NPS response scored 0–6. Route it into your feedback tool, e.g. create a FeedbackEngine::Feedback from nps.comment.
105 106 107 |
# File 'lib/testimonials/configuration.rb', line 105 def on_detractor @on_detractor end |
#on_submit ⇒ Object
Called with each saved Testimonials::Testimonial or Testimonials::NpsResponse — notify Slack, send an email. Runs inline after save; keep it fast or hand off to a job.
101 102 103 |
# File 'lib/testimonials/configuration.rb', line 101 def on_submit @on_submit end |
#prompt_events ⇒ Object
The throttling ledger itself (testimonials_prompt_events). Off means no
per-user prompt history is written — and therefore no auto-prompts:
testimonial_prompt! stops opening the widget, because a prompt that
can't be throttled would reopen on every page. Explicit opens — your
own button, data-testimonial-prompt, window.Testimonials.open(),
the public pages — are unaffected. For apps that only ever open the
widget on a click; --skip-prompt-events writes it at install time.
79 80 81 |
# File 'lib/testimonials/configuration.rb', line 79 def prompt_events @prompt_events end |
#public_api ⇒ Object
Unauthenticated read access to the JSON API (approved + consented records only). OFF by default: the API then answers only for admins.
91 92 93 |
# File 'lib/testimonials/configuration.rb', line 91 def public_api @public_api end |
#public_collection ⇒ Object
The standalone collection page at "##mount_path/new" — for links you send to customers outside the app. ON by default; set false to 404 it.
87 88 89 |
# File 'lib/testimonials/configuration.rb', line 87 def public_collection @public_collection end |
#questions ⇒ Object
Guiding prompts shown above the message field and while recording —
they fight blank-page paralysis, they are not form fields. nil uses the
gem's built-in localized questions (testimonials.questions, with
%app interpolated). Override with an array of literal strings, or a
callable for host-side i18n: -> { I18n.t("myapp.review_questions") }.
An empty array hides the section.
48 49 50 |
# File 'lib/testimonials/configuration.rb', line 48 def questions @questions end |
#rate_limit ⇒ Object
Per-IP throttle for the public endpoints, 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.
110 111 112 |
# File 'lib/testimonials/configuration.rb', line 110 def rate_limit @rate_limit end |
#reprompt_after ⇒ Object
Auto-prompt throttling. A user who dismissed the widget is not
auto-prompted again within reprompt_after; a user auto-prompted
max_prompts times without submitting is never auto-prompted again;
a user who submitted a testimonial is done for good. Explicit opens
(clicking your link) always work.
70 71 72 |
# File 'lib/testimonials/configuration.rb', line 70 def reprompt_after @reprompt_after end |
#storage_service ⇒ Object
The Active Storage service that stores uploads — video, its poster frame, guest avatars — as a service name from the host's config/storage.yml (e.g. a dedicated bucket or folder). nil, the default, uses the environment's default service.
63 64 65 |
# File 'lib/testimonials/configuration.rb', line 63 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 collection: today's behavior, unchanged.
Testimonials, NPS, the dashboard and the read API all scope to whatever
this returns. The recommended key is a GlobalID (record.to_gid.to_s),
which also matches the has_testimonials model concern.
35 36 37 |
# File 'lib/testimonials/configuration.rb', line 35 def tenant @tenant end |
#user_display ⇒ Object
Turn a resolved user into the attribution stored with a submission. Return a hash with :name, :email, and optionally :title_company. Receives whatever #current_user returned.
40 41 42 |
# File 'lib/testimonials/configuration.rb', line 40 def user_display @user_display end |
#video ⇒ Object
Video testimonials (recording and upload). Requires Active Storage.
51 52 53 |
# File 'lib/testimonials/configuration.rb', line 51 def video @video end |
Instance Method Details
#avatars_enabled? ⇒ Boolean
157 158 159 |
# File 'lib/testimonials/configuration.rb', line 157 def avatars_enabled? avatars && defined?(::ActiveStorage) ? true : false end |
#events_endpoint ⇒ Object
149 |
# File 'lib/testimonials/configuration.rb', line 149 def events_endpoint = "#{mount_path.chomp('/')}/events" |
#nps_endpoint ⇒ Object
148 |
# File 'lib/testimonials/configuration.rb', line 148 def nps_endpoint = "#{mount_path.chomp('/')}/nps" |
#testimonials_endpoint ⇒ Object
147 |
# File 'lib/testimonials/configuration.rb', line 147 def testimonials_endpoint = mount_path.chomp('/') |
#video_enabled? ⇒ Boolean
Video and avatars need Active Storage — both the config switch and the host actually having it loaded.
153 154 155 |
# File 'lib/testimonials/configuration.rb', line 153 def video_enabled? video && defined?(::ActiveStorage) ? true : false end |