Class: Rigor::Plugin::Blueprint

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

Overview

Frozen, Ractor.shareable? description of how to materialise a single plugin instance inside a worker. ADR-15 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.

Parameters:

  • klass_name: (String, Module)
  • config: (Hash[untyped, untyped]) (defaults to: {})


21
22
23
24
25
# File 'lib/rigor/plugin/blueprint.rb', line 21

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

#configHash[untyped, untyped] (readonly)

Returns the value of attribute config.

Returns:

  • (Hash[untyped, untyped])


19
20
21
# File 'lib/rigor/plugin/blueprint.rb', line 19

def config
  @config
end

#klass_nameString (readonly)

Returns the value of attribute klass_name.

Returns:

  • (String)


19
20
21
# File 'lib/rigor/plugin/blueprint.rb', line 19

def klass_name
  @klass_name
end

Instance Method Details

#materialize(services:) ⇒ Rigor::Plugin::Base

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.

Parameters:

  • services: (Object)

Returns:



30
31
32
33
34
35
# File 'lib/rigor/plugin/blueprint.rb', line 30

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