Class: Rigor::Plugin::Services

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

Overview

Dependency-injection container handed to every plugin’s Base#init method. Plugins read from the container; they MUST NOT mutate it. The container is constructed once per ‘Analysis::Runner.run` and destroyed at the end of the run.

ADR-2 § “Registration, Configuration, and Caching” reserves this surface for “constructor injection for analyzer services such as reflection providers, type factories, loggers, and configuration readers”. Slice 1 wires four of those:

  • ‘reflection`: the Reflection read-side facade.

  • ‘type`: the Type::Combinator factory module.

  • ‘configuration`: the project’s Configuration.

  • ‘cache_store`: the Cache::Store the run is using (or `nil` when caching is disabled). Slice 6 wires plugin-side cache producers through this entry.

Loggers are not yet a public surface in the core analyzer; they will be added when the diagnostics formatter grows a progress channel.

Slice 2 (Plugin trust / I/O policy) extends the container with ‘trust_policy` and a per-plugin `io_boundary_for(plugin_id)` factory. Plugins should reach for the boundary rather than raw `File.read` so reads stay within the trusted scope and feed cache invalidation; ADR-2 § “Plugin Trust and I/O Policy” documents the trust model the boundary enforces.

ADR-9 slice 2 adds ‘fact_store`: the per-run cross-plugin `Plugin::FactStore`. Producer plugins publish their facts in `#prepare(services)` (slice 3); consumer plugins read in `#diagnostics_for_file` via `services.fact_store.read(…)`. A fresh `FactStore` instance is constructed per Services when none is supplied — the runner threads its own instance in once slice 3 wires `#prepare` invocation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reflection:, type:, configuration:, cache_store: nil, trust_policy: nil, fact_store: nil) ⇒ Services

rubocop:disable Metrics/ParameterLists



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rigor/plugin/services.rb', line 45

def initialize( # rubocop:disable Metrics/ParameterLists
  reflection:, type:, configuration:,
  cache_store: nil, trust_policy: nil, fact_store: nil
)
  @reflection = reflection
  @type = type
  @configuration = configuration
  @cache_store = cache_store
  @trust_policy = trust_policy || default_trust_policy
  @fact_store = fact_store || FactStore.new
  freeze
end

Instance Attribute Details

#cache_storeObject (readonly)

Returns the value of attribute cache_store.



43
44
45
# File 'lib/rigor/plugin/services.rb', line 43

def cache_store
  @cache_store
end

#configurationObject (readonly)

Returns the value of attribute configuration.



43
44
45
# File 'lib/rigor/plugin/services.rb', line 43

def configuration
  @configuration
end

#fact_storeObject (readonly)

Returns the value of attribute fact_store.



43
44
45
# File 'lib/rigor/plugin/services.rb', line 43

def fact_store
  @fact_store
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



43
44
45
# File 'lib/rigor/plugin/services.rb', line 43

def reflection
  @reflection
end

#trust_policyObject (readonly)

Returns the value of attribute trust_policy.



43
44
45
# File 'lib/rigor/plugin/services.rb', line 43

def trust_policy
  @trust_policy
end

#typeObject (readonly)

Returns the value of attribute type.



43
44
45
# File 'lib/rigor/plugin/services.rb', line 43

def type
  @type
end

Instance Method Details

#io_boundary_for(plugin_id) ⇒ Object

Returns a fresh IoBoundary bound to ‘plugin_id` and the current `trust_policy`. The boundary accumulates per-plugin cache descriptor entries; the loader / contribution merger constructs one boundary per plugin per run.



62
63
64
# File 'lib/rigor/plugin/services.rb', line 62

def io_boundary_for(plugin_id)
  IoBoundary.new(policy: @trust_policy, plugin_id: plugin_id)
end