Module: Hames
- Defined in:
- lib/hames.rb,
lib/hames/events.rb,
lib/hames/loader.rb,
lib/hames/context.rb
Overview
Hames is Terret's plugin kernel: services in a context, typed events with four dispatch modes, reversible effects, and dependency-driven boot. It has no knowledge of LLMs and is reusable for any plugin-composed application.
Defined Under Namespace
Classes: Context, ContractError, CycleError, EventDecl, Loader, Row, Service, ServiceMissingError
Constant Summary collapse
- VERSION =
"0.1.0"- MODES =
Runtime event contracts. Every event is declared once with its dispatch mode (and optionally a durability flag and payload class). The bus refuses to dispatch undeclared events or to dispatch a declared event through the wrong mode. This is the Ruby replacement for Cordis's TypeScript declaration-merged event typing.
%i[emit waterfall parallel serial].freeze
Class Method Summary collapse
- .assert_mode!(name, mode) ⇒ Object
-
.catalog ⇒ Object
Generated documentation source: [ [name, mode, durable, doc], ... ].
- .declared?(name) ⇒ Boolean
-
.event(name, mode: nil, durable: false, payload: nil, doc: nil) ⇒ Object
Declare (or look up) an event contract.
- .events ⇒ Object
-
.reset_events! ⇒ Object
test hook.
Class Method Details
.assert_mode!(name, mode) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/hames/events.rb', line 34 def assert_mode!(name, mode) decl = events[name.to_s] raise Hames::ContractError, "dispatch of undeclared event #{name}" unless decl return if decl.mode == mode raise Hames::ContractError, "event #{name} is #{decl.mode}, dispatched as #{mode}" end |
.catalog ⇒ Object
Generated documentation source: [ [name, mode, durable, doc], ... ]
44 45 46 |
# File 'lib/hames/events.rb', line 44 def catalog events.values.sort_by(&:name).map { |d| [d.name, d.mode, d.durable, d.doc] } end |
.declared?(name) ⇒ Boolean
32 |
# File 'lib/hames/events.rb', line 32 def declared?(name) = events.key?(name.to_s) |
.event(name, mode: nil, durable: false, payload: nil, doc: nil) ⇒ Object
Declare (or look up) an event contract.
Hames.event "tools/pre_execute", mode: :waterfall, payload: Tools::Call
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hames/events.rb', line 19 def event(name, mode: nil, durable: false, payload: nil, doc: nil) name = name.to_s return events.fetch(name) if mode.nil? raise ArgumentError, "unknown dispatch mode #{mode.inspect}" unless MODES.include?(mode) if (existing = events[name]) && existing.mode != mode raise Hames::ContractError, "event #{name} already declared with mode #{existing.mode}, got #{mode}" end events[name] = EventDecl.new(name:, mode:, durable:, payload:, doc:) end |
.events ⇒ Object
14 |
# File 'lib/hames/events.rb', line 14 def events = (@events ||= {}) |
.reset_events! ⇒ Object
test hook
48 |
# File 'lib/hames/events.rb', line 48 def reset_events! = events.clear # test hook |