yrb-lite 0.1.0.beta3-x86_64-linux-musl → 0.1.0.beta4-x86_64-linux-musl

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: d8c75abbfba8fd4f5b06a613066e804ac630a6078509142f8d96bdb9f98ddbf7
4
- data.tar.gz: 8406c4ccbebfd116f53b04b48c4f328dfcf93cfff9fd1a384efb903aa096abee
3
+ metadata.gz: d30b134e25ded582a7cefad2c3aacaa9fb25fac53c686b4a68fdf1c54c858f05
4
+ data.tar.gz: f8c392669953c1658de1b2174ec5beb5f814902f2110d49e115e125770be6eb3
5
5
  SHA512:
6
- metadata.gz: a8f63fa73e324759d2c550b01369412c50cdfac92afab4a5249fd7ac9bee6cda6e8d42d06b78e13ea84bea0b20d2933446e6c3bf9e7bddd90e8ca68a2845ee42
7
- data.tar.gz: e00e0b3d388f9ef6c496cc508797f3d928e301fd80b4d363df157a79c1ab54feeb8e078f501331604803faa68b683abc9477eafaf26670eee890c2a5c1001a09
6
+ metadata.gz: 0bb4e1724eff734814185ef7d5fe600741d8fd4e8ac6f6fcf3f258279e9a29d5f407a8a290a7778c41d071db43165a3a8bfb38e83c9127f631d25a9cd69f1539
7
+ data.tar.gz: 4652e8fc269d4ddb5f9a2e13579c4f76c34fffed24879505a20e1df3628be549282cd8f834ed7c3d7bbff0011e1783359678c0c9a7770040b1409d3112a698be
data/CHANGELOG.md CHANGED
@@ -6,6 +6,21 @@ to follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.0.beta4] - 2026-06-18
10
+
11
+ ### Changed
12
+
13
+ - `on_change` block recorders now run in the **channel instance's context**
14
+ (via `instance_exec`), so a recorder can call the channel's own methods --
15
+ `current_user`, `params`, request/connection-scoped accessors -- directly,
16
+ instead of plumbing them in through a thread-local. A non-Proc callable (an
17
+ object responding to `#call`) is still invoked with `#call` and its own
18
+ context. `on_load`/`on_save` are unchanged: they can run in the shared
19
+ document registry during a cold load or eviction, where no connection
20
+ instance exists, so they remain key-only. Existing block recorders that use
21
+ only the `(key, update)` arguments and lexically-scoped constants are
22
+ unaffected; the only behavioral change is `self` inside the block.
23
+
9
24
  ## [0.1.0.beta3] - 2026-06-18
10
25
 
11
26
  ### Changed
@@ -76,7 +91,8 @@ to follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
76
91
  - Precompiled native gems for common platforms (no Rust toolchain needed to
77
92
  install) via the cross-gem workflow.
78
93
 
79
- [Unreleased]: https://github.com/jpcamara/yrb-lite/compare/v0.1.0.beta3...main
94
+ [Unreleased]: https://github.com/jpcamara/yrb-lite/compare/v0.1.0.beta4...main
95
+ [0.1.0.beta4]: https://github.com/jpcamara/yrb-lite/compare/v0.1.0.beta3...v0.1.0.beta4
80
96
  [0.1.0.beta3]: https://github.com/jpcamara/yrb-lite/compare/v0.1.0.beta2...v0.1.0.beta3
81
97
  [0.1.0.beta2]: https://github.com/jpcamara/yrb-lite/compare/v0.1.0.beta1...v0.1.0.beta2
82
98
  [0.1.0.beta1]: https://github.com/jpcamara/yrb-lite/releases/tag/v0.1.0.beta1
data/lib/yrb_lite/sync.rb CHANGED
@@ -20,6 +20,10 @@ module YrbLite
20
20
  # on_load { |key| Document.find_by(key: key)&.content }
21
21
  # on_save { |key, update| Document.find_by(key: key)&.update!(content: update) }
22
22
  #
23
+ # # on_change blocks run in the channel instance's context, so instance
24
+ # # methods (current_user, params, ...) are available without plumbing:
25
+ # on_change { |key, update| Document.record!(key, update, by: current_user) }
26
+ #
23
27
  # def subscribed
24
28
  # sync_for params[:id]
25
29
  # end
@@ -73,6 +77,13 @@ module YrbLite
73
77
  # the change is rejected: neither applied to the shared document nor
74
78
  # broadcast to other subscribers.
75
79
  #
80
+ # A block recorder runs in the *channel instance's* context, so it can
81
+ # call the channel's own methods (current_user, params, a per-connection
82
+ # Current.* accessor) directly, with no thread-local plumbing. (A non-Proc
83
+ # callable is invoked with #call instead, since it carries its own
84
+ # context.) on_change always fires from within sync_receive, unlike
85
+ # on_load/on_save, which can run context-free in the shared registry.
86
+ #
76
87
  # Registering an on_change switches that channel onto the strict path
77
88
  # (record, apply, broadcast). Without it, the default fast path applies
78
89
  # and broadcasts, with an optional on_save snapshot.
@@ -282,9 +293,9 @@ module YrbLite
282
293
  next :noop unless update
283
294
  next :gap unless awareness.update_ready?(update)
284
295
 
285
- recorder.call(@sync_key, update) # durable write; raise to reject
286
- awareness.apply_update(update) # only recorded changes reach the doc
287
- sync_distribute(encoded) # ...and only then the wire
296
+ sync_record_change(recorder, update) # durable write; raise to reject
297
+ awareness.apply_update(update) # only recorded changes reach the doc
298
+ sync_distribute(encoded) # ...and only then the wire
288
299
  :recorded
289
300
  end
290
301
 
@@ -422,7 +433,9 @@ module YrbLite
422
433
  return :gap
423
434
  end
424
435
 
425
- self.class.on_change&.call(@sync_key, update) # record before relay
436
+ if (recorder = self.class.on_change)
437
+ sync_record_change(recorder, update) # record before relay
438
+ end
426
439
  sync_distribute(encoded)
427
440
  :recorded
428
441
  when MSG_KIND_AWARENESS
@@ -460,6 +473,14 @@ module YrbLite
460
473
  saver.call(@sync_key, sync_awareness.encode_state_as_update)
461
474
  end
462
475
 
476
+ # Invoke the on_change recorder. A block/proc runs in this channel instance's
477
+ # context (instance_exec) so it can reach the channel's own methods; a
478
+ # non-Proc callable is invoked with #call, since it carries its own context.
479
+ def sync_record_change(recorder, update)
480
+ args = [@sync_key, update]
481
+ recorder.is_a?(Proc) ? instance_exec(*args, &recorder) : recorder.call(*args)
482
+ end
483
+
463
484
  # -- Shared document registry ------------------------------------------
464
485
 
465
486
  @registry = {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YrbLite
4
- VERSION = "0.1.0.beta3"
4
+ VERSION = "0.1.0.beta4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yrb-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta3
4
+ version: 0.1.0.beta4
5
5
  platform: x86_64-linux-musl
6
6
  authors:
7
7
  - JP Camara