Class: Insika::Registry
- Inherits:
-
Object
- Object
- Insika::Registry
- Defined in:
- lib/insika/registry.rb
Overview
Generic executable base: Registry = EXECUTABLE content (tools/workflows/policies). Catalog (skills/prompts) is non-executable and does not inherit from here.
Immutable post-boot by CONSTRUCTION (only boot registers): there
is no freeze!; immutability is not enforced at runtime.
Direct Known Subclasses
ChannelRegistry, PolicyRegistry, ToolRegistry, WorkflowRegistry
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
-
#deregister_plugin(plugin_id) ⇒ Object
Loader rollback support: removes the entries of a plugin.
- #entries ⇒ Object
-
#entry(name) ⇒ Object
-> the raw Entry (name/plugin/metadata/factory) | raise NotFoundError.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #names ⇒ Object
-
#register(name, callable = nil, plugin: nil, **metadata, &block) ⇒ Object
factory = block OR the positional callable.
-
#resolve(name) ⇒ Object
-> instance (factory.call) | raise NotFoundError.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
13 14 15 |
# File 'lib/insika/registry.rb', line 13 def initialize @entries = {} end |
Instance Method Details
#deregister_plugin(plugin_id) ⇒ Object
Loader rollback support: removes the entries of a plugin. NOT a runtime API (registries are immutable post-boot).
54 55 56 57 |
# File 'lib/insika/registry.rb', line 54 def deregister_plugin(plugin_id) @entries.delete_if { |_name, entry| entry.plugin == plugin_id.to_s } nil end |
#entries ⇒ Object
49 |
# File 'lib/insika/registry.rb', line 49 def entries = @entries.values |
#entry(name) ⇒ Object
-> the raw Entry (name/plugin/metadata/factory) | raise NotFoundError. For readers that need the metadata WITHOUT resolving the factory (discovery, WorkflowRegistry#definition).
44 45 46 47 |
# File 'lib/insika/registry.rb', line 44 def entry(name) @entries[name.to_s] || (raise Insika::NotFoundError, "'#{name}' not registered in #{self.class}") end |
#names ⇒ Object
50 |
# File 'lib/insika/registry.rb', line 50 def names = @entries.keys |
#register(name, callable = nil, plugin: nil, **metadata, &block) ⇒ Object
factory = block OR the positional callable. metadata captured by **kw (Symbol keys, stored as-is). Duplicate: FIRST wins (plugin precedence) — the second is discarded with a warn, never overwritten.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/insika/registry.rb', line 20 def register(name, callable = nil, plugin: nil, **, &block) name = name.to_s factory = block || (callable.nil? ? nil : -> { callable }) raise ArgumentError, "registration without factory: #{name}" if factory.nil? if @entries.key?(name) existing = @entries[name] warn "[registry] '#{name}' already registered by #{existing.plugin.inspect}; " \ "descartando registro de #{plugin.inspect} (primeiro vence)" return self end @entries[name] = Entry.new(name: name, plugin: plugin&.to_s, metadata: , factory: factory) self end |
#resolve(name) ⇒ Object
-> instance (factory.call) | raise NotFoundError.
37 38 39 |
# File 'lib/insika/registry.rb', line 37 def resolve(name) entry(name).factory.call end |