Module: Rubino::Memory::Backends
- Defined in:
- lib/rubino/memory/backends.rb,
lib/rubino/memory/backends/sqlite.rb,
lib/rubino/memory/backends/default.rb
Overview
Registry of pluggable memory backends, mirroring Tools::Registry: a name => class map with register/build. The active backend is selected by the ‘memory.backend` config key (default “sqlite” — the tiny-Zep FTS5/ graph-lite backend). DEFAULT_NAME below is the registry fallback used only when the configured name is blank/unknown.
Defined Under Namespace
Constant Summary collapse
- DEFAULT_NAME =
"default"
Class Method Summary collapse
-
.build(config: nil) ⇒ Object
Builds the configured backend instance.
- .fetch(name) ⇒ Object
-
.names ⇒ Object
All registered backend names.
-
.register(klass) ⇒ Object
Registers a backend class under its #backend_name.
- .registered?(name) ⇒ Boolean
-
.reset! ⇒ Object
For tests.
Class Method Details
.build(config: nil) ⇒ Object
Builds the configured backend instance. Falls back to the default backend when ‘memory.backend` is unset or names an unknown backend, so a stale config never breaks the interaction.
35 36 37 38 39 40 41 42 |
# File 'lib/rubino/memory/backends.rb', line 35 def build(config: nil) cfg = config || Rubino.configuration name = cfg.dig("memory", "backend").to_s klass = @registry[name] || @registry[DEFAULT_NAME] raise Error, "no memory backend registered (looked for #{name.inspect})" unless klass klass.new(config: cfg) end |
.fetch(name) ⇒ Object
28 29 30 |
# File 'lib/rubino/memory/backends.rb', line 28 def fetch(name) @registry[name.to_s] end |
.names ⇒ Object
All registered backend names.
20 21 22 |
# File 'lib/rubino/memory/backends.rb', line 20 def names @registry.keys end |
.register(klass) ⇒ Object
Registers a backend class under its #backend_name.
15 16 17 |
# File 'lib/rubino/memory/backends.rb', line 15 def register(klass) @registry[klass.backend_name.to_s] = klass end |
.registered?(name) ⇒ Boolean
24 25 26 |
# File 'lib/rubino/memory/backends.rb', line 24 def registered?(name) @registry.key?(name.to_s) end |
.reset! ⇒ Object
For tests.
45 46 47 |
# File 'lib/rubino/memory/backends.rb', line 45 def reset! @registry = {} end |