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
-
#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.
-
#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.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/testimonials/configuration.rb', line 103 def initialize @app_name = nil @enabled = ->(_request) { true } @authorize_admin = ->(_request) { Rails.env.development? } @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 @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
#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.
52 53 54 |
# File 'lib/testimonials/configuration.rb', line 52 def avatars @avatars end |
#consent_text ⇒ Object
Consent line stored verbatim with each submission. nil uses the localized default.
70 71 72 |
# File 'lib/testimonials/configuration.rb', line 70 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.
22 23 24 |
# File 'lib/testimonials/configuration.rb', line 22 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.
53 54 55 |
# File 'lib/testimonials/configuration.rb', line 53 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.
66 67 68 |
# File 'lib/testimonials/configuration.rb', line 66 def max_prompts @max_prompts end |
#max_video_seconds ⇒ Object
Returns the value of attribute max_video_seconds.
48 49 50 |
# File 'lib/testimonials/configuration.rb', line 48 def max_video_seconds @max_video_seconds end |
#max_video_size ⇒ Object
Returns the value of attribute max_video_size.
48 49 50 |
# File 'lib/testimonials/configuration.rb', line 48 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.
101 102 103 |
# File 'lib/testimonials/configuration.rb', line 101 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.
82 83 84 |
# File 'lib/testimonials/configuration.rb', line 82 def nps @nps end |
#nps_reprompt_after ⇒ Object
Returns the value of attribute nps_reprompt_after.
83 84 85 |
# File 'lib/testimonials/configuration.rb', line 83 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.
92 93 94 |
# File 'lib/testimonials/configuration.rb', line 92 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.
88 89 90 |
# File 'lib/testimonials/configuration.rb', line 88 def on_submit @on_submit 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.
78 79 80 |
# File 'lib/testimonials/configuration.rb', line 78 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.
74 75 76 |
# File 'lib/testimonials/configuration.rb', line 74 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.
44 45 46 |
# File 'lib/testimonials/configuration.rb', line 44 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.
97 98 99 |
# File 'lib/testimonials/configuration.rb', line 97 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.
66 67 68 |
# File 'lib/testimonials/configuration.rb', line 66 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.
59 60 61 |
# File 'lib/testimonials/configuration.rb', line 59 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.
31 32 33 |
# File 'lib/testimonials/configuration.rb', line 31 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.
36 37 38 |
# File 'lib/testimonials/configuration.rb', line 36 def user_display @user_display end |
#video ⇒ Object
Video testimonials (recording and upload). Requires Active Storage.
47 48 49 |
# File 'lib/testimonials/configuration.rb', line 47 def video @video end |
Instance Method Details
#avatars_enabled? ⇒ Boolean
142 143 144 |
# File 'lib/testimonials/configuration.rb', line 142 def avatars_enabled? avatars && defined?(::ActiveStorage) ? true : false end |
#events_endpoint ⇒ Object
134 |
# File 'lib/testimonials/configuration.rb', line 134 def events_endpoint = "#{mount_path.chomp('/')}/events" |
#nps_endpoint ⇒ Object
133 |
# File 'lib/testimonials/configuration.rb', line 133 def nps_endpoint = "#{mount_path.chomp('/')}/nps" |
#testimonials_endpoint ⇒ Object
132 |
# File 'lib/testimonials/configuration.rb', line 132 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.
138 139 140 |
# File 'lib/testimonials/configuration.rb', line 138 def video_enabled? video && defined?(::ActiveStorage) ? true : false end |