Class: Stoplight::Wiring::LightFactory Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/wiring/light_factory.rb,
lib/stoplight/wiring/light_factory/traffic_control_dsl.rb,
lib/stoplight/wiring/light_factory/traffic_recovery_dsl.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.

Concrete factory for building Stoplight::Light+ instances with full dependency wiring.

This factory implements the Stoplight::Domain::LightFactory protocol. It knows how to:

1. Parse and transform user-provided settings
2. Wire together all Light dependencies using a DI container
3. Validate configuration compatibility
4. Construct fully-functional Light instances

See Also:

  • Domain::LightFactory
  • Stoplight()

Constant Summary collapse

TrafficControlDsl =

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

->(value) {
  case value
  in _ if value.respond_to?(:stop_traffic?) # TODO: can be removed in 6.0
    value
  in :consecutive_errors
    Domain::TrafficControl::ConsecutiveErrors.new
  in :error_rate
    Domain::TrafficControl::ErrorRate.new
  in {error_rate: error_rate_settings}
    Domain::TrafficControl::ErrorRate.new(**error_rate_settings)
  else
    raise Stoplight::Error::ConfigurationError, <<~ERROR
      unsupported traffic_control strategy provided (`#{value}`). Supported options:
        * :consecutive_errors
        * :error_rate
    ERROR
  end
}
TrafficRecoveryDsl =

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

->(value) {
  case value
  in _ if value.respond_to?(:determine_color) # TODO: remove in 6.0
    value
  in :consecutive_successes
    Domain::TrafficRecovery::ConsecutiveSuccesses.new
  else
    raise Error::ConfigurationError, <<~ERROR
      unsupported traffic_recovery strategy provided (`#{value}`). Supported options:
        * :consecutive_successes
    ERROR
  end
}

Instance Method Summary collapse

Constructor Details

#initialize(config:) ⇒ LightFactory

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 LightFactory.



18
19
20
# File 'lib/stoplight/wiring/light_factory.rb', line 18

def initialize(config:)
  @config = config
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

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.



74
75
76
# File 'lib/stoplight/wiring/light_factory.rb', line 74

def ==(other)
  other.is_a?(self.class) && other.config == config
end

#buildStoplight::Light

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.

Builds a fully-configured Light instance.

The method resolves all dependencies from the container and constructs a Light that’s ready to use. The Light is injected with a reference to this factory, allowing the Stoplight::Light#with method to work for reconfiguration.

Examples:

factory = Stoplight::Wiring::LightFactory.new(container)
light = factory.build

# Light is ready to use
light.run { api_call }

Returns:

  • (Stoplight::Light)

    Configured circuit breaker

Raises:



70
71
72
# File 'lib/stoplight/wiring/light_factory.rb', line 70

def build
  light_builder(config:).build
end

#build_with(name: T.undefined, cool_off_time: T.undefined, threshold: T.undefined, recovery_threshold: T.undefined, window_size: T.undefined, tracked_errors: T.undefined, skipped_errors: T.undefined, data_store: T.undefined, error_notifier: T.undefined, notifiers: T.undefined, traffic_control: T.undefined, traffic_recovery: T.undefined) ⇒ Object

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.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/stoplight/wiring/light_factory.rb', line 80

def build_with(
  name: T.undefined,
  cool_off_time: T.undefined,
  threshold: T.undefined,
  recovery_threshold: T.undefined,
  window_size: T.undefined,
  tracked_errors: T.undefined,
  skipped_errors: T.undefined,
  data_store: T.undefined,
  error_notifier: T.undefined,
  notifiers: T.undefined,
  traffic_control: T.undefined,
  traffic_recovery: T.undefined
)
  with(
    name:,
    cool_off_time:,
    threshold:,
    recovery_threshold:,
    window_size:,
    tracked_errors:,
    skipped_errors:,
    data_store:,
    error_notifier:,
    notifiers:,
    traffic_control:,
    traffic_recovery:
  ).build
end

#hashObject

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.



110
111
112
# File 'lib/stoplight/wiring/light_factory.rb', line 110

def hash
  [self.class, config].hash
end

#with(name: T.undefined, cool_off_time: T.undefined, threshold: T.undefined, recovery_threshold: T.undefined, window_size: T.undefined, tracked_errors: T.undefined, skipped_errors: T.undefined, data_store: T.undefined, error_notifier: T.undefined, notifiers: T.undefined, traffic_control: T.undefined, traffic_recovery: T.undefined) ⇒ Object

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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stoplight/wiring/light_factory.rb', line 22

def with(
  name: T.undefined,
  cool_off_time: T.undefined,
  threshold: T.undefined,
  recovery_threshold: T.undefined,
  window_size: T.undefined,
  tracked_errors: T.undefined,
  skipped_errors: T.undefined,
  data_store: T.undefined,
  error_notifier: T.undefined,
  notifiers: T.undefined,
  traffic_control: T.undefined,
  traffic_recovery: T.undefined
)
  self.class.new(
    config: ConfigurationDsl.new(
      name:,
      cool_off_time:,
      threshold:,
      recovery_threshold:,
      window_size:,
      tracked_errors:,
      skipped_errors:,
      traffic_control:,
      traffic_recovery:,
      error_notifier:,
      data_store:,
      notifiers:
    ).configure!(config)
  )
end