testimonials 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENTS.md +2 -2
- data/CHANGELOG.md +22 -0
- data/README.md +8 -2
- data/Rakefile +9 -1
- data/app/controllers/testimonials/nps_controller.rb +3 -1
- data/app/controllers/testimonials/submissions_controller.rb +3 -1
- data/app/models/testimonials/testimonial.rb +3 -3
- data/config/locales/testimonials.sl.yml +118 -0
- data/docs/ractors.md +123 -0
- data/docs/screenshots/01-prompt.png +0 -0
- data/docs/screenshots/02-form.png +0 -0
- data/docs/screenshots/03-camera-check.jpg +0 -0
- data/docs/screenshots/04-video-review.jpg +0 -0
- data/docs/screenshots/05-video-attached.png +0 -0
- data/docs/screenshots/admin-ui/after-index-mobile.png +0 -0
- data/docs/screenshots/admin-ui/after-index.png +0 -0
- data/docs/screenshots/admin-ui/after-nps-index-mobile.png +0 -0
- data/docs/screenshots/admin-ui/after-nps-index.png +0 -0
- data/docs/screenshots/admin-ui/after-nps-show-mobile.png +0 -0
- data/docs/screenshots/admin-ui/after-nps-show.png +0 -0
- data/docs/screenshots/admin-ui/after-show-mobile.png +0 -0
- data/docs/screenshots/admin-ui/after-show.png +0 -0
- data/docs/screenshots/admin-ui/before-index.png +0 -0
- data/docs/screenshots/admin-ui/before-nps-index.png +0 -0
- data/docs/screenshots/admin-ui/before-show.png +0 -0
- data/docs/screenshots/dashboard-index.png +0 -0
- data/docs/screenshots/dashboard-show.jpg +0 -0
- data/docs/screenshots/hero.jpg +0 -0
- data/docs/screenshots/nps-01-score.jpg +0 -0
- data/docs/screenshots/nps-02-comment.png +0 -0
- data/docs/screenshots/nps-dashboard.jpg +0 -0
- data/lib/testimonials/engine.rb +11 -0
- data/lib/testimonials/has_testimonials.rb +13 -2
- data/lib/testimonials/ractor_support.rb +521 -0
- data/lib/testimonials/version.rb +1 -1
- data/lib/testimonials/widget.rb +3 -3
- data/lib/testimonials.rb +1 -0
- metadata +27 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4fe17d284164332ca78b3660ae93c51c2490b7dc70b30d889363b00538f19e8
|
|
4
|
+
data.tar.gz: 6fceeb695a38a6c78902f36d17ad4a68b12366eb14f66fc49bd800dcd2b687bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e85a35d1df0ae5f0f21e3272b03b627e4a27b47521b5a8051809b5f7d988e9f35977ded8f4be8a2848a0d3916344b1c84b30925b6d2cc612a36f96386df94b0
|
|
7
|
+
data.tar.gz: d2a9e4affe1a2a96a62be60f688a992dc15eafb68ca484b887293173bff5312bcf85b1d99b38ad503c578921dffe36536c50f17e15b949554a843166cafe0ac7
|
data/AGENTS.md
CHANGED
|
@@ -172,7 +172,7 @@ Everything is optional; a fresh install works with zero config. Full list with c
|
|
|
172
172
|
| `mount_path` | `"/testimonials"` | Must match `mount_testimonials at:` in routes. |
|
|
173
173
|
| `rate_limit` | `{ to: 5, within: 60 }` | Rails 7.2+; ignored on 7.1. `nil` disables. |
|
|
174
174
|
|
|
175
|
-
Turbo Drive and nonce-based CSP work out of the box; the widget config rides in a `type="application/json"` block (data, not code) and the code is a same-origin `src` script.
|
|
175
|
+
Turbo Drive and nonce-based CSP work out of the box; the widget config rides in a `type="application/json"` block (data, not code) and the code is a same-origin `src` script. 27 locales ship with the gem, including localized guiding questions.
|
|
176
176
|
|
|
177
177
|
### Common failure modes
|
|
178
178
|
|
|
@@ -208,7 +208,7 @@ bundle exec rubocop # must be clean
|
|
|
208
208
|
BUNDLE_GEMFILE=gemfiles/rails_7.1.gemfile bundle exec rake test # 7.1, 7.2, 8.0, 8.1 in gemfiles/
|
|
209
209
|
```
|
|
210
210
|
|
|
211
|
-
Layout: `app/` controllers, models, dashboard views · `lib/testimonials/` config, widget JS/CSS, seeds, engine · `lib/generators/testimonials/` install, nps, prompt_events, tenant · `config/locales/`
|
|
211
|
+
Layout: `app/` controllers, models, dashboard views · `lib/testimonials/` config, widget JS/CSS, seeds, engine · `lib/generators/testimonials/` install, nps, prompt_events, tenant · `config/locales/` 27 locales · `test/` minitest, `test/dummy` the host app · `examples/` display snippets for hosts.
|
|
212
212
|
|
|
213
213
|
Conventions this codebase holds to — follow them rather than the first thing that works:
|
|
214
214
|
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- Add Slovenian text for reviews, consent, NPS, and the moderation dashboard.
|
|
6
|
+
Hosts can use the locale through Rails I18n with no setup changes.
|
|
7
|
+
|
|
8
|
+
## 1.1.0 - 2026-10-18
|
|
9
|
+
|
|
10
|
+
- Add Rails edge CI and experimental Ruby 4.0+ Ractor request support. The host
|
|
11
|
+
must opt into `Rails.application.ractorize!` and use the upstream Rack/I18n
|
|
12
|
+
dependencies documented in `docs/ractors.md`.
|
|
13
|
+
- Exercise actual multipart uploads and private downloads in worker Ractors
|
|
14
|
+
when Active Storage is installed, alongside the optional-dependency-free host.
|
|
15
|
+
- Prepare immutable widget assets and a frozen configuration snapshot at
|
|
16
|
+
Ractorization. Callbacks still run for each request, with isolated captures;
|
|
17
|
+
callbacks that capture mutable state fail at boot with the setting name.
|
|
18
|
+
Normal Rails boots retain mutable configuration and lazy asset loading.
|
|
19
|
+
- Bridge framework operations that are not yet Ractor safe (mounted URL
|
|
20
|
+
generation, digests/key derivation and attribute factories) to the main
|
|
21
|
+
Ractor. This adds dispatch overhead in Ractor mode; it is compatibility
|
|
22
|
+
support, not a claim of improved throughput. Existing Rails 7.1–8.1 installs
|
|
23
|
+
need no migration or initializer changes.
|
|
24
|
+
|
|
3
25
|
## 1.0.1 - 2026-08-11
|
|
4
26
|
|
|
5
27
|
- **Media responses now opt out of MIME sniffing.** Approved, consented media
|
data/README.md
CHANGED
|
@@ -86,7 +86,7 @@ and the things it should not do. It ships inside the gem, so
|
|
|
86
86
|
| **Display** | Headless. Your markup, via the models or a JSON API |
|
|
87
87
|
| **Deps** | None. Plain JS — no Tailwind, no Stimulus, no importmap, no build step |
|
|
88
88
|
| **Auth** | Lambdas over the raw request — Devise, Rails 8 auth, anything |
|
|
89
|
-
| **i18n** |
|
|
89
|
+
| **i18n** | 27 languages, including localized guiding questions |
|
|
90
90
|
| **Turbo/CSP** | Turbo Drive and strict nonce-based CSP out of the box |
|
|
91
91
|
|
|
92
92
|
## Why self-host it
|
|
@@ -222,7 +222,7 @@ end
|
|
|
222
222
|
|
|
223
223
|
The questions above the form ("How has %{app} helped you?") fight blank-page
|
|
224
224
|
paralysis — they are prompts, not form fields. By default they come from the
|
|
225
|
-
gem's locale files, so all
|
|
225
|
+
gem's locale files, so all 27 languages get good questions with your app name
|
|
226
226
|
interpolated.
|
|
227
227
|
|
|
228
228
|
```ruby
|
|
@@ -453,3 +453,9 @@ touch your own CSS — and migrations that follow your app's `primary_key_type`.
|
|
|
453
453
|
|
|
454
454
|
MIT. If it saved you a subscription, a
|
|
455
455
|
[⭐](https://github.com/yshmarov/testimonials) is a fair trade.
|
|
456
|
+
|
|
457
|
+
## Rails edge and Ractors
|
|
458
|
+
|
|
459
|
+
Rails edge is tested alongside Rails 7.1–8.1. Experimental Ruby 4.0+ Ractor hosting
|
|
460
|
+
requires additional upstream dependencies and freezes configuration at startup.
|
|
461
|
+
See [the Ractor hosting guide](docs/ractors.md) for callbacks, requirements and checks.
|
data/Rakefile
CHANGED
|
@@ -5,7 +5,7 @@ require 'rake/testtask'
|
|
|
5
5
|
|
|
6
6
|
Rake::TestTask.new(:test) do |t|
|
|
7
7
|
t.libs << 'test'
|
|
8
|
-
t.test_files = FileList['test/**/*_test.rb'].exclude('test/system/**/*')
|
|
8
|
+
t.test_files = FileList['test/**/*_test.rb'].exclude('test/system/**/*', 'test/ractor/**/*')
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
namespace :test do
|
|
@@ -17,3 +17,11 @@ namespace :test do
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
task default: :test
|
|
20
|
+
|
|
21
|
+
namespace :test do
|
|
22
|
+
desc 'Run isolated configuration and Rails edge Ractor request tests (Ruby 4.0+)'
|
|
23
|
+
task :ractor do
|
|
24
|
+
ruby '-Itest', 'test/ractor/configuration_test.rb'
|
|
25
|
+
ruby '-Itest', 'test/ractor/requests_test.rb'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -6,7 +6,9 @@ module Testimonials
|
|
|
6
6
|
before_action :require_nps
|
|
7
7
|
|
|
8
8
|
if respond_to?(:rate_limit) && Testimonials.config.rate_limit
|
|
9
|
-
rate_limit(**Testimonials.config.rate_limit, only: :create, with:
|
|
9
|
+
Testimonials::RactorSupport.rate_limit(self, **Testimonials.config.rate_limit, only: :create, with: lambda {
|
|
10
|
+
render_rate_limited
|
|
11
|
+
})
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def create
|
|
@@ -15,7 +15,9 @@ module Testimonials
|
|
|
15
15
|
# into Rails 7.2+ (backed by Rails.cache); on Rails 7.1 this is a no-op.
|
|
16
16
|
# Tune or disable via config.rate_limit — read once at boot.
|
|
17
17
|
if respond_to?(:rate_limit) && Testimonials.config.rate_limit
|
|
18
|
-
rate_limit(**Testimonials.config.rate_limit, only: :create, with:
|
|
18
|
+
Testimonials::RactorSupport.rate_limit(self, **Testimonials.config.rate_limit, only: :create, with: lambda {
|
|
19
|
+
render_rate_limited
|
|
20
|
+
})
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def create
|
|
@@ -37,9 +37,9 @@ module Testimonials
|
|
|
37
37
|
scope :publishable, -> { approved.where(consent_given: true) }
|
|
38
38
|
scope :featured_first, -> { order(featured: :desc, id: :desc) }
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
def pending? = status == 'pending'
|
|
41
|
+
def approved? = status == 'approved'
|
|
42
|
+
def archived? = status == 'archived'
|
|
43
43
|
|
|
44
44
|
def video? = kind == 'video'
|
|
45
45
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
sl:
|
|
2
|
+
testimonials:
|
|
3
|
+
questions:
|
|
4
|
+
- "Kako bi se predstavili in kako uporabljate %{app}?"
|
|
5
|
+
- "Kako vam je %{app} pomagal pri delu?"
|
|
6
|
+
- "Kaj vam je pri %{app} najbolj všeč?"
|
|
7
|
+
consent_prompt: "Kje lahko uporabimo vašo izjavo?"
|
|
8
|
+
consent_public: "Mojo izjavo lahko javno uporabljate pri trženju in prodaji."
|
|
9
|
+
consent_private: "Mojo izjavo lahko uporabljate samo zasebno pri trženju in prodaji."
|
|
10
|
+
cta: "Napišite mnenje"
|
|
11
|
+
update_title: "Posodobite svoje mnenje"
|
|
12
|
+
enjoying: "Ste zadovoljni z uporabo %{app}?"
|
|
13
|
+
not_now: "Ne zdaj"
|
|
14
|
+
rate_aria: "Ocena %{count} od 5"
|
|
15
|
+
share_title: "Delite svojo izkušnjo"
|
|
16
|
+
promoter_title: "Veseli nas! Bi svoje mnenje delili javno?"
|
|
17
|
+
questions_title: "Vprašanja"
|
|
18
|
+
message: "Vaša izjava"
|
|
19
|
+
message_placeholder: "Kaj bi o %{app} povedali prijatelju?"
|
|
20
|
+
record_video: "Posnemi video"
|
|
21
|
+
record_video_hint: "S kratkim videom lahko poveste več kot s stranjo besedila."
|
|
22
|
+
name: "Vaše ime"
|
|
23
|
+
email: "Vaš e-poštni naslov"
|
|
24
|
+
title_company: "Delovno mesto, podjetje"
|
|
25
|
+
photo: "Vaša fotografija"
|
|
26
|
+
optional: "neobvezno"
|
|
27
|
+
submit: "Pošlji"
|
|
28
|
+
cancel: "Prekliči"
|
|
29
|
+
close: "Zapri"
|
|
30
|
+
thanks: "Najlepša hvala!"
|
|
31
|
+
video_check_title: "Preverite kamero"
|
|
32
|
+
video_hint: "Posnetek lahko traja do %{seconds} sekund. Pred pošiljanjem si ga lahko ogledate."
|
|
33
|
+
start_recording: "Začni snemanje"
|
|
34
|
+
stop_recording: "Končaj snemanje"
|
|
35
|
+
record_again: "Posnemi znova"
|
|
36
|
+
use_video: "Uporabi ta video"
|
|
37
|
+
upload_instead: "Naloži videodatoteko"
|
|
38
|
+
video_attached: "Video je priložen"
|
|
39
|
+
remove: "Odstrani"
|
|
40
|
+
nps_question: "Kako verjetno je, da bi %{app} priporočili prijatelju ali sodelavcu?"
|
|
41
|
+
nps_low: "Sploh ni verjetno"
|
|
42
|
+
nps_high: "Zelo verjetno"
|
|
43
|
+
nps_comment_label: "Kaj je glavni razlog za vašo oceno?"
|
|
44
|
+
error_blank: "Napišite mnenje ali posnemite video."
|
|
45
|
+
error_contact: "Vnesite ime in e-poštni naslov."
|
|
46
|
+
error_save: "Odgovora ni bilo mogoče poslati. Poskusite znova."
|
|
47
|
+
error_video_too_large: "Videodatoteka je prevelika (največ %{size} MB)."
|
|
48
|
+
error_camera: "Dostop do kamere ni mogoč. Namesto tega lahko naložite videodatoteko."
|
|
49
|
+
error_rate_limited: "Poslali ste preveč odgovorov. Počakajte trenutek in poskusite znova."
|
|
50
|
+
page:
|
|
51
|
+
title: "Delite svojo izkušnjo z %{app}"
|
|
52
|
+
subtitle: "Vaša izkušnja pomaga drugim pri odločitvi. Hvala!"
|
|
53
|
+
nps_title: "Pomagajte nam izboljšati %{app}"
|
|
54
|
+
nps_subtitle: "Odgovor na eno vprašanje vam bo vzel deset sekund."
|
|
55
|
+
kinds:
|
|
56
|
+
text: "Besedilo"
|
|
57
|
+
video: "Video"
|
|
58
|
+
sources:
|
|
59
|
+
widget: "Gradnik v aplikaciji"
|
|
60
|
+
page: "Stran za zbiranje mnenj"
|
|
61
|
+
nps: "Po oceni NPS"
|
|
62
|
+
statuses:
|
|
63
|
+
pending: "V obravnavi"
|
|
64
|
+
approved: "Odobreno"
|
|
65
|
+
archived: "Arhivirano"
|
|
66
|
+
dashboard:
|
|
67
|
+
title: "Testimonials"
|
|
68
|
+
nps: "NPS"
|
|
69
|
+
nps_page: "Zbiraj ocene NPS"
|
|
70
|
+
collection_page: "Zbiraj izjave"
|
|
71
|
+
download_video: "Prenesi video"
|
|
72
|
+
all_kinds: "Vse vrste"
|
|
73
|
+
search: "Iskanje"
|
|
74
|
+
search_placeholder: "Iščite po besedilu, imenu ali e-poštnem naslovu…"
|
|
75
|
+
rating: "Ocena"
|
|
76
|
+
testimonial: "Izjava"
|
|
77
|
+
from: "Od"
|
|
78
|
+
consent: "Soglasje"
|
|
79
|
+
no_consent: "Samo za zasebno uporabo. Izjava ni dostopna prek API-ja za branje."
|
|
80
|
+
received: "Prejeto"
|
|
81
|
+
featured: "Izpostavljeno"
|
|
82
|
+
approve: "Odobri"
|
|
83
|
+
feature: "Izpostavi"
|
|
84
|
+
unfeature: "Odstrani iz izpostavljenih"
|
|
85
|
+
best_line: "Izbrani citat"
|
|
86
|
+
best_line_hint: "Citat bo prikazan na vašem spletnem mestu. Če polje pustite prazno, bo prikazano celotno besedilo. Pri videu vnesite najpomembnejšo izjavo iz posnetka."
|
|
87
|
+
save_best_line: "Shrani"
|
|
88
|
+
email: "E-pošta"
|
|
89
|
+
source: "Vir"
|
|
90
|
+
page: "Stran"
|
|
91
|
+
locale: "Jezik"
|
|
92
|
+
browser: "Brskalnik"
|
|
93
|
+
empty: "Tu še ni izjav."
|
|
94
|
+
newer: "← Novejše"
|
|
95
|
+
older: "Starejše →"
|
|
96
|
+
move_to_pending: "Označi kot v obravnavi"
|
|
97
|
+
move_to_approved: "Odobri"
|
|
98
|
+
move_to_archived: "Arhiviraj"
|
|
99
|
+
delete: "Izbriši"
|
|
100
|
+
delete_confirm: "Želite izbrisati to izjavo?"
|
|
101
|
+
nps_score: "Ocena NPS"
|
|
102
|
+
promoters: "Promotorji (9–10)"
|
|
103
|
+
passives: "Pasivni (7–8)"
|
|
104
|
+
detractors: "Kritiki (0–6)"
|
|
105
|
+
nps_band_needs_work: "Potrebne so izboljšave"
|
|
106
|
+
nps_band_good: "Dobro"
|
|
107
|
+
nps_band_great: "Zelo dobro"
|
|
108
|
+
nps_band_excellent: "Odlično"
|
|
109
|
+
nps_sample_note: "Ocena temelji na %{count} odgovorih. Za zanesljivo razlago jih je premalo."
|
|
110
|
+
nps_guide: "Kako izračunamo NPS in katera ocena je dobra?"
|
|
111
|
+
nps_guide_formula: "NPS je razlika med odstotkom promotorjev in odstotkom kritikov. Pasivni se upoštevajo v skupnem številu odgovorov, vendar ne v nobeni od obeh skupin, zato rezultat približajo ničli. Ocena je število od −100 do +100."
|
|
112
|
+
nps_guide_needs_work: "Več kritikov kot promotorjev."
|
|
113
|
+
nps_guide_good: "Običajen rezultat za večino podjetij."
|
|
114
|
+
nps_guide_great: "Visoka zvestoba."
|
|
115
|
+
nps_guide_excellent: "Izjemno visok in redek rezultat."
|
|
116
|
+
nps_guide_caveat: "Referenčne vrednosti se med panogami razlikujejo. Pri programski opremi so pogosto okoli 40, pri letalskih družbah in ponudnikih interneta pa okoli 0. Gibanje ocene skozi čas in komentarji povedo več kot posamezna številka."
|
|
117
|
+
score: "Ocena"
|
|
118
|
+
comment: "Komentar"
|
data/docs/ractors.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Rails edge and experimental Ractor hosting
|
|
2
|
+
|
|
3
|
+
The regular CI matrix covers Rails 7.1, 7.2, 8.0 and 8.1. A required Rails
|
|
4
|
+
edge job runs the same suite against `rails/rails` main. A separate job boots
|
|
5
|
+
an eager-loaded host, calls `Rails.application.ractorize!`, and sends real
|
|
6
|
+
Rack requests through the mounted engine in non-main Ractors, including
|
|
7
|
+
simultaneous requests. The Ractor checks run in separate processes because
|
|
8
|
+
Ractorization freezes Rails; they never freeze the ordinary test application.
|
|
9
|
+
|
|
10
|
+
## Host prerequisites
|
|
11
|
+
|
|
12
|
+
Ractor hosting currently requires Ruby 4.0+, Rails main, Rack main's
|
|
13
|
+
`rack/ractorize`, and the unreleased [I18n Ractor support](https://github.com/ruby-i18n/i18n/pull/741).
|
|
14
|
+
`gemfiles/rails_ractor.gemfile` records the exact I18n revision tested. These
|
|
15
|
+
are development/test dependencies, not new runtime dependencies for released
|
|
16
|
+
Rails. The gem's supported dependency range remains Rails >= 7.1 and < 9.
|
|
17
|
+
|
|
18
|
+
For a host experimenting with Ractor hosting, the tested upstream overrides are:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem "rails", github: "rails/rails", branch: "main"
|
|
22
|
+
gem "rack", github: "rack/rack", branch: "main"
|
|
23
|
+
gem "i18n", github: "Shopify/i18n", ref: "58aa1dcd3e04c34831e1c2ec06c83391559c7c91"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Follow Rails' own Ractor hosting requirements: disable reloading, eager-load
|
|
27
|
+
application code, use a shareable logger/cache and a Ractor-compatible job
|
|
28
|
+
adapter. Before application classes load, enable Rails' callback isolation:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
require "active_support/ractors"
|
|
32
|
+
ActiveSupport::Ractors.unshareable_proc_action = :raise
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Our isolated fixture uses `ActiveSupport::Ractors::Logger`, a null
|
|
36
|
+
cache, and (where jobs are loaded) `:inline`. Its separate shared counter proves
|
|
37
|
+
that public submission limits remain effective across worker Ractors. The
|
|
38
|
+
ordinary dummy application's `:test` job adapter is unchanged.
|
|
39
|
+
|
|
40
|
+
The engine prepares itself automatically on `before_ractorize`; ordinary Rails
|
|
41
|
+
boots do not freeze its configuration or load the experimental I18n extension.
|
|
42
|
+
An unavailable I18n Ractor extension produces a startup error explaining the
|
|
43
|
+
prerequisite. Rails edge and Ractor hosting remain experimental: this is not a
|
|
44
|
+
promise that every third-party host middleware, database driver, storage
|
|
45
|
+
service, mail adapter or Action Cable adapter is Ractor safe.
|
|
46
|
+
|
|
47
|
+
## Configuration and callbacks
|
|
48
|
+
|
|
49
|
+
Finish configuring Testimonials before calling `ractorize!`. The engine publishes
|
|
50
|
+
a frozen copy of the configuration and warms/freezes widget JS, CSS and content
|
|
51
|
+
fingerprints. Changes after Ractorization require a process restart. Arrays and
|
|
52
|
+
hashes supplied by the host are copied before freezing.
|
|
53
|
+
|
|
54
|
+
Callbacks are isolated with Ruby's `Ractor.shareable_lambda` or
|
|
55
|
+
`Ractor.shareable_proc`, preserving lambda/proc arity. They continue to receive
|
|
56
|
+
the same request, user, record or event arguments and run on each request.
|
|
57
|
+
Isolated callbacks use arguments and constants; their implicit initializer
|
|
58
|
+
`self` becomes nil, following Rails' isolated callback convention.
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
Testimonials.configure do |config|
|
|
62
|
+
config.enabled = ->(request) { request.get_header("HTTP_X_WIDGET") != "off" }
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Immutable captured values must already be shareable:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
expected_host = "app.example.com".freeze
|
|
70
|
+
Testimonials.configure do |config|
|
|
71
|
+
config.enabled = ->(request) { request.host == expected_host }
|
|
72
|
+
end
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Mutable captures (an array collecting notifications, an unfrozen captured
|
|
76
|
+
string, or reassigned outer locals) cannot be shared. The engine fails at
|
|
77
|
+
startup with `Testimonials.config.<setting>` in the error rather than failing on
|
|
78
|
+
a visitor's request. Use request-local state and external persistence for
|
|
79
|
+
side effects. A pre-isolated callback made with an explicit shareable `self:`
|
|
80
|
+
keeps that receiver. Stateful callable objects must be copyable/shareable;
|
|
81
|
+
custom objects remain subject to Ruby's Ractor rules.
|
|
82
|
+
|
|
83
|
+
## Scope and cost
|
|
84
|
+
|
|
85
|
+
Some Rails main paths are still being converted to Ractors. The engine warms
|
|
86
|
+
model attributes and controller names, prepares ETag callbacks, and supplies
|
|
87
|
+
narrow bridges for mounted URL generation, cache freshness, digest/key
|
|
88
|
+
operations, GlobalID URI decoding and boot-time attribute decorators. Those bridges preserve the
|
|
89
|
+
original operation on the main Ractor; requests, authorization callbacks,
|
|
90
|
+
rendering and persistence orchestration execute in their worker Ractors.
|
|
91
|
+
Adapter name quoting delegates to its original implementation on the main Ractor,
|
|
92
|
+
which preserves escaping and avoids process-global mutable caches in workers.
|
|
93
|
+
Disk-backed uploads use Ractor-local storage clients and plain temporary files
|
|
94
|
+
with explicit cleanup, because Tempfile's generated delegation methods cannot
|
|
95
|
+
be called from another Ractor. MIME registrations must finish before
|
|
96
|
+
Ractorization, when Marcel's MIME tables become immutable. Eager model schema
|
|
97
|
+
preparation adds startup database work.
|
|
98
|
+
The bridges are internal compatibility code, add coordination overhead, and
|
|
99
|
+
must be reviewed as upstream Rails evolves. No throughput improvement is claimed.
|
|
100
|
+
|
|
101
|
+
## Run the checks
|
|
102
|
+
|
|
103
|
+
Use the Ruby configured in `mise.toml`, never macOS's system Ruby.
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
BUNDLE_GEMFILE=gemfiles/rails_edge.gemfile bundle install
|
|
107
|
+
BUNDLE_GEMFILE=gemfiles/rails_edge.gemfile bundle exec rake test
|
|
108
|
+
BUNDLE_GEMFILE=gemfiles/rails_ractor.gemfile bundle install
|
|
109
|
+
BUNDLE_GEMFILE=gemfiles/rails_ractor.gemfile bundle exec rake test:ractor
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The request fixture creates and removes its own temporary database and host;
|
|
113
|
+
it does not reuse or freeze `test/dummy`. The shared schema lives in
|
|
114
|
+
`test/support/schema.rb` so the ordinary and Ractor suites exercise the same
|
|
115
|
+
record shape. Successful checks establish the tested SQLite host and explicit
|
|
116
|
+
request paths, not all combinations of host integrations.
|
|
117
|
+
|
|
118
|
+
The media job also runs with `RACTOR_MEDIA=1`, exercising private disk-backed
|
|
119
|
+
Active Storage downloads through the engine's authorization gate. Storage
|
|
120
|
+
services are initialized per Ractor, and streamed responses use a thread local
|
|
121
|
+
to that Ractor. Livechat additionally runs with `RACTOR_CABLE=1`, checking the
|
|
122
|
+
signed stream token and broadcasts delegated to the main Action Cable server.
|
|
123
|
+
Other storage services and production Cable adapters need host-specific QA.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/testimonials/engine.rb
CHANGED
|
@@ -2,8 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
module Testimonials
|
|
4
4
|
class Engine < ::Rails::Engine
|
|
5
|
+
initializer 'testimonials.ractor_middleware' do |app|
|
|
6
|
+
app.middleware.insert_before 0, RactorSupport::Middleware
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
isolate_namespace Testimonials
|
|
6
10
|
|
|
11
|
+
initializer 'testimonials.ractorize', before: 'action_controller.ractorize' do
|
|
12
|
+
if Rails::Application.method_defined?(:ractorize!)
|
|
13
|
+
Engine.routes.singleton_class.prepend(RactorSupport::MountedRoutes)
|
|
14
|
+
end
|
|
15
|
+
ActiveSupport.on_load(:before_ractorize) { Testimonials::RactorSupport.prepare! }
|
|
16
|
+
end
|
|
17
|
+
|
|
7
18
|
rake_tasks do
|
|
8
19
|
load File.expand_path('../tasks/testimonials_tasks.rake', __dir__)
|
|
9
20
|
end
|
|
@@ -22,8 +22,19 @@ module Testimonials
|
|
|
22
22
|
def has_testimonials(as: :testimonials, key: nil) # rubocop:disable Naming/PredicatePrefix
|
|
23
23
|
resolver = key || ->(record) { record.to_gid.to_s }
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
class_attribute :_testimonials_tenant_resolvers, instance_accessor: false, default: {} unless
|
|
26
|
+
respond_to?(:_testimonials_tenant_resolvers)
|
|
27
|
+
relation_name = as.to_sym
|
|
28
|
+
declaring_model = self
|
|
29
|
+
self._testimonials_tenant_resolvers = _testimonials_tenant_resolvers.merge(relation_name => resolver)
|
|
30
|
+
{ relation_name => :Testimonial, :"#{as}_nps" => :NpsResponse }.each do |name, model|
|
|
31
|
+
getter = proc do
|
|
32
|
+
key_resolver = declaring_model._testimonials_tenant_resolvers.fetch(relation_name)
|
|
33
|
+
Testimonials.const_get(model).for_tenant(key_resolver.call(self))
|
|
34
|
+
end
|
|
35
|
+
getter = Ractor.shareable_proc(&getter) if defined?(Ractor.shareable_proc)
|
|
36
|
+
define_method(name, &getter)
|
|
37
|
+
end
|
|
27
38
|
end
|
|
28
39
|
end
|
|
29
40
|
end
|
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Testimonials
|
|
4
|
+
# Used only by Rails' opt-in before_ractorize hook. Normal Rails boots keep
|
|
5
|
+
# mutable configuration and lazy assets, including on older Ruby versions.
|
|
6
|
+
module RactorSupport
|
|
7
|
+
# Small bridges for framework paths that Rails main does not prepare yet.
|
|
8
|
+
# They are installed only when the host explicitly calls ractorize!.
|
|
9
|
+
# Rails' built-in JSON renderer is still defined from an unisolated Proc.
|
|
10
|
+
# Keep its JSON/JSONP and escaping behavior in a regular Ruby method.
|
|
11
|
+
module JsonRendering
|
|
12
|
+
def _render_with_renderer_json(json, options)
|
|
13
|
+
json_options = options.except(:callback, :content_type, :status)
|
|
14
|
+
json_options[:escape] ||= false if !self.class.escape_json_responses? && options[:callback].blank?
|
|
15
|
+
json = json.to_json(json_options) unless json.is_a?(String)
|
|
16
|
+
if options[:callback].present?
|
|
17
|
+
self.content_type = :js if media_type.nil? || media_type == Mime[:json]
|
|
18
|
+
"/**/#{options[:callback]}(#{json})"
|
|
19
|
+
else
|
|
20
|
+
self.content_type = :json if media_type.nil?
|
|
21
|
+
json
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module DependencyInterlock
|
|
27
|
+
def interlock
|
|
28
|
+
return super if Ractor.main?
|
|
29
|
+
|
|
30
|
+
Ractor[:engine_dependency_interlock] ||= ActiveSupport::Dependencies::Interlock.new
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module LiveThreads
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def new_controller_thread
|
|
38
|
+
return super if Ractor.main?
|
|
39
|
+
|
|
40
|
+
Thread.new do
|
|
41
|
+
Thread.current.abort_on_exception = true
|
|
42
|
+
yield
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
module UniquenessCoverage
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def covered_by_unique_index?(klass, record, attribute, scope)
|
|
51
|
+
return super unless frozen?
|
|
52
|
+
|
|
53
|
+
copies = Ractor[:engine_uniqueness_validators] ||= {}
|
|
54
|
+
copy = copies[[self, klass]] ||= dup
|
|
55
|
+
copy.send(:covered_by_unique_index?, klass, record, attribute, scope)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# GlobalID calls CGI.unescape without an encoding, whose default reads a
|
|
60
|
+
# process-wide class variable. Preserve CGI's configured default on main.
|
|
61
|
+
module UriUnescaping
|
|
62
|
+
def unescape(string, *arguments)
|
|
63
|
+
return super if Ractor.main?
|
|
64
|
+
|
|
65
|
+
shared_arguments = Ractor.make_shareable([string, *arguments], copy: true)
|
|
66
|
+
ActiveSupport::Ractors.on_main(self) { unescape(*shared_arguments) }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
module CacheFreshness
|
|
71
|
+
def strict_freshness
|
|
72
|
+
return super if Ractor.main?
|
|
73
|
+
|
|
74
|
+
ActiveSupport::Ractors.on_main(self) { strict_freshness }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Attribute decorators (including Rails enums and serialized attributes)
|
|
79
|
+
# are boot-time factories. Keep their original receivers and captures on
|
|
80
|
+
# the main Ractor, rather than changing the semantics of Rails' closures.
|
|
81
|
+
class Decorator
|
|
82
|
+
def initialize(callback)
|
|
83
|
+
@key = RactorSupport.register_decorator(callback)
|
|
84
|
+
freeze
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def call(*arguments)
|
|
88
|
+
return RactorSupport.call_decorator(@key, arguments) if Ractor.main?
|
|
89
|
+
|
|
90
|
+
shared_arguments = Ractor.make_shareable(arguments, copy: true)
|
|
91
|
+
ActiveSupport::Ractors.on_main(self) { RactorSupport.call_decorator(@key, shared_arguments) }
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.register_decorator(callback)
|
|
96
|
+
@decorators ||= []
|
|
97
|
+
@decorators << callback
|
|
98
|
+
@decorators.length - 1
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def self.call_decorator(key, arguments)
|
|
102
|
+
@decorators.fetch(key).call(*arguments)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.prepare_attributes(model)
|
|
106
|
+
prepare_attributes(model.superclass) if model.superclass.respond_to?(:pending_attribute_modifications, true)
|
|
107
|
+
model.send(:pending_attribute_modifications)&.each do |modification|
|
|
108
|
+
next unless modification.respond_to?(:decorator) && modification.decorator.is_a?(Proc)
|
|
109
|
+
|
|
110
|
+
modification.decorator = Decorator.new(modification.decorator)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
module AdapterQuoting
|
|
115
|
+
def quote_column_name(name)
|
|
116
|
+
return super if Ractor.main?
|
|
117
|
+
|
|
118
|
+
shared_name = Ractor.make_shareable(name, copy: true)
|
|
119
|
+
ActiveSupport::Ractors.on_main(self) { quote_column_name(shared_name) }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def quote_table_name(name)
|
|
123
|
+
return super if Ractor.main?
|
|
124
|
+
|
|
125
|
+
shared_name = Ractor.make_shareable(name, copy: true)
|
|
126
|
+
ActiveSupport::Ractors.on_main(self) { quote_table_name(shared_name) }
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Route arguments can contain records with native Set caches. Only their
|
|
131
|
+
# to_param value is needed to generate a mount prefix; keep the caller's
|
|
132
|
+
# original record objects in the options passed to the actual route.
|
|
133
|
+
def self.routing_snapshot(value)
|
|
134
|
+
return value if Ractor.shareable?(value)
|
|
135
|
+
|
|
136
|
+
copy = case value
|
|
137
|
+
when ActiveRecord::Base then value.to_param
|
|
138
|
+
when Hash then value.to_h { |key, item| [routing_snapshot(key), routing_snapshot(item)] }
|
|
139
|
+
when Array then value.map { |item| routing_snapshot(item) }
|
|
140
|
+
when Set then Set.new(value.map { |item| routing_snapshot(item) })
|
|
141
|
+
else return Ractor.make_shareable(value, copy: true)
|
|
142
|
+
end
|
|
143
|
+
Ractor.make_shareable(copy)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
module MountedRoutes
|
|
147
|
+
def find_script_name(options)
|
|
148
|
+
return super unless defined?(Ractor.shareable_proc) && !Ractor.main?
|
|
149
|
+
|
|
150
|
+
shared_options = RactorSupport.routing_snapshot(options)
|
|
151
|
+
prefix, updated = ActiveSupport::Ractors.on_main(self) do
|
|
152
|
+
local_options = shared_options.dup
|
|
153
|
+
[find_script_name(local_options), local_options]
|
|
154
|
+
end
|
|
155
|
+
(shared_options.keys - updated.keys).each { |key| options.delete(key) }
|
|
156
|
+
updated.each do |key, value|
|
|
157
|
+
options[key] = value unless shared_options.key?(key) && shared_options[key] == value
|
|
158
|
+
end
|
|
159
|
+
prefix
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
module Digesting
|
|
164
|
+
def hexdigest(value)
|
|
165
|
+
return super if Ractor.main?
|
|
166
|
+
|
|
167
|
+
shared_value = Ractor.make_shareable(value, copy: true)
|
|
168
|
+
ActiveSupport::Ractors.on_main(self) { hexdigest(shared_value) }
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
module KeyGeneration
|
|
173
|
+
def generate_key(salt, key_size = 64)
|
|
174
|
+
return super if Ractor.main?
|
|
175
|
+
|
|
176
|
+
shared_salt = Ractor.make_shareable(salt, copy: true)
|
|
177
|
+
ActiveSupport::Ractors.on_main(self) { generate_key(shared_salt, key_size) }
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
module UploadCleanup
|
|
182
|
+
def open
|
|
183
|
+
reopen(path, 'rb+')
|
|
184
|
+
self
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Tempfile#close takes a positional unlink flag.
|
|
188
|
+
def close(unlink_now = false) # rubocop:disable Style/OptionalBooleanParameter
|
|
189
|
+
super() unless closed?
|
|
190
|
+
unlink if unlink_now
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def unlink
|
|
194
|
+
File.unlink(path)
|
|
195
|
+
rescue Errno::ENOENT
|
|
196
|
+
nil
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def close!
|
|
200
|
+
close(true)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def self.upload_tempfile(filename, _content_type)
|
|
205
|
+
extension = File.extname(filename.gsub("\0", '%00'))[0, 129]
|
|
206
|
+
Tempfile.create(['RackMultipart', extension]).extend(UploadCleanup)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
class Middleware
|
|
210
|
+
def initialize(app)
|
|
211
|
+
@app = app
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def call(env)
|
|
215
|
+
if (fallbacks = RactorSupport.fallbacks)
|
|
216
|
+
Fiber[:i18n_fallbacks] ||= fallbacks
|
|
217
|
+
env['rack.multipart.tempfile_factory'] ||= RactorSupport.method(:upload_tempfile) unless Ractor.main?
|
|
218
|
+
end
|
|
219
|
+
@app.call(env)
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def self.fallbacks
|
|
224
|
+
@fallbacks
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
module StorageMetadata
|
|
228
|
+
def analyzed = read_store_attribute(:metadata, :analyzed)
|
|
229
|
+
def identified = read_store_attribute(:metadata, :identified)
|
|
230
|
+
def composed = read_store_attribute(:metadata, :composed)
|
|
231
|
+
|
|
232
|
+
def analyzed=(value)
|
|
233
|
+
write_store_attribute(:metadata, :analyzed, value)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def identified=(value)
|
|
237
|
+
write_store_attribute(:metadata, :identified, value)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def composed=(value)
|
|
241
|
+
write_store_attribute(:metadata, :composed, value)
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
class StorageServices
|
|
246
|
+
def initialize(configurations)
|
|
247
|
+
@configurations = Ractor.make_shareable(configurations, copy: true)
|
|
248
|
+
freeze
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def fetch(name, &)
|
|
252
|
+
registry = if Ractor.main?
|
|
253
|
+
RactorSupport.storage_registry
|
|
254
|
+
else
|
|
255
|
+
Ractor[:engine_storage_services] ||= ActiveStorage::Service::Registry.new(@configurations)
|
|
256
|
+
end
|
|
257
|
+
registry.fetch(name, &)
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def self.storage_registry
|
|
262
|
+
@storage_registry
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
module StorageChecksums
|
|
266
|
+
def checksum_implementation(**options)
|
|
267
|
+
implementation = super
|
|
268
|
+
if Ractor.main? || !implementation.respond_to?(:name) || !implementation.name&.start_with?('OpenSSL::Digest::')
|
|
269
|
+
return implementation
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
DigestFactory.new(implementation.name.delete_prefix('OpenSSL::Digest::'))
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
class DigestFactory
|
|
277
|
+
def initialize(algorithm)
|
|
278
|
+
@algorithm = algorithm.freeze
|
|
279
|
+
freeze
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def new
|
|
283
|
+
OpenSSL::Digest.new(@algorithm)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def file(io)
|
|
287
|
+
new.file(io)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def base64digest(value)
|
|
291
|
+
new.base64digest(value)
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def self.prepare_redirects!
|
|
296
|
+
base = ActionController::Base
|
|
297
|
+
readers = Module.new
|
|
298
|
+
%i[raise_on_open_redirects action_on_open_redirect action_on_path_relative_redirect].each do |key|
|
|
299
|
+
source = base.method(key).source_location&.first
|
|
300
|
+
next unless source&.end_with?('/action_controller/metal/redirecting.rb')
|
|
301
|
+
|
|
302
|
+
value = Ractor.make_shareable(base.public_send(key), copy: true)
|
|
303
|
+
readers.define_method(key, Ractor.shareable_proc { Ractor.main? ? super() : value })
|
|
304
|
+
end
|
|
305
|
+
return if readers.instance_methods(false).empty?
|
|
306
|
+
|
|
307
|
+
base.prepend(readers)
|
|
308
|
+
base.singleton_class.prepend(readers)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def self.prepare_previewers!
|
|
312
|
+
ActiveStorage.previewers.each do |previewer|
|
|
313
|
+
readers = Module.new
|
|
314
|
+
previewer.methods.grep(/_exists\?\z/).each do |capability|
|
|
315
|
+
method = previewer.method(capability)
|
|
316
|
+
next unless method.arity.zero? && method.source_location&.first&.include?('/active_storage/previewer/')
|
|
317
|
+
|
|
318
|
+
readers.define_method(capability, Ractor.shareable_proc do
|
|
319
|
+
if Ractor.main?
|
|
320
|
+
super()
|
|
321
|
+
else
|
|
322
|
+
ActiveSupport::Ractors.on_main(self) { public_send(capability) }
|
|
323
|
+
end
|
|
324
|
+
end)
|
|
325
|
+
end
|
|
326
|
+
previewer.singleton_class.prepend(readers) unless readers.instance_methods(false).empty?
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def self.prepare_storage!
|
|
331
|
+
return unless defined?(ActiveStorage::Blob)
|
|
332
|
+
|
|
333
|
+
prepare_previewers!
|
|
334
|
+
ActiveStorage::Blob.prepend(StorageMetadata) unless ActiveStorage::Blob < StorageMetadata
|
|
335
|
+
%i[EXTENSIONS TYPE_EXTS TYPE_ALIASES TYPE_PARENTS ROOT_XML MAGIC].each do |name|
|
|
336
|
+
Ractor.make_shareable(Marcel.const_get(name)) if Marcel.const_defined?(name)
|
|
337
|
+
end
|
|
338
|
+
ActiveStorage::Service.prepend(StorageChecksums) unless ActiveStorage::Service < StorageChecksums
|
|
339
|
+
unless Ractor.shareable?(ActiveStorage::Blob.services)
|
|
340
|
+
@storage_registry = ActiveStorage::Blob.services
|
|
341
|
+
configurations = @storage_registry.instance_variable_get(:@configurations)
|
|
342
|
+
default_name = ActiveStorage::Blob.service.name
|
|
343
|
+
default_reader = Module.new
|
|
344
|
+
default_reader.define_method(:service, Ractor.shareable_proc do
|
|
345
|
+
Ractor.main? ? super() : services.fetch(default_name)
|
|
346
|
+
end)
|
|
347
|
+
ActiveStorage::Blob.singleton_class.prepend(default_reader)
|
|
348
|
+
ActiveStorage::Blob.services = StorageServices.new(configurations)
|
|
349
|
+
end
|
|
350
|
+
settings = ActiveStorage.class_variables.map { |name| name.to_s.delete_prefix('@@').to_sym }
|
|
351
|
+
settings.select! { |key| ActiveStorage.respond_to?(key) }
|
|
352
|
+
snapshot = settings.to_h { |key| [key, ActiveStorage.public_send(key)] }
|
|
353
|
+
checksum = snapshot[:checksum_implementation]
|
|
354
|
+
if checksum.is_a?(Class) && checksum.name&.start_with?('OpenSSL::Digest::')
|
|
355
|
+
snapshot[:checksum_implementation] = DigestFactory.new(checksum.name.delete_prefix('OpenSSL::Digest::'))
|
|
356
|
+
end
|
|
357
|
+
Ractor.make_shareable(snapshot)
|
|
358
|
+
readers = Module.new
|
|
359
|
+
settings.each do |key|
|
|
360
|
+
readers.define_method(key, Ractor.shareable_proc { Ractor.main? ? super() : snapshot.fetch(key) })
|
|
361
|
+
end
|
|
362
|
+
ActiveStorage.singleton_class.prepend(readers)
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def self.prepare_framework!
|
|
366
|
+
CGI.singleton_class.prepend(UriUnescaping) unless CGI.singleton_class < UriUnescaping
|
|
367
|
+
Ractor.make_shareable(GlobalID.app) if defined?(GlobalID) && GlobalID.respond_to?(:app)
|
|
368
|
+
I18n.available_locales.each { |locale| I18n.transliterate('ractor', locale: locale) }
|
|
369
|
+
require 'i18n/ractorize'
|
|
370
|
+
require 'tempfile'
|
|
371
|
+
prepare_redirects!
|
|
372
|
+
%i[BASE36_ALPHABET BASE58_ALPHABET].each do |name|
|
|
373
|
+
Ractor.make_shareable(SecureRandom.const_get(name)) if SecureRandom.const_defined?(name)
|
|
374
|
+
end
|
|
375
|
+
uniqueness = ActiveRecord::Validations::UniquenessValidator
|
|
376
|
+
uniqueness.prepend(UniquenessCoverage) unless uniqueness < UniquenessCoverage
|
|
377
|
+
dependencies = ActiveSupport::Dependencies.singleton_class
|
|
378
|
+
dependencies.prepend(DependencyInterlock) unless dependencies < DependencyInterlock
|
|
379
|
+
prepare_storage!
|
|
380
|
+
Ractor.make_shareable(ActiveRecord::Associations::AssociationScope::INSTANCE)
|
|
381
|
+
Ractor.make_shareable(ActionDispatch::Http::Cache::Response::SPECIAL_KEYS)
|
|
382
|
+
freshness = ActionDispatch::Http::Cache::Request.singleton_class
|
|
383
|
+
freshness.prepend(CacheFreshness) unless freshness < CacheFreshness
|
|
384
|
+
fallbacks = I18n.fallbacks
|
|
385
|
+
I18n.available_locales.each { |locale| fallbacks[locale] }
|
|
386
|
+
@fallbacks = Ractor.make_shareable(fallbacks)
|
|
387
|
+
ActiveSupport::Digest.singleton_class.prepend(Digesting) unless ActiveSupport::Digest.singleton_class < Digesting
|
|
388
|
+
ActiveSupport::KeyGenerator.prepend(KeyGeneration) unless ActiveSupport::KeyGenerator < KeyGeneration
|
|
389
|
+
ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool|
|
|
390
|
+
adapter = pool.db_config.adapter_class.singleton_class
|
|
391
|
+
adapter.prepend(AdapterQuoting) unless adapter < AdapterQuoting
|
|
392
|
+
end
|
|
393
|
+
rescue LoadError => e
|
|
394
|
+
raise LoadError,
|
|
395
|
+
"Ractor requests need the upstream I18n Ractor support (see gemfiles/rails_ractor.gemfile): #{e.message}"
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def self.prepare!
|
|
399
|
+
# A cache store can reference the whole middleware stack and freeze
|
|
400
|
+
# other mounted engines before their own hooks run. Warm every engine's
|
|
401
|
+
# request environment before making any of that graph shareable.
|
|
402
|
+
Rails.application.railties.each do |railtie|
|
|
403
|
+
railtie.env_config if railtie.is_a?(Rails::Engine)
|
|
404
|
+
end
|
|
405
|
+
Engine.instance.env_config
|
|
406
|
+
prepare_framework!
|
|
407
|
+
ActiveRecord::Base.descendants.each do |model|
|
|
408
|
+
if model.respond_to?(:_testimonials_tenant_resolvers)
|
|
409
|
+
model._testimonials_tenant_resolvers = share_options(model._testimonials_tenant_resolvers)
|
|
410
|
+
end
|
|
411
|
+
next if model.abstract_class? || !model.table_exists?
|
|
412
|
+
|
|
413
|
+
model.reflect_on_all_associations.each { |reflection| reflection.send(:inverse_name) }
|
|
414
|
+
prepare_attributes(model)
|
|
415
|
+
Ractor.make_shareable(model.defined_enums)
|
|
416
|
+
model.defined_enums.each do |attribute, mapping|
|
|
417
|
+
method_name = attribute.pluralize
|
|
418
|
+
source = model.method(method_name).source_location&.first
|
|
419
|
+
next unless source&.end_with?('/active_record/enum.rb')
|
|
420
|
+
|
|
421
|
+
model.define_singleton_method(method_name, Ractor.shareable_proc { mapping })
|
|
422
|
+
end
|
|
423
|
+
model.define_attribute_methods
|
|
424
|
+
if model.respond_to?(:attachment_reflections)
|
|
425
|
+
model.attachment_reflections.each_value(&:named_variants)
|
|
426
|
+
Ractor.make_shareable(model.attachment_reflections)
|
|
427
|
+
end
|
|
428
|
+
end
|
|
429
|
+
ActionController::Base.descendants.each do |controller|
|
|
430
|
+
next unless controller.name&.start_with?('Testimonials::')
|
|
431
|
+
|
|
432
|
+
controller.prepend(LiveThreads) if defined?(ActionController::Live) && controller < ActionController::Live
|
|
433
|
+
renderer_source = controller.instance_method(:_render_with_renderer_json).source_location&.first
|
|
434
|
+
if renderer_source&.end_with?('/action_controller/metal/renderers.rb') && !(controller < JsonRendering)
|
|
435
|
+
controller.prepend(JsonRendering)
|
|
436
|
+
end
|
|
437
|
+
Ractor.make_shareable(controller.controller_name)
|
|
438
|
+
controller.etaggers = controller.etaggers.map { |callback| Ractor.shareable_proc(&callback) }.freeze
|
|
439
|
+
end
|
|
440
|
+
Testimonials.instance_variable_set(:@config, configuration(Testimonials.config))
|
|
441
|
+
%i[javascript dashboard_javascript dashboard_stylesheet fingerprint
|
|
442
|
+
dashboard_fingerprint dashboard_stylesheet_fingerprint].each do |method|
|
|
443
|
+
next unless Widget.respond_to?(method)
|
|
444
|
+
|
|
445
|
+
Widget.public_send(method)
|
|
446
|
+
end
|
|
447
|
+
ActionController::Base.descendants.each do |controller|
|
|
448
|
+
next unless controller.respond_to?(:testimonials_rate_limit_options)
|
|
449
|
+
|
|
450
|
+
options = controller.testimonials_rate_limit_options
|
|
451
|
+
controller.testimonials_rate_limit_options = share_options(options)
|
|
452
|
+
end
|
|
453
|
+
Widget.instance_variables.each do |variable|
|
|
454
|
+
Widget.instance_variable_set(variable, Ractor.make_shareable(Widget.instance_variable_get(variable)))
|
|
455
|
+
end
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
# Rails edge's rate_limit currently closes over reassigned keyword
|
|
459
|
+
# arguments. A named filter avoids that unshareable closure; the actual
|
|
460
|
+
# counter, cache key and rejection still use Rails' rate_limiting method.
|
|
461
|
+
def self.rate_limit(controller, to:, within:, only:, with:, **options)
|
|
462
|
+
unless Rails::Application.method_defined?(:ractorize!)
|
|
463
|
+
return controller.rate_limit(to: to, within: within, only: only, with: with, **options)
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
controller.class_attribute :testimonials_rate_limit_options, instance_accessor: false
|
|
467
|
+
controller.testimonials_rate_limit_options = {
|
|
468
|
+
to: to, within: within, by: -> { request.remote_ip }, with: with,
|
|
469
|
+
store: controller.cache_store, name: nil, scope: controller.controller_path
|
|
470
|
+
}.merge(options.slice(:by, :store, :name, :scope))
|
|
471
|
+
controller.testimonials_rate_limit_options[:scope] ||= controller.controller_path
|
|
472
|
+
filters = options.except(:by, :store, :name, :scope)
|
|
473
|
+
controller.before_action :testimonials_rate_limit, only: only, **filters
|
|
474
|
+
controller.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
475
|
+
private
|
|
476
|
+
def testimonials_rate_limit
|
|
477
|
+
rate_limiting(**self.class.testimonials_rate_limit_options)
|
|
478
|
+
end
|
|
479
|
+
RUBY
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
def self.share_options(options)
|
|
483
|
+
options.to_h do |key, value|
|
|
484
|
+
value = configuration_value(value) if value.is_a?(Proc)
|
|
485
|
+
[key, Ractor.make_shareable(value)]
|
|
486
|
+
end.freeze
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
def self.configuration_value(value)
|
|
490
|
+
case value
|
|
491
|
+
when Proc
|
|
492
|
+
return value if Ractor.shareable?(value)
|
|
493
|
+
|
|
494
|
+
# Like Rails callbacks, isolated callbacks use arguments and constants,
|
|
495
|
+
# not their initializer's implicit self. Keep lambda/proc arity intact.
|
|
496
|
+
value.lambda? ? Ractor.shareable_lambda(&value) : Ractor.shareable_proc(&value)
|
|
497
|
+
when Hash
|
|
498
|
+
value.to_h { |key, item| [configuration_value(key), configuration_value(item)] }.freeze
|
|
499
|
+
when Array
|
|
500
|
+
value.map { |item| configuration_value(item) }.freeze
|
|
501
|
+
else
|
|
502
|
+
Ractor.make_shareable(value, copy: true)
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
def self.configuration(original)
|
|
507
|
+
prepared = original.dup
|
|
508
|
+
original.instance_variables.each do |variable|
|
|
509
|
+
value = original.instance_variable_get(variable)
|
|
510
|
+
begin
|
|
511
|
+
shared = configuration_value(value)
|
|
512
|
+
prepared.instance_variable_set(variable, shared)
|
|
513
|
+
rescue Ractor::Error, TypeError => e
|
|
514
|
+
setting = variable.to_s.delete_prefix('@')
|
|
515
|
+
raise ArgumentError, "Testimonials.config.#{setting} cannot be shared with Ractors: #{e.message}"
|
|
516
|
+
end
|
|
517
|
+
end
|
|
518
|
+
Ractor.make_shareable(prepared)
|
|
519
|
+
end
|
|
520
|
+
end
|
|
521
|
+
end
|
data/lib/testimonials/version.rb
CHANGED
data/lib/testimonials/widget.rb
CHANGED
|
@@ -10,9 +10,9 @@ module Testimonials
|
|
|
10
10
|
# the engine instead of the host's asset pipeline, and it lives under lib/ so
|
|
11
11
|
# a host that does run a pipeline never ingests it either.
|
|
12
12
|
module Widget
|
|
13
|
-
SOURCE = File.expand_path('widget.js', __dir__)
|
|
14
|
-
DASHBOARD_SOURCE = File.expand_path('dashboard.js', __dir__)
|
|
15
|
-
DASHBOARD_STYLESHEET_SOURCE = File.expand_path('dashboard.css', __dir__)
|
|
13
|
+
SOURCE = File.expand_path('widget.js', __dir__).freeze
|
|
14
|
+
DASHBOARD_SOURCE = File.expand_path('dashboard.js', __dir__).freeze
|
|
15
|
+
DASHBOARD_STYLESHEET_SOURCE = File.expand_path('dashboard.css', __dir__).freeze
|
|
16
16
|
|
|
17
17
|
# Right-to-left scripts, so the form renders mirrored for those locales.
|
|
18
18
|
# Matched on the language subtag, so region variants ("ar-EG") count too.
|
data/lib/testimonials.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: testimonials
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yaroslav Shmarov
|
|
@@ -99,6 +99,7 @@ files:
|
|
|
99
99
|
- config/locales/testimonials.pt.yml
|
|
100
100
|
- config/locales/testimonials.ro.yml
|
|
101
101
|
- config/locales/testimonials.ru.yml
|
|
102
|
+
- config/locales/testimonials.sl.yml
|
|
102
103
|
- config/locales/testimonials.th.yml
|
|
103
104
|
- config/locales/testimonials.tr.yml
|
|
104
105
|
- config/locales/testimonials.uk.yml
|
|
@@ -106,6 +107,29 @@ files:
|
|
|
106
107
|
- config/locales/testimonials.vi.yml
|
|
107
108
|
- config/locales/testimonials.zh-CN.yml
|
|
108
109
|
- config/routes.rb
|
|
110
|
+
- docs/ractors.md
|
|
111
|
+
- docs/screenshots/01-prompt.png
|
|
112
|
+
- docs/screenshots/02-form.png
|
|
113
|
+
- docs/screenshots/03-camera-check.jpg
|
|
114
|
+
- docs/screenshots/04-video-review.jpg
|
|
115
|
+
- docs/screenshots/05-video-attached.png
|
|
116
|
+
- docs/screenshots/admin-ui/after-index-mobile.png
|
|
117
|
+
- docs/screenshots/admin-ui/after-index.png
|
|
118
|
+
- docs/screenshots/admin-ui/after-nps-index-mobile.png
|
|
119
|
+
- docs/screenshots/admin-ui/after-nps-index.png
|
|
120
|
+
- docs/screenshots/admin-ui/after-nps-show-mobile.png
|
|
121
|
+
- docs/screenshots/admin-ui/after-nps-show.png
|
|
122
|
+
- docs/screenshots/admin-ui/after-show-mobile.png
|
|
123
|
+
- docs/screenshots/admin-ui/after-show.png
|
|
124
|
+
- docs/screenshots/admin-ui/before-index.png
|
|
125
|
+
- docs/screenshots/admin-ui/before-nps-index.png
|
|
126
|
+
- docs/screenshots/admin-ui/before-show.png
|
|
127
|
+
- docs/screenshots/dashboard-index.png
|
|
128
|
+
- docs/screenshots/dashboard-show.jpg
|
|
129
|
+
- docs/screenshots/hero.jpg
|
|
130
|
+
- docs/screenshots/nps-01-score.jpg
|
|
131
|
+
- docs/screenshots/nps-02-comment.png
|
|
132
|
+
- docs/screenshots/nps-dashboard.jpg
|
|
109
133
|
- examples/README.md
|
|
110
134
|
- examples/badge.html.erb
|
|
111
135
|
- examples/json_ld.html.erb
|
|
@@ -131,6 +155,7 @@ files:
|
|
|
131
155
|
- lib/testimonials/engine.rb
|
|
132
156
|
- lib/testimonials/has_testimonials.rb
|
|
133
157
|
- lib/testimonials/prompt_helper.rb
|
|
158
|
+
- lib/testimonials/ractor_support.rb
|
|
134
159
|
- lib/testimonials/seeds.rb
|
|
135
160
|
- lib/testimonials/version.rb
|
|
136
161
|
- lib/testimonials/widget.js
|
|
@@ -159,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
159
184
|
- !ruby/object:Gem::Version
|
|
160
185
|
version: '0'
|
|
161
186
|
requirements: []
|
|
162
|
-
rubygems_version: 4.0.
|
|
187
|
+
rubygems_version: 4.0.20
|
|
163
188
|
specification_version: 4
|
|
164
189
|
summary: 'Testimonials, reviews and NPS for Rails: in-app collection widget, public
|
|
165
190
|
collection page, triage dashboard, and a read API.'
|