Class: Textus::Step::RegistryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/step/registry_store.rb

Overview

The single home for registered steps. Reuses Step::EventBus for observe (pub/sub) dispatch — including its timeout isolation and error ring buffer — and holds a kind->name->instance table for the invocable kinds (fetch/transform/validate). Replaces the EventBus+RpcRegistryStore pair.

Instance Method Summary collapse

Constructor Details

#initialize(error_log: Step::ErrorLog.new) ⇒ RegistryStore

Returns a new instance of RegistryStore.



10
11
12
13
# File 'lib/textus/step/registry_store.rb', line 10

def initialize(error_log: Step::ErrorLog.new)
  @bus   = Step::EventBus.new(error_log: error_log)
  @table = Hash.new { |h, k| h[k] = {} }
end

Instance Method Details

#error_logObject



54
# File 'lib/textus/step/registry_store.rb', line 54

def error_log = @bus.error_log

#invoke(kind, name, caps:, **other) ⇒ Object

Invoke an invocable step. Mirrors the old RpcRegistryStore#invoke: inject caps only when #call declares :caps or accepts keyrest.



32
33
34
35
36
37
38
# File 'lib/textus/step/registry_store.rb', line 32

def invoke(kind, name, caps:, **other)
  step = @table[kind][name.to_sym] or raise UsageError.new("unknown #{kind}: #{name}")
  sig = Step::Signature.new(step.method(:call))
  kwargs = other.dup
  kwargs[:caps] = caps if sig.accepts_keyrest? || sig.declared_keys.include?(:caps)
  step.call(**kwargs)
end

#names(kind) ⇒ Object



40
41
42
43
44
# File 'lib/textus/step/registry_store.rb', line 40

def names(kind)
  return @bus.pubsub_handlers_names if kind.to_sym == :observe

  @table[kind.to_sym].keys
end

#on(event, name, keys: nil) ⇒ Object



52
# File 'lib/textus/step/registry_store.rb', line 52

def on(event, name, keys: nil, &) = @bus.register(event, name, keys: keys, &)

#on_errorObject



53
# File 'lib/textus/step/registry_store.rb', line 53

def on_error(&) = @bus.on_error(&)

#publish(event) ⇒ Object

Pub/sub passthrough (observe + internal built-in subscribers).



51
# File 'lib/textus/step/registry_store.rb', line 51

def publish(event, **) = @bus.publish(event, **)

#pubsub_handlers(event) ⇒ Object



46
47
48
# File 'lib/textus/step/registry_store.rb', line 46

def pubsub_handlers(event)
  @bus.pubsub_handlers(event)
end

#register(step, keys: nil) ⇒ Object

Register either a Step instance (invocable/observe table) or a pub/sub subscriber (‘register(event, name, keys:, &block)`) for internal/spec probes.

Raises:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/textus/step/registry_store.rb', line 18

def register(step, *, keys: nil, &)
  return @bus.register(step, *, keys: keys, &) unless step.is_a?(Step::Base)

  kind = step.class.kind
  name = step.name.to_sym
  return register_observe(step) if kind == :observe

  raise UsageError.new("#{kind} '#{name}' already registered") if @table[kind].key?(name)

  @table[kind][name] = step
end