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.
-
#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.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/testimonials/configuration.rb', line 88 def initialize @app_name = nil @enabled = ->(_request) { true } @authorize_admin = ->(_request) { Rails.env.development? } @current_user = ->(_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 @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.
43 44 45 |
# File 'lib/testimonials/configuration.rb', line 43 def avatars @avatars end |
#consent_text ⇒ Object
Consent line stored verbatim with each submission. nil uses the localized default.
55 56 57 |
# File 'lib/testimonials/configuration.rb', line 55 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.
44 45 46 |
# File 'lib/testimonials/configuration.rb', line 44 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.
51 52 53 |
# File 'lib/testimonials/configuration.rb', line 51 def max_prompts @max_prompts end |
#max_video_seconds ⇒ Object
Returns the value of attribute max_video_seconds.
39 40 41 |
# File 'lib/testimonials/configuration.rb', line 39 def max_video_seconds @max_video_seconds end |
#max_video_size ⇒ Object
Returns the value of attribute max_video_size.
39 40 41 |
# File 'lib/testimonials/configuration.rb', line 39 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.
86 87 88 |
# File 'lib/testimonials/configuration.rb', line 86 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.
67 68 69 |
# File 'lib/testimonials/configuration.rb', line 67 def nps @nps end |
#nps_reprompt_after ⇒ Object
Returns the value of attribute nps_reprompt_after.
68 69 70 |
# File 'lib/testimonials/configuration.rb', line 68 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.
77 78 79 |
# File 'lib/testimonials/configuration.rb', line 77 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.
73 74 75 |
# File 'lib/testimonials/configuration.rb', line 73 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.
63 64 65 |
# File 'lib/testimonials/configuration.rb', line 63 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.
59 60 61 |
# File 'lib/testimonials/configuration.rb', line 59 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.
35 36 37 |
# File 'lib/testimonials/configuration.rb', line 35 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.
82 83 84 |
# File 'lib/testimonials/configuration.rb', line 82 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.
51 52 53 |
# File 'lib/testimonials/configuration.rb', line 51 def reprompt_after @reprompt_after 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.
27 28 29 |
# File 'lib/testimonials/configuration.rb', line 27 def user_display @user_display end |
#video ⇒ Object
Video testimonials (recording and upload). Requires Active Storage.
38 39 40 |
# File 'lib/testimonials/configuration.rb', line 38 def video @video end |
Instance Method Details
#avatars_enabled? ⇒ Boolean
125 126 127 |
# File 'lib/testimonials/configuration.rb', line 125 def avatars_enabled? avatars && defined?(::ActiveStorage) ? true : false end |
#events_endpoint ⇒ Object
117 |
# File 'lib/testimonials/configuration.rb', line 117 def events_endpoint = "#{mount_path.chomp('/')}/events" |
#nps_endpoint ⇒ Object
116 |
# File 'lib/testimonials/configuration.rb', line 116 def nps_endpoint = "#{mount_path.chomp('/')}/nps" |
#testimonials_endpoint ⇒ Object
115 |
# File 'lib/testimonials/configuration.rb', line 115 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.
121 122 123 |
# File 'lib/testimonials/configuration.rb', line 121 def video_enabled? video && defined?(::ActiveStorage) ? true : false end |