bible270 1.18.0 → 1.19.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1932d8cdbae32aa00b8a05785ca6c680b403fa3be0be733752e9a6a2af1f99f6
4
- data.tar.gz: ddb45896f1678fff0b941444a7a321b3769952160e8bfc5e4cc6929019d8b8d0
3
+ metadata.gz: 3dfc37decf954d5e4c09a801dd5351bb92bf581f76488d2313713ecfdb19ae20
4
+ data.tar.gz: 978863928b51813457d448ef3fb8c7744416a85917b53bdce0981309a4eabf5a
5
5
  SHA512:
6
- metadata.gz: b9b08e64471767bab9832574dbbdfc6c44f9fa23989fdc4cc99c2ca84c64cfdd939bd1ad1d3d95446cbe8b11e8121738306c5eac27e2ffab9fbea073d99967e9
7
- data.tar.gz: 5b4412c468de22d275f2274056f381ec980785273177dc1333e7a5eaba30b853a04ded9598e6ad557e42b4106a4883e7c18775ecc97326c693de9aa7b85a3dd2
6
+ metadata.gz: 7060fdc5566ff5bafd10f879fa99b9d353beace15e657ab6dc9c484496aa80d14caac3b6a094694393e2fb39c360a28bfa955635c6d1e7010be5dc4e96b16a05
7
+ data.tar.gz: b9cc997a2d380e110eaf34b2f5c74c454834c2488fc4585ce7cbf0e02a168a336808f7e34852b525073639d668afb15f6ac6dbe92188497e8ac4f29b1774868d
data/CHANGELOG.md CHANGED
@@ -4,6 +4,32 @@ Notable changes, following [Keep a Changelog](https://keepachangelog.com/en/1.1.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ### Changed
8
+
9
+ - give longer completion passages more reading time, from 5.5 to 30 seconds
10
+ - rotate Scripture frames in shuffled rounds shared by the bread popup and day completion
11
+ - speed up tests with balanced files, leaner fixtures, and CPU-aware image processing
12
+ - reuse unchanged reading-plan cache settings while preserving live configuration updates
13
+
14
+ **Upgrade:** Install migration `20260101000029` to save readers' rotation across visits and devices.
15
+
16
+ ## [1.18.1] - 2026-11-14
17
+
18
+ ### Added
19
+
20
+ - expand the bundled Scripture frame collection
21
+
22
+ ### Changed
23
+
24
+ - collapse Progress sync, Their reflections, and Completions on Admin reader pages; keep the completion summary visible
25
+
26
+ ### Fixed
27
+
28
+ - display the last sync time in the system time zone instead of UTC
29
+ - guard sync-secret configuration in setup examples so Docker builds need no runtime secrets
30
+
31
+ ## [1.18.0] - 2026-11-14
32
+
7
33
  ### Added
8
34
 
9
35
  - let admins link matching reader accounts for one-way progress sync, including existing completions
@@ -11,6 +37,10 @@ Notable changes, following [Keep a Changelog](https://keepachangelog.com/en/1.1.
11
37
 
12
38
  **Setup:** Install migration `20260101000028` on each instance, configure trusted connections, and schedule delivery on the primary. Progress sync is off until configured.
13
39
 
40
+ ### Fixed
41
+
42
+ - make the sync job test adapter compatible with Rails 7.2
43
+
14
44
  ## [1.17.2] - 2026-11-13
15
45
 
16
46
  ### Added
@@ -893,7 +923,9 @@ This is the initial public release.
893
923
 
894
924
  - Email sign-in requires working Action Mailer delivery in the host application. Set `config.mailer_from`; delivery is inline by default, or set `email_sign_in_deliver_later` when a queue backend is available.
895
925
 
896
- [Unreleased]: https://github.com/avonderluft/bible270/compare/v1.17.2...main
926
+ [Unreleased]: https://github.com/avonderluft/bible270/compare/v1.18.1...main
927
+ [1.18.1]: https://github.com/avonderluft/bible270/compare/v1.18.0...v1.18.1
928
+ [1.18.0]: https://github.com/avonderluft/bible270/compare/v1.17.2...v1.18.0
897
929
  [1.17.2]: https://github.com/avonderluft/bible270/compare/v1.17.1...v1.17.2
898
930
  [1.17.1]: https://github.com/avonderluft/bible270/compare/v1.17.0...v1.17.1
899
931
  [1.17.0]: https://github.com/avonderluft/bible270/compare/v1.16.0...v1.17.0
data/README.md CHANGED
@@ -264,6 +264,8 @@ The `admin_resolver` callback takes precedence over `admin_emails`.
264
264
 
265
265
  Authorized readers get an **Admin** link. **View as non-admin** hides admin details and disables all administration for this session, including role and membership changes. You remain signed in; reflections and active check-offs still work. Use **Return to admin view** in the Admin tab or sign in again to restore access. Roles and other sessions are unchanged.
266
266
 
267
+ Reader pages start with **Progress sync**, **Their reflections**, and **Completions** collapsed. Completion counts, percentage, and schedule status remain visible.
268
+
267
269
  The panel supports:
268
270
 
269
271
  - Sort active readers by name, completed days, activity, or consistency; **Reader Stats** follows the same sort.
@@ -321,22 +323,26 @@ On the **primary**:
321
323
 
322
324
  ```ruby
323
325
  config.progress_sync_instance_id = 'primary'
324
- config.progress_sync_destinations = {
325
- 'church' => {
326
- label: 'Church', url: 'https://church.example/daily-bread',
327
- secret: ENV.fetch('B270_PRIMARY_CHURCH_SYNC_SECRET')
326
+ if (sync_secret = ENV['B270_PRIMARY_CHURCH_SYNC_SECRET'])
327
+ config.progress_sync_destinations = {
328
+ 'church' => {
329
+ label: 'Church', url: 'https://church.example/daily-bread',
330
+ secret: sync_secret
331
+ }
328
332
  }
329
- }
333
+ end
330
334
  ```
331
335
 
332
336
  On the **destination**:
333
337
 
334
338
  ```ruby
335
- config.progress_sync_sources = {
336
- 'primary' => { secret: ENV.fetch('B270_PRIMARY_CHURCH_SYNC_SECRET') }
337
- }
339
+ if (sync_secret = ENV['B270_PRIMARY_CHURCH_SYNC_SECRET'])
340
+ config.progress_sync_sources = { 'primary' => { secret: sync_secret } }
341
+ end
338
342
  ```
339
343
 
344
+ Supply the secret at container runtime, not during image builds. Without it, sync stays disabled.
345
+
340
346
  Use the same randomly generated secret on both sides, at least 32 characters; `bin/rails secret` can generate one. Use a separate secret for each destination. URLs must be canonical HTTPS engine mount URLs, without redirects. Trust authorizes the primary's admins to link accounts by email; grant it only to installations you control or trust.
341
347
 
342
348
  Schedule this command **every minute on the primary**, using the host's scheduler:
@@ -408,7 +414,9 @@ For a host Content Security Policy (CSP), add `https://www.youtube-nocookie.com`
408
414
 
409
415
  Hover over the bread icon for **3 seconds**, or open it immediately by tap, click, or Enter/Space. The random, theme-matched frame closes when you leave a hover preview, press Escape, click outside, or select the bread again.
410
416
 
411
- Completing a day shows a random frame followed by the optional dove; both fade out together. Disabling the dove keeps the frame. Reduced-motion users see a static frame, and Escape dismisses the sequence.
417
+ Completion frames stay fully visible for **5.5–30 seconds**, based on passage length, before the optional dove and shared fade. Disabling the dove keeps the frame. Reduced-motion users see a static frame, and Escape dismisses the sequence.
418
+
419
+ The popup and completion frames share a shuffled rotation: each enabled text is selected before repeating, without back-to-back repeats when alternatives exist. Changing the available texts starts a fresh round. Migration `20260101000029` saves signed-in readers' rotation across visits and devices; visitors and installations awaiting migration use browser-session rotation.
412
420
 
413
421
  The [bundled YAML catalog](config/scripture_frames.yml) supplies the defaults in biblical order. Manage texts under **Admin → Scripture frames**:
414
422
 
@@ -757,9 +765,9 @@ node --test test/javascript/*.cjs
757
765
  bundle exec rubocop --cache false
758
766
  ```
759
767
 
760
- `rake test` uses up to eight CPU-aware workers and writes coverage to `coverage/index.html`. Tests share setup in `test/support`.
768
+ `rake test` uses up to 16 CPU-aware workers and writes coverage to `coverage/index.html`. Tests share setup in `test/support`; libvips uses one thread per worker to avoid CPU contention.
761
769
 
762
- Use `PARALLEL_WORKERS=4 bundle exec rake test` to choose the count, or `bundle exec rake test:serial` for serial coverage. Logs keep warnings and errors in `test/dummy/log/test-*.log`; set `TEST_LOG_LEVEL=debug` for request, template, and SQL details.
770
+ Use `PARALLEL_WORKERS=4 bundle exec rake test` to limit CPU/memory use, or `bundle exec rake test:serial` for serial coverage. `VIPS_CONCURRENCY` overrides image-processing threads. Logs keep warnings and errors in `test/dummy/log/test-*.log`; `TEST_LOG_LEVEL=debug` adds request/SQL details and `TEST_ERROR_PAGES=1` enables developer error pages. Unexpected errors still raise.
763
771
 
764
772
  JavaScript tests require **Node.js 22+**. Chromium layout checks run when a browser is available (`CHROME_BIN` selects it). Video tests do not contact YouTube; check live playback and host CSP separately.
765
773
 
data/Rakefile CHANGED
@@ -161,13 +161,15 @@ namespace :test do
161
161
  Rake::Task['test:serial'].enhance(['test:prepare_serial'])
162
162
 
163
163
  task :parallel do
164
- workers = ENV.fetch('PARALLEL_WORKERS') { Etc.nprocessors.clamp(1, 8).to_s }
164
+ workers = ENV.fetch('PARALLEL_WORKERS') { Etc.nprocessors.clamp(1, 16).to_s }
165
165
  FileUtils.rm_rf('coverage')
166
166
  env = {
167
167
  'PARALLEL_COVERAGE' => 'true',
168
168
  'RECORD_RUNTIME' => 'true',
169
169
  'SKIP_COV' => nil,
170
170
  'NO_COLOR' => '1',
171
+ # Parallel processes already use the CPUs; avoid nested libvips thread pools.
172
+ 'VIPS_CONCURRENCY' => ENV.fetch('VIPS_CONCURRENCY', '1'),
171
173
  'TMPDIR' => ENV.fetch('BIBLE270_TEST_TMPDIR', '/tmp')
172
174
  }
173
175
  command = ['bundle', 'exec', 'parallel_test', 'test', '--type', 'test', '-n', workers]
@@ -7,7 +7,7 @@ module Bible270
7
7
  return head :not_acceptable unless request.format.json?
8
8
 
9
9
  exclude = params[:exclude] if params[:exclude].is_a?(String)
10
- frame = ScriptureFrames.random(exclude: exclude)
10
+ frame = ScriptureFrames.random(exclude: exclude, reader: current_reader, session: session)
11
11
  return head :no_content unless frame
12
12
 
13
13
  render json: frame.to_h
@@ -7,8 +7,12 @@
7
7
  .where(bible270_participations: { reader_id: @reader.id }).includes(:participation).order(created_at: :desc, id: :desc).to_a : []
8
8
  %>
9
9
  <% if destinations.any? || links.any? %>
10
- <section class="b270-panel b270-progress-sync" id="b270-progress-sync" aria-labelledby="b270-progress-sync-heading">
11
- <h2 class="b270-subhead" id="b270-progress-sync-heading">Progress sync</h2>
10
+ <details class="b270-panel b270-admin-section" id="b270-progress-sync-panel">
11
+ <summary id="b270-progress-sync-heading">
12
+ <span class="b270-disclosure-show">Show Progress sync</span>
13
+ <span class="b270-disclosure-hide">Hide Progress sync</span>
14
+ </summary>
15
+ <section class="b270-progress-sync b270-admin-section-content" id="b270-progress-sync" aria-labelledby="b270-progress-sync-heading">
12
16
  <p class="b270-hint">New check-offs sync one way to an account with the same email.</p>
13
17
  <% unless schema_available %>
14
18
  <p class="b270-flash alert">Progress sync needs a site update. Contact the site administrator.</p>
@@ -62,7 +66,7 @@
62
66
  <p><strong><%= label %></strong> · <%= link.remote_name %> · <%= link.status %></p>
63
67
  <p class="b270-hint">
64
68
  Run <%= link.participation.plan_run_id %> ·
65
- Last synced: <%= link.last_synced_at ? link.last_synced_at.strftime('%b %-d, %Y %H:%M %Z') : 'Never' %> ·
69
+ Last synced: <%= link.last_synced_at ? b270_datetime(link.last_synced_at) : 'Never' %> ·
66
70
  Pending: <%= link.pending_count %>
67
71
  <% unless link.last_added.nil? || link.last_existing.nil? %>
68
72
  · <%= link.last_added %> added; <%= link.last_existing %> already present
@@ -88,5 +92,6 @@
88
92
  </ul>
89
93
  <% end %>
90
94
  <% end %>
91
- </section>
95
+ </section>
96
+ </details>
92
97
  <% end %>
@@ -0,0 +1,4 @@
1
+ <%# locals: (reader:, days_completed:, percentage: false) %>
2
+ <%= days_completed %>/<%= Bible270::Plan::DAYS %> days
3
+ <% if percentage %>· <%= (days_completed.to_f / Bible270::Plan::DAYS * 100).round %>%<% end %>
4
+ · <%= reader.progress_status(completed_days: days_completed) %>
@@ -19,8 +19,7 @@
19
19
  <%= reader.provider %>
20
20
  <% end %>
21
21
  <% if reader.dated? %>· started <%= reader.effective_start_date.strftime('%b %-d, %Y') %><% end %>
22
- · <%= days_completed[reader.id] %>/<%= Bible270::Plan::DAYS %> days
23
- · <%= report.status_for(reader) %>
22
+ · <%= render 'bible270/admin/reader_completion_summary', reader: reader, days_completed: days_completed[reader.id] %>
24
23
  </div>
25
24
  <% consistency = report.consistency_for(reader) %>
26
25
  <div class="sub b270-reader-consistency">
@@ -201,14 +201,29 @@
201
201
 
202
202
  <%= render 'progress_sync' %>
203
203
 
204
- <div class="b270-panel">
205
- <%= render "bible270/shared/interaction_status" %>
206
- <%= render "bible270/shared/reflections", comments: @comments, moderate: true, editable: true, actions: true %>
207
- </div>
204
+ <%= render "bible270/shared/interaction_status" %>
205
+ <details class="b270-panel b270-admin-section" id="b270-reader-reflections">
206
+ <summary>
207
+ <span class="b270-disclosure-show">Show Their reflections</span>
208
+ <span class="b270-disclosure-hide">Hide Their reflections</span>
209
+ </summary>
210
+ <div class="b270-admin-section-content">
211
+ <%= render "bible270/shared/reflections", comments: @comments, title: nil, moderate: true, editable: true, actions: true %>
212
+ </div>
213
+ </details>
208
214
 
209
215
 
210
- <div class="b270-panel">
211
- <h2 class="b270-subhead">Completions</h2>
216
+ <details class="b270-panel b270-admin-section" id="b270-reader-completions">
217
+ <summary>
218
+ <span class="b270-disclosure-label">
219
+ <span class="b270-disclosure-show">Show Completions</span>
220
+ <span class="b270-disclosure-hide">Hide Completions</span>
221
+ </span>
222
+ <span class="b270-completions-summary">
223
+ <%= render 'reader_completion_summary', reader: @reader, days_completed: @days_completed, percentage: true %>
224
+ </span>
225
+ </summary>
226
+ <div class="b270-admin-section-content">
212
227
  <% unless @reader.alumni? %>
213
228
  <%= form_with url: admin_reader_through_path(@reader), method: :patch, class: "b270-startform" do %>
214
229
  <%= hidden_field_tag :participation_id, @reader.participation.id %>
@@ -234,7 +249,8 @@
234
249
  <% end %>
235
250
  </div>
236
251
  <p class="b270-hint"><%= @reader.alumni? ? 'Archived completions are read-only.' : 'Click a day to toggle it complete.' %></p>
237
- </div>
252
+ </div>
253
+ </details>
238
254
 
239
255
  <% if @past_participations.any? %>
240
256
  <div class="b270-panel" id="b270-run-history">
@@ -1,5 +1,5 @@
1
1
  <%# locals: (day:, reader:, completion_event_id:) %>
2
- <% frame = Bible270::ScriptureFrames.random %>
2
+ <% frame = Bible270::ScriptureFrames.random(reader: reader, session: session) %>
3
3
  <div class="b270-completion" data-b270-completion data-b270-day="<%= day %>"
4
4
  data-b270-completion-event="<%= completion_event_id %>" data-turbo-temporary hidden>
5
5
  <% if frame %>
@@ -72,6 +72,12 @@
72
72
  if (current(state) && !state.finishing) dispose(state);
73
73
  }
74
74
 
75
+ function holdDuration(state) {
76
+ const text = state.frame.querySelector("[data-b270-scripture-text]")?.textContent || "";
77
+ const wordCount = text.match(/[^\s\p{White_Space}]+/gu)?.length || 0;
78
+ return Math.min(30000, Math.max(5500, 2000 + wordCount * 250));
79
+ }
80
+
75
81
  function fly(state) {
76
82
  if (!current(state)) return;
77
83
  if (!state.dove || motion?.matches) {
@@ -109,7 +115,7 @@
109
115
  state.raf = null;
110
116
  if (!current(state)) return;
111
117
  element.classList.add("is-visible");
112
- if (state.frame) later(state, () => fly(state), fadeInDuration() + 5500);
118
+ if (state.frame) later(state, () => fly(state), fadeInDuration() + holdDuration(state));
113
119
  else fly(state);
114
120
  });
115
121
  }
@@ -779,6 +779,17 @@
779
779
  .b270-footer p{margin:0;line-height:1.5}
780
780
  details.b270-index>summary{cursor:pointer;font-family:"Spectral",serif;font-size:18px;font-weight:600;list-style:none;margin-top:30px}
781
781
  details.b270-index>summary::-webkit-details-marker{display:none}
782
+ details.b270-admin-section>summary{display:flex;align-items:center;flex-wrap:wrap;gap:8px 16px;cursor:pointer;
783
+ list-style:none;font-family:"Spectral",serif;font-size:18px;font-weight:600}
784
+ details.b270-admin-section>summary::-webkit-details-marker{display:none}
785
+ details.b270-admin-section>summary:focus-visible{outline:2px solid var(--gold);outline-offset:4px;border-radius:4px}
786
+ .b270-admin-section>summary .b270-disclosure-hide{display:none}
787
+ .b270-admin-section[open]>summary .b270-disclosure-show{display:none}
788
+ .b270-admin-section[open]>summary .b270-disclosure-hide{display:inline}
789
+ .b270-admin-section:not([open])>:not(summary){display:none}
790
+ .b270-admin-section-content{margin-top:12px}
791
+ .b270-disclosure-label{flex:none}
792
+ .b270-completions-summary{min-width:0;font-family:system-ui,sans-serif;font-size:12.5px;font-weight:400;color:var(--muted)}
782
793
  details.b270-active-readers{margin-bottom:24px}
783
794
  details.b270-active-readers>summary{margin:0 0 12px}
784
795
  details.b270-active-readers .b270-active-readers-hide{display:none}
@@ -13,6 +13,16 @@
13
13
  translation: ESV
14
14
  text: But the word is very near you. It is in your mouth and in your heart, so that you can do it.
15
15
  attribution: ESV © 2001 Crossway.
16
+ - id: psalm-1-1-2
17
+ reference: Psalm 1:1-2
18
+ translation: NASB95
19
+ text: |-
20
+ How blessed is the man who does not walk in the counsel of the wicked,
21
+ Nor stand in the path of sinners,
22
+ Nor sit in the seat of scoffers!
23
+ But his delight is in the law of the LORD,
24
+ And in His law he meditates day and night.
25
+ attribution: NASB 1995 © The Lockman Foundation.
16
26
  - id: psalm-19-8
17
27
  reference: Psalm 19:8
18
28
  translation: NKJV
@@ -69,6 +79,13 @@
69
79
  The unfolding of Your words gives light;
70
80
  It gives understanding to the simple.
71
81
  attribution: NASB 1995 © The Lockman Foundation.
82
+ - id: psalm-119-162
83
+ reference: Psalm 119:162
84
+ translation: NASB95
85
+ text: |-
86
+ I rejoice at Your word,
87
+ As one who finds great spoil.
88
+ attribution: NASB 1995 © The Lockman Foundation.
72
89
  - id: proverbs-6-23
73
90
  reference: Proverbs 6:23
74
91
  translation: NASB95
@@ -83,6 +100,16 @@
83
100
  He who gives attention to the word will find good,
84
101
  And blessed is he who trusts in the LORD.
85
102
  attribution: NASB 1995 © The Lockman Foundation.
103
+ - id: isaiah-40-7-8
104
+ reference: Isaiah 40:7-8
105
+ translation: NASB95
106
+ text: |-
107
+ The grass withers, the flower fades,
108
+ When the breath of the LORD blows upon it;
109
+ Surely the people are grass.
110
+ The grass withers, the flower fades,
111
+ But the word of our God stands forever.
112
+ attribution: NASB 1995 © The Lockman Foundation.
86
113
  - id: isaiah-55-11
87
114
  reference: Isaiah 55:11
88
115
  translation: ESV
@@ -92,6 +119,16 @@
92
119
  but it shall accomplish that which I purpose,
93
120
  and shall succeed in the thing for which I sent it.
94
121
  attribution: ESV © 2001 Crossway.
122
+ - id: isaiah-66-2
123
+ reference: Isaiah 66:2
124
+ translation: ESV
125
+ text: |-
126
+ All these things my hand has made,
127
+ and so all these things came to be, declares the LORD.
128
+ But this is the one to whom I will look:
129
+ he who is humble and contrite in spirit
130
+ and trembles at my word.
131
+ attribution: ESV © 2001 Crossway.
95
132
  - id: jeremiah-15-16
96
133
  reference: Jeremiah 15:16
97
134
  translation: NASB95
@@ -108,6 +145,11 @@
108
145
  “Is not My word like a fire?” says the LORD,
109
146
  “And like a hammer that breaks the rock in pieces?
110
147
  attribution: NKJV © 1982 Thomas Nelson.
148
+ - id: matthew-24-35
149
+ reference: Matthew 24:35
150
+ translation: NKJV
151
+ text: Heaven and earth will pass away, but My words will by no means pass away.
152
+ attribution: NKJV © 1982 Thomas Nelson.
111
153
  - id: john-6-63
112
154
  reference: John 6:63
113
155
  translation: NKJV
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddScriptureFrameRotationToBible270Readers < ActiveRecord::Migration[7.0]
4
+ def change
5
+ add_column :bible270_readers, :scripture_frame_rotation, :json, null: false, default: {}
6
+ end
7
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  module Bible270
4
6
  # Repairs schema_migrations after a database is copied without matching migration
5
7
  # bookkeeping. A migration is safe to mark only when every table, column and
@@ -38,6 +40,7 @@ module Bible270
38
40
  'AddRevertToBible270PlanRuns' => :check_run_revert,
39
41
  'CreateBible270ScriptureFrames' => :check_scripture_frames,
40
42
  'CreateBible270ProgressSync' => :check_progress_sync,
43
+ 'AddScriptureFrameRotationToBible270Readers' => :check_scripture_frame_rotation,
41
44
 
42
45
  'CreateActiveStorageTables' => :check_active_storage
43
46
  }.freeze
@@ -307,6 +310,12 @@ module Bible270
307
310
  progress_sync_relationships_missing + progress_sync_link_indexes_missing
308
311
  end
309
312
 
313
+ def check_scripture_frame_rotation
314
+ table_missing(:bible270_readers, columns: %i[scripture_frame_rotation]) +
315
+ missing_column_definitions(:bible270_readers,
316
+ scripture_frame_rotation: { type: :json, null: false, default: {} })
317
+ end
318
+
310
319
  def check_admin
311
320
  table_missing(:bible270_readers, columns: %i[admin]) +
312
321
  missing_column_definitions(:bible270_readers, admin: { type: :boolean, null: false, default: false })
@@ -489,6 +498,13 @@ module Bible270
489
498
  connection.columns(table).flat_map do |column|
490
499
  definitions.fetch(column.name.to_sym, {}).filter_map do |attribute, expected|
491
500
  actual = column.public_send(attribute)
501
+ if attribute == :default && column.type == :json && actual.is_a?(String)
502
+ begin
503
+ actual = JSON.parse(actual)
504
+ rescue JSON::ParserError
505
+ # Leave malformed defaults unmatched.
506
+ end
507
+ end
492
508
  actual = ActiveModel::Type::Boolean.new.cast(actual) if attribute == :default && column.type == :boolean
493
509
  if attribute == :default && column.type == :integer && actual.is_a?(String) && actual.match?(%r{\A[+-]?\d+\z})
494
510
  actual = Integer(actual, 10)
data/lib/bible270/plan.rb CHANGED
@@ -187,7 +187,7 @@ module Bible270
187
187
  # Validated on the way out so a typo fails loudly instead of silently
188
188
  # producing overlapping or out-of-range readings.
189
189
  def chapter_breaks_for(book, chapter)
190
- points = configured_breaks[[book, chapter]]
190
+ points = cached_configured_breaks[[book, chapter]]
191
191
  return nil if points.nil?
192
192
 
193
193
  total = verses_for(book, chapter)
@@ -197,13 +197,13 @@ module Bible270
197
197
  "verse numbers between 1 and #{total - 1}, got #{points.inspect}"
198
198
  end
199
199
 
200
- points
200
+ points.dup
201
201
  end
202
202
 
203
203
  # {index => reading count} for chapters whose breaks are set explicitly.
204
204
  def pinned_from_breaks(chapters)
205
205
  chapters.each_with_index.filter_map do |(book, chapter), idx|
206
- points = configured_breaks[[book, chapter]]
206
+ points = cached_configured_breaks[[book, chapter]]
207
207
  [idx, points.size + 1] if points
208
208
  end.to_h
209
209
  end
@@ -233,7 +233,7 @@ module Bible270
233
233
  # all at once rather than leaving a half-rebuilt plan.
234
234
 
235
235
  def memo(key)
236
- fingerprint = configured_breaks
236
+ fingerprint = cached_configured_breaks
237
237
  if @cache_fingerprint != fingerprint
238
238
  @cache = {}
239
239
  @cache_fingerprint = fingerprint
@@ -247,6 +247,10 @@ module Bible270
247
247
  def reset!
248
248
  @cache = {}
249
249
  @cache_fingerprint = nil
250
+ @break_source_fingerprint = nil
251
+ @configured_breaks = nil
252
+ @file_breaks_stamp = nil
253
+ @file_breaks = nil
250
254
  true
251
255
  end
252
256
 
@@ -257,11 +261,26 @@ module Bible270
257
261
  # Bible270.config.chapter_breaks_path. The file is re-read whenever it
258
262
  # changes, so break points can be tuned without restarting the server.
259
263
 
264
+ # Keep the public result mutable without exposing the internal cache.
260
265
  def configured_breaks
261
- base = CHAPTER_BREAKS.merge(config_breaks)
266
+ cached_configured_breaks.to_h { |(book, chapter), points| [[book.dup, chapter], points.dup] }
267
+ end
268
+
269
+ def cached_configured_breaks
270
+ # Normalization snapshots mutable override arrays on every lookup.
271
+ overrides = config_breaks
262
272
  path = breaks_file_path
263
- path ? base.merge(file_breaks(path)) : base
273
+ from_file = file_breaks(path) if path
274
+ fingerprint = [CHAPTER_BREAKS, overrides, path && @file_breaks_stamp, from_file]
275
+ return @configured_breaks if @break_source_fingerprint == fingerprint
276
+
277
+ merged = CHAPTER_BREAKS.merge(overrides)
278
+ merged.merge!(from_file) if from_file
279
+ @configured_breaks = merged.freeze
280
+ @break_source_fingerprint = fingerprint
281
+ @configured_breaks
264
282
  end
283
+ private_class_method :cached_configured_breaks
265
284
 
266
285
  def config_breaks
267
286
  return {} unless bible270_config.respond_to?(:chapter_breaks)
@@ -284,11 +303,12 @@ module Bible270
284
303
  # not re-parsed on every request.
285
304
  def file_breaks(path)
286
305
  stat = File.stat(path)
287
- stamp = [path, stat.mtime.to_f, stat.size]
306
+ stamp = [path.dup, stat.mtime.to_f, stat.size]
288
307
  return @file_breaks if @file_breaks_stamp == stamp
289
308
 
309
+ parsed = parse_breaks_file(path)
290
310
  @file_breaks_stamp = stamp
291
- @file_breaks = parse_breaks_file(path)
311
+ @file_breaks = parsed
292
312
  end
293
313
 
294
314
  def parse_breaks_file(path)
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'json'
5
+ require 'securerandom'
6
+
7
+ module Bible270
8
+ class ScriptureFrameRotation
9
+ SESSION_KEY = 'bible270_scripture_frame_rotation'
10
+ COLUMN = 'scripture_frame_rotation'
11
+ HEX_DIGEST = %r{\A[0-9a-f]{64}\z}
12
+ SEED = %r{\A[0-9a-f]{16}\z}
13
+ private_constant :COLUMN, :HEX_DIGEST, :SEED
14
+
15
+ def self.select(pool, reader: nil, session: nil, exclude: nil)
16
+ rotation = new(pool, exclude: exclude)
17
+ if reader&.persisted? && Reader.column_names.include?(COLUMN)
18
+ # Never lock the request's reader: it may carry unsaved profile changes.
19
+ locked = Reader.find(reader.id)
20
+ locked.with_lock do
21
+ frame, state = rotation.advance(locked[COLUMN])
22
+ locked.update_column(COLUMN, state) unless locked[COLUMN] == state
23
+ frame
24
+ end
25
+ else
26
+ rotation.select_from_session(session, reader)
27
+ end
28
+ end
29
+
30
+ def initialize(pool, exclude: nil)
31
+ @pool = pool.sort_by(&:id)
32
+ @catalog = Digest::SHA256.hexdigest(JSON.generate(@pool.map(&:id)))
33
+ @exclude = exclude if exclude.is_a?(String)
34
+ end
35
+
36
+ def select_from_session(session, reader)
37
+ return @pool.reject { |frame| @pool.length > 1 && frame.id == @exclude }.sample unless session
38
+
39
+ identity = reader&.id ? "reader:#{reader.id}" : 'visitor'
40
+ entry = session[SESSION_KEY]
41
+ previous = entry['state'] if entry.is_a?(Hash) && entry['identity'] == identity
42
+ frame, state = advance(previous)
43
+ session[SESSION_KEY] = { 'identity' => identity, 'state' => state }
44
+ frame
45
+ end
46
+
47
+ def advance(previous)
48
+ return [nil, {}] if @pool.empty? && !last_digest(previous)
49
+
50
+ state = valid_state?(previous) ? previous.dup : fresh_state(last_digest(previous))
51
+ state['deferred'] = state['deferred'].dup
52
+ return [nil, state] if @pool.empty?
53
+
54
+ state = fresh_state(state['last']) if state['cursor'] == @pool.length && state['deferred'].empty?
55
+ order = @pool.shuffle(random: Random.new(state['seed'].to_i(16)))
56
+ position = next_position(order, state)
57
+ frame = order[position]
58
+ state['deferred'].delete(position)
59
+ state['last'] = Digest::SHA256.hexdigest(frame.id)
60
+ [frame, state]
61
+ end
62
+
63
+ private
64
+
65
+ def fresh_state(last)
66
+ { 'version' => 1, 'catalog' => @catalog, 'seed' => SecureRandom.hex(8),
67
+ 'cursor' => 0, 'deferred' => [], 'last' => last }
68
+ end
69
+
70
+ def last_digest(state)
71
+ state['last'] if state.is_a?(Hash) && state['last'].is_a?(String) && HEX_DIGEST.match?(state['last'])
72
+ end
73
+
74
+ def valid_state?(state)
75
+ return false unless state.is_a?(Hash) && state.size == 6 && (state.keys - %w[catalog cursor deferred last seed version]).empty?
76
+ return false unless state['version'] == 1 && state['catalog'] == @catalog
77
+ return false unless state['seed'].is_a?(String) && SEED.match?(state['seed'])
78
+ return false unless state['last'].nil? || last_digest(state)
79
+
80
+ valid_positions?(state['cursor'], state['deferred'])
81
+ end
82
+
83
+ def valid_positions?(cursor, deferred)
84
+ cursor.is_a?(Integer) && cursor.between?(0, @pool.length) &&
85
+ deferred.is_a?(Array) && deferred.length <= 2 && deferred.uniq == deferred &&
86
+ deferred.all? { |position| position.is_a?(Integer) && position >= 0 && position < cursor }
87
+ end
88
+
89
+ # At most two positions can be blocked (last and exclude). Keep them unseen
90
+ # rather than dropping them, including when the next request changes exclude.
91
+ def next_position(order, state)
92
+ position = state['deferred'].find { |index| penalty(order[index], state).zero? }
93
+ return position if position
94
+
95
+ while state['cursor'] < order.length
96
+ position = state['cursor']
97
+ state['cursor'] += 1
98
+ return position if penalty(order[position], state).zero?
99
+
100
+ state['deferred'] << position
101
+ end
102
+ state['deferred'].min_by { |index| penalty(order[index], state) }
103
+ end
104
+
105
+ def penalty(frame, state)
106
+ (Digest::SHA256.hexdigest(frame.id) == state['last'] ? 2 : 0) + (frame.id == @exclude ? 1 : 0)
107
+ end
108
+ end
109
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'yaml'
4
4
  require 'bible270/translations'
5
+ require 'bible270/scripture_frame_rotation'
5
6
 
6
7
  module Bible270
7
8
  module ScriptureFrames
@@ -156,7 +157,7 @@ module Bible270
156
157
  end
157
158
  private_class_method :default_disable_setting
158
159
 
159
- def random(exclude: nil)
160
+ def random(exclude: nil, reader: nil, session: nil)
160
161
  disabled_ids = disabled_default_ids
161
162
  pool = defaults.reject { |frame| disabled_ids.include?(frame.id) }
162
163
  if custom_available?
@@ -165,6 +166,8 @@ module Bible270
165
166
  translation: frame.translation, text: frame.text, attribution: frame.attribution)
166
167
  end
167
168
  end
169
+ return ScriptureFrameRotation.select(pool, reader: reader, session: session, exclude: exclude) if reader || session
170
+
168
171
  pool = pool.reject { |frame| frame.id == exclude } if pool.length > 1 && exclude.is_a?(String)
169
172
  pool.sample
170
173
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bible270
4
- VERSION = '1.18.0'
4
+ VERSION = '1.19.0'
5
5
  end
@@ -54,12 +54,16 @@ Bible270.configure do |config|
54
54
  # --- Progress sync (optional) ---------------------------------------------
55
55
  # Admin-managed one-way check-offs between trusted installations. See README.
56
56
  # config.progress_sync_instance_id = 'primary'
57
- # config.progress_sync_destinations = {
58
- # 'church' => { label: 'Church', url: 'https://church.example/daily-bread',
59
- # secret: ENV.fetch('B270_PRIMARY_CHURCH_SYNC_SECRET') }
60
- # }
57
+ # Credentials are runtime-only; leave sync disabled during image builds.
58
+ # if (sync_secret = ENV['B270_PRIMARY_CHURCH_SYNC_SECRET'])
59
+ # config.progress_sync_destinations = {
60
+ # 'church' => { label: 'Church', url: 'https://church.example/daily-bread', secret: sync_secret }
61
+ # }
62
+ # end
61
63
  # On the receiving installation, authorize that source with the same secret:
62
- # config.progress_sync_sources = { 'primary' => { secret: ENV.fetch('B270_PRIMARY_CHURCH_SYNC_SECRET') } }
64
+ # if (sync_secret = ENV['B270_PRIMARY_CHURCH_SYNC_SECRET'])
65
+ # config.progress_sync_sources = { 'primary' => { secret: sync_secret } }
66
+ # end
63
67
  # Schedule bible270:progress_sync:deliver every minute on the primary.
64
68
  # config.progress_sync_deliver_later = true # optional: persistent Active Job backend + worker
65
69
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bible270
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.0
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew vonderLuft
@@ -176,6 +176,7 @@ files:
176
176
  - app/models/bible270/setting.rb
177
177
  - app/models/bible270/sign_in_token.rb
178
178
  - app/views/bible270/admin/_progress_sync.html.erb
179
+ - app/views/bible270/admin/_reader_completion_summary.html.erb
179
180
  - app/views/bible270/admin/_reader_list.html.erb
180
181
  - app/views/bible270/admin/_scripture_frames.html.erb
181
182
  - app/views/bible270/admin/_scripture_text.html.erb
@@ -282,6 +283,7 @@ files:
282
283
  - db/migrate/20260101000026_add_revert_to_bible270_plan_runs.rb
283
284
  - db/migrate/20260101000027_create_bible270_scripture_frames.rb
284
285
  - db/migrate/20260101000028_create_bible270_progress_sync.rb
286
+ - db/migrate/20260101000029_add_scripture_frame_rotation_to_bible270_readers.rb
285
287
  - lib/bible270.rb
286
288
  - lib/bible270/avatar_backfill.rb
287
289
  - lib/bible270/avatar_images.rb
@@ -302,6 +304,7 @@ files:
302
304
  - lib/bible270/progress_sync/client.rb
303
305
  - lib/bible270/reader_consistency.rb
304
306
  - lib/bible270/reader_progress_report.rb
307
+ - lib/bible270/scripture_frame_rotation.rb
305
308
  - lib/bible270/scripture_frames.rb
306
309
  - lib/bible270/translations.rb
307
310
  - lib/bible270/versification.rb