Class: Stoplight::Wiring::LightBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/wiring/light_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constructs a fully-wired Light instance from validated configuration.

LightBuilder is the final assembly step in the Light creation pipeline. It receives validated config and dependencies from ConfigurationPipeline and wires together all infrastructure components (data stores, trackers, strategies) needed for a functioning circuit breaker.

LightBuilder maintains a global registry (MEMORY_REGISTRY) that ensures the same Memory data store config object always produces the same data store instance:

data_store = Stoplight::DataStore::Memory.new
light1 = Stoplight("foo", data_store: data_store)
light2 = Stoplight("bar", data_store: data_store)
# light1 and light2 share the same underlying memory store

light3 = Stoplight("baz", data_store: Stoplight::DataStore::Memory.new)
# light3 has its own independent store

This singleton behavior is keyed by config object identity (object_id), not by value equality.

Direct Known Subclasses

System::LightBuilder

Instance Method Summary collapse

Constructor Details

#initialize(config:, factory:) ⇒ LightBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LightBuilder.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/stoplight/wiring/light_builder.rb', line 37

def initialize(config:, factory:)
  @clock = Infrastructure::SystemClock.new
  @config = config
  @name = T.must(config.name)
  @cool_off_time = config.cool_off_time

  @data_store_config = config.data_store
  @error_notifier = config.error_notifier
  @factory = factory
  @notifiers = config.notifiers
  @traffic_recovery = config.traffic_recovery
  @traffic_control = config.traffic_control

  @error_tracking_policy = Domain::ErrorTrackingPolicy.new(
    tracked: config.tracked_errors,
    skipped: config.skipped_errors
  )
end

Instance Method Details

#buildObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
64
65
# File 'lib/stoplight/wiring/light_builder.rb', line 56

def build
  Stoplight::Domain::Light.new(
    @name,
    state_store:,
    green_run_strategy:,
    yellow_run_strategy:,
    red_run_strategy:,
    factory:
  )
end