Class: Axn::Core::Flow::Handlers::Registry
- Inherits:
-
Object
- Object
- Axn::Core::Flow::Handlers::Registry
- Defined in:
- lib/axn/core/flow/handlers/registry.rb
Overview
Small, immutable, copy-on-write registry keyed by event_type. Stores arrays of entries (handlers/interceptors) in insertion order.
NOTE: serves different need than user-mutable e.g. Axn::Async::Adapters
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #for(event_type) ⇒ Object
-
#initialize(index) ⇒ Registry
constructor
A new instance of Registry.
-
#register(event_type:, entry:) ⇒ Object
Always register most-recent-first (last-defined wins).
Constructor Details
#initialize(index) ⇒ Registry
Returns a new instance of Registry.
14 15 16 17 |
# File 'lib/axn/core/flow/handlers/registry.rb', line 14 def initialize(index) # Freeze arrays and the index for immutability @index = index.transform_values { |arr| Array(arr).freeze }.freeze end |
Class Method Details
.empty ⇒ Object
12 |
# File 'lib/axn/core/flow/handlers/registry.rb', line 12 def self.empty = new({}) |
Instance Method Details
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/axn/core/flow/handlers/registry.rb', line 31 def empty? @index.empty? end |
#for(event_type) ⇒ Object
27 28 29 |
# File 'lib/axn/core/flow/handlers/registry.rb', line 27 def for(event_type) Array(@index[event_type.to_sym]) end |
#register(event_type:, entry:) ⇒ Object
Always register most-recent-first (last-defined wins). Simpler mental model.
20 21 22 23 24 25 |
# File 'lib/axn/core/flow/handlers/registry.rb', line 20 def register(event_type:, entry:) key = event_type.to_sym existing = Array(@index[key]) updated = [entry] + existing self.class.new(@index.merge(key => updated.freeze)) end |