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/unset. An explicitly-set UNKNOWN name is a misconfiguration (a typo silently degrading memory) → rejected.

Defined Under Namespace

Classes: Default, Sqlite

Constant Summary collapse

DEFAULT_NAME =
"default"

Class Method Summary collapse

Class Method Details

.build(config: nil) ⇒ Object

Builds the configured backend instance. A BLANK/unset ‘memory.backend` falls back to the default backend (so a fresh config just works); an explicitly-set name that names NO registered backend is a typo that would otherwise silently degrade to the default — reject it with a clear error listing the known backends instead.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubino/memory/backends.rb', line 38

def build(config: nil)
  cfg = config || Rubino.configuration
  name = cfg.dig("memory", "backend").to_s.strip
  klass = name.empty? ? @registry[DEFAULT_NAME] : @registry[name]

  unless klass
    raise Error, unknown_backend_message(name) unless name.empty?

    raise Error, "no memory backend registered (looked for #{DEFAULT_NAME.inspect})"
  end

  klass.new(config: cfg)
end

.fetch(name) ⇒ Object



29
30
31
# File 'lib/rubino/memory/backends.rb', line 29

def fetch(name)
  @registry[name.to_s]
end

.namesObject

All registered backend names.



21
22
23
# File 'lib/rubino/memory/backends.rb', line 21

def names
  @registry.keys
end

.register(klass) ⇒ Object

Registers a backend class under its #backend_name.



16
17
18
# File 'lib/rubino/memory/backends.rb', line 16

def register(klass)
  @registry[klass.backend_name.to_s] = klass
end

.registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rubino/memory/backends.rb', line 25

def registered?(name)
  @registry.key?(name.to_s)
end

.reset!Object

For tests.



61
62
63
# File 'lib/rubino/memory/backends.rb', line 61

def reset!
  @registry = {}
end

.unknown_backend_message(name) ⇒ Object

A clear, actionable rejection for an unknown ‘memory.backend` name, listing the registered backends so the user can fix the typo.



54
55
56
57
58
# File 'lib/rubino/memory/backends.rb', line 54

def unknown_backend_message(name)
  known = names.sort.join(", ")
  "unknown memory backend #{name.inspect}: set memory.backend to one of " \
    "[#{known}] (or leave it unset for the default)."
end