Class: Rigor::Plugin::Blueprint

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/plugin/blueprint.rb

Overview

Frozen, ‘Ractor.shareable?` description of how to materialise a single plugin instance inside a worker. [ADR-15](../../../docs/adr/15-ractor-concurrency.md) Phase 3 introduces the carrier so the eventual worker pool can pass `Array<Blueprint>` across a Ractor boundary verbatim; each worker calls #materialize once at startup, then owns its plugin instances (and their mutable per-run accumulators) for the lifetime of the worker.

Holds the constant path (‘String`) of the plugin class — NOT the class object itself. Plugin gems are required from the main Ractor BEFORE any worker spawns, so every Ractor resolves the same constant via `Object.const_get`.

The ‘config` Hash is deep-copied + made shareable at construction so the Blueprint stays decoupled from whatever Hash the project configuration emitted. The original config Hash held by the loader is therefore unaffected by Blueprint construction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass_name:, config: {}) ⇒ Blueprint

Returns a new instance of Blueprint.



27
28
29
30
31
# File 'lib/rigor/plugin/blueprint.rb', line 27

def initialize(klass_name:, config: {})
  @klass_name = normalise_klass_name(klass_name)
  @config = Ractor.make_shareable(Marshal.load(Marshal.dump(config)))
  freeze
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



25
26
27
# File 'lib/rigor/plugin/blueprint.rb', line 25

def config
  @config
end

#klass_nameObject (readonly)

Returns the value of attribute klass_name.



25
26
27
# File 'lib/rigor/plugin/blueprint.rb', line 25

def klass_name
  @klass_name
end

Instance Method Details

#materialize(services:) ⇒ Object

Resolves the plugin class via ‘Object.const_get`, builds a fresh instance bound to the supplied services container, and calls `#init(services)`. Mirrors Loader#instantiate bit-for-bit so the blueprint-driven path stays consistent with the configuration-driven load path.



39
40
41
42
43
44
# File 'lib/rigor/plugin/blueprint.rb', line 39

def materialize(services:)
  klass = Object.const_get(@klass_name)
  plugin = klass.new(services: services, config: @config)
  plugin.init(services)
  plugin
end