Module: Testimonials
- Defined in:
- lib/testimonials.rb,
lib/testimonials/engine.rb,
lib/testimonials/widget.rb,
lib/testimonials/version.rb,
lib/testimonials/configuration.rb,
lib/testimonials/prompt_helper.rb,
lib/testimonials/has_testimonials.rb,
app/models/testimonials/testimonial.rb,
app/models/testimonials/nps_response.rb,
app/models/testimonials/prompt_event.rb,
app/helpers/testimonials/widget_helper.rb,
app/models/testimonials/application_record.rb,
app/controllers/testimonials/nps_controller.rb,
app/controllers/testimonials/media_controller.rb,
app/controllers/testimonials/events_controller.rb,
app/controllers/testimonials/widgets_controller.rb,
app/controllers/testimonials/api/base_controller.rb,
app/controllers/testimonials/api/stats_controller.rb,
app/controllers/testimonials/collection_controller.rb,
app/controllers/testimonials/application_controller.rb,
lib/generators/testimonials/tenant/tenant_generator.rb,
app/controllers/testimonials/testimonials_controller.rb,
app/controllers/testimonials/nps_responses_controller.rb,
lib/generators/testimonials/install/install_generator.rb,
app/controllers/testimonials/api/testimonials_controller.rb
Overview
Testimonials, reviews and NPS for Rails. An iOS-style in-app widget collects star ratings and testimonials (text or video) at moments your code chooses; a public page collects them from shareable links; NPS promoters are routed straight into the testimonial ask. Everything lands in your own database with a minimal dashboard to approve, feature, and pick best lines — and a read API to render approved testimonials wherever you like.
Defined Under Namespace
Modules: Api, Generators, HasTestimonials, PromptHelper, Widget, WidgetHelper Classes: ApplicationController, ApplicationRecord, CollectionController, Configuration, Engine, EventsController, MediaController, NpsController, NpsResponse, NpsResponsesController, PromptEvent, Testimonial, TestimonialsController, WidgetsController
Constant Summary collapse
- VERSION =
'0.5.0'
Class Method Summary collapse
-
.admin?(request) ⇒ Boolean
Can this request browse and triage submissions? Checked by every dashboard action.
- .app_name ⇒ Object
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
-
.consent_text ⇒ Object
The public-use consent line, stored verbatim when a customer allows their testimonial to be shown publicly.
-
.consent_text_for(public_use) ⇒ Object
The exact line the customer agreed to, given their public/private choice.
-
.consent_text_private ⇒ Object
The private-use line, stored when a customer allows only internal use.
-
.enabled?(request) ⇒ Boolean
Can this request see the widget and submit? Checked on the server for every public endpoint and by the helper before rendering.
-
.for(record) ⇒ Object
Testimonials belonging to a host record, keyed by its GlobalID — the documented tenant convention.
-
.nps_for(record) ⇒ Object
The NPS responses belonging to a host record, same keying as
.for. -
.questions ⇒ Object
The guiding questions for the current locale, with %app filled in.
-
.tenant(request) ⇒ Object
The tenant key for this request, or nil for the single global collection.
Class Method Details
.admin?(request) ⇒ Boolean
Can this request browse and triage submissions? Checked by every dashboard action.
34 35 36 |
# File 'lib/testimonials.rb', line 34 def admin?(request) !!config..call(request) end |
.app_name ⇒ Object
38 39 40 |
# File 'lib/testimonials.rb', line 38 def app_name config.app_name.presence || rails_app_name end |
.config ⇒ Object
18 19 20 |
# File 'lib/testimonials.rb', line 18 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
22 23 24 |
# File 'lib/testimonials.rb', line 22 def configure yield config end |
.consent_text ⇒ Object
The public-use consent line, stored verbatim when a customer allows their testimonial to be shown publicly. Override with config.consent_text.
75 76 77 78 79 |
# File 'lib/testimonials.rb', line 75 def config..presence || I18n.t('testimonials.consent_public', default: 'You can use my testimonial publicly in your marketing and sales.') end |
.consent_text_for(public_use) ⇒ Object
The exact line the customer agreed to, given their public/private choice.
88 89 90 |
# File 'lib/testimonials.rb', line 88 def (public_use) public_use ? : end |
.consent_text_private ⇒ Object
The private-use line, stored when a customer allows only internal use.
82 83 84 85 |
# File 'lib/testimonials.rb', line 82 def I18n.t('testimonials.consent_private', default: 'You can only use my testimonial privately in your marketing and sales.') end |
.enabled?(request) ⇒ Boolean
Can this request see the widget and submit? Checked on the server for every public endpoint and by the helper before rendering.
28 29 30 |
# File 'lib/testimonials.rb', line 28 def enabled?(request) !!config.enabled.call(request) end |
.for(record) ⇒ Object
Testimonials belonging to a host record, keyed by its GlobalID — the
documented tenant convention. Sugar for Testimonial.for_tenant(...);
the has_testimonials model concern is built on this.
53 54 55 |
# File 'lib/testimonials.rb', line 53 def for(record) Testimonial.for_tenant(tenant_key_for(record)) end |
.nps_for(record) ⇒ Object
The NPS responses belonging to a host record, same keying as .for.
58 59 60 |
# File 'lib/testimonials.rb', line 58 def nps_for(record) NpsResponse.for_tenant(tenant_key_for(record)) end |
.questions ⇒ Object
The guiding questions for the current locale, with %app filled in. I18n leaves the token alone when no interpolation values are passed, so a plain gsub covers built-in, literal, and lambda-provided strings alike.
66 67 68 69 70 71 |
# File 'lib/testimonials.rb', line 66 def questions list = config.questions list = list.call if list.respond_to?(:call) list = I18n.t('testimonials.questions', default: []) if list.nil? Array(list).map { |q| q.to_s.gsub('%{app}', app_name) } end |
.tenant(request) ⇒ Object
The tenant key for this request, or nil for the single global collection.
Normalized to a string so where(tenant:) is consistent whether the
resolver returns a GlobalID, an integer id, or a slug. Blank resolves to
nil — an app that only sometimes has a tenant falls back to global.
46 47 48 |
# File 'lib/testimonials.rb', line 46 def tenant(request) config.tenant.call(request).presence&.to_s end |