Class: RactorRailsShim::Callbacks::Registry
- Inherits:
-
Object
- Object
- RactorRailsShim::Callbacks::Registry
- Defined in:
- lib/ractor_rails_shim/callbacks/registry.rb
Instance Method Summary collapse
-
#applicable(kind) ⇒ Object
The subset of transports that apply to
kind. -
#capture ⇒ Object
Forward the optional finalize-the-snapshot phase to every transport that responds.
-
#initialize(transports = []) ⇒ Registry
constructor
transports: an Enumerable of transport objects (duck-typed).
-
#install ⇒ Object
Forward the optional framework-hooking phase to every transport that responds.
-
#register(transport) ⇒ Object
Register one transport.
-
#replay(context, kind, &block) ⇒ Object
Replay the empty callback chain for
contextandkind.
Constructor Details
#initialize(transports = []) ⇒ Registry
transports: an Enumerable of transport objects (duck-typed). Defaults
to empty so callers can register incrementally.
29 30 31 |
# File 'lib/ractor_rails_shim/callbacks/registry.rb', line 29 def initialize(transports = []) @transports = transports.is_a?(Enumerable) ? transports.to_a : Array(transports) end |
Instance Method Details
#applicable(kind) ⇒ Object
The subset of transports that apply to kind. Public so tests (and a
future "is anything replayable for this kind?" check) can introspect.
41 42 43 |
# File 'lib/ractor_rails_shim/callbacks/registry.rb', line 41 def applicable(kind) @transports.select { |t| t.applies_to?(kind) } end |
#capture ⇒ Object
Forward the optional finalize-the-snapshot phase to every transport that responds. Called from the main Ractor at prepare time.
66 67 68 |
# File 'lib/ractor_rails_shim/callbacks/registry.rb', line 66 def capture @transports.each { |t| t.capture if t.respond_to?(:capture) } end |
#install ⇒ Object
Forward the optional framework-hooking phase to every transport that responds. Idempotent install is each transport's own concern.
60 61 62 |
# File 'lib/ractor_rails_shim/callbacks/registry.rb', line 60 def install @transports.each { |t| t.install if t.respond_to?(:install) } end |
#register(transport) ⇒ Object
Register one transport. Returns self for chaining.
34 35 36 37 |
# File 'lib/ractor_rails_shim/callbacks/registry.rb', line 34 def register(transport) @transports << transport self end |
#replay(context, kind, &block) ⇒ Object
Replay the empty callback chain for context and kind. Runs every
applicable transport's before-work, yields the block ONCE, then runs
every applicable transport's after-work. Returns the block's result.
If nothing applies, just yields (matching the original empty-chain path).
49 50 51 52 53 54 55 56 |
# File 'lib/ractor_rails_shim/callbacks/registry.rb', line 49 def replay(context, kind, &block) applicable = applicable(kind) return yield if applicable.empty? applicable.each { |t| t.before(context, kind) } result = yield applicable.each { |t| t.after(context, kind) } result end |