Class: Cordis::Registry
- Inherits:
-
Object
- Object
- Cordis::Registry
- Defined in:
- lib/cordis/registry.rb
Overview
Plugin registry: keyed by the resolved callback — one Runtime per callback, applying the same plugin N times = N fibers under one Runtime.
Defined Under Namespace
Classes: Runtime
Instance Method Summary collapse
-
#initialize(ctx) ⇒ Registry
constructor
A new instance of Registry.
- #next_uid ⇒ Object
-
#plugin(ctx, plugin, config = nil) ⇒ Object
Entry point for ctx.plugin.
- #remove(fiber) ⇒ Object
- #runtimes ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(ctx) ⇒ Registry
Returns a new instance of Registry.
9 10 11 12 13 |
# File 'lib/cordis/registry.rb', line 9 def initialize(ctx) @ctx = ctx @store = {} @counter = 0 end |
Instance Method Details
#next_uid ⇒ Object
15 |
# File 'lib/cordis/registry.rb', line 15 def next_uid = (@counter += 1) |
#plugin(ctx, plugin, config = nil) ⇒ Object
Entry point for ctx.plugin. Plugin shapes: a callable, { apply:, inject:, name: }, or a Class (instantiated at load time; see Cordis::Service). Returns the fiber synchronously; the actual apply is deferred one tick (must be called inside Sync/Async).
23 24 25 26 27 28 |
# File 'lib/cordis/registry.rb', line 23 def plugin(ctx, plugin, config = nil) key, callback, inject, name = resolve(plugin) ctx.fiber.assert_active runtime = @store[key] ||= Runtime.new(name, callback, [], key) Fiber.new(ctx, config: config, inject: inject, runtime: runtime) end |
#remove(fiber) ⇒ Object
30 31 32 33 34 |
# File 'lib/cordis/registry.rb', line 30 def remove(fiber) runtime = fiber.runtime runtime.fibers.reject! { |f| f.equal?(fiber) } @store.delete(runtime.key) if runtime.fibers.empty? end |
#runtimes ⇒ Object
17 |
# File 'lib/cordis/registry.rb', line 17 def runtimes = @store.values |
#size ⇒ Object
16 |
# File 'lib/cordis/registry.rb', line 16 def size = @store.size |