Class: SwarmSDK::Swarm::SwarmRegistryBuilder
- Inherits:
-
Object
- Object
- SwarmSDK::Swarm::SwarmRegistryBuilder
- Defined in:
- lib/swarm_sdk/swarm/swarm_registry_builder.rb
Overview
Builder for swarm registry in DSL
Supports registering external swarms for composable swarms pattern.
Instance Attribute Summary collapse
-
#registrations ⇒ Object
readonly
Returns the value of attribute registrations.
Instance Method Summary collapse
-
#initialize ⇒ SwarmRegistryBuilder
constructor
A new instance of SwarmRegistryBuilder.
-
#register(name, file: nil, yaml: nil, keep_context: true) { ... } ⇒ Object
Register a swarm from file, YAML string, or inline block.
Constructor Details
#initialize ⇒ SwarmRegistryBuilder
Returns a new instance of SwarmRegistryBuilder.
29 30 31 |
# File 'lib/swarm_sdk/swarm/swarm_registry_builder.rb', line 29 def initialize @registrations = [] end |
Instance Attribute Details
#registrations ⇒ Object (readonly)
Returns the value of attribute registrations.
27 28 29 |
# File 'lib/swarm_sdk/swarm/swarm_registry_builder.rb', line 27 def registrations @registrations end |
Instance Method Details
#register(name, file: nil, yaml: nil, keep_context: true) { ... } ⇒ Object
Register a swarm from file, YAML string, or inline block
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/swarm_sdk/swarm/swarm_registry_builder.rb', line 41 def register(name, file: nil, yaml: nil, keep_context: true, &block) # Validate that exactly one source is provided sources = [file, yaml, block].compact if sources.empty? raise ArgumentError, "register '#{name}' requires either file:, yaml:, or a block" elsif sources.size > 1 raise ArgumentError, "register '#{name}' accepts only one of: file:, yaml:, or block (got #{sources.size})" end # Determine source type and store source = if file { type: :file, value: file } elsif yaml { type: :yaml, value: yaml } else { type: :block, value: block } end @registrations << { name: name.to_s, source: source, keep_context: keep_context, } end |