Class: Stoplight::Wiring::DefaultConfiguration
- Inherits:
-
Object
- Object
- Stoplight::Wiring::DefaultConfiguration
- Defined in:
- lib/stoplight/wiring/default_configuration.rb
Overview
User-facing configuration interface for setting global Stoplight defaults.
This class serves as the configuration DSL yielded to users when calling Stoplight.configure. It provides a clean interface for setting default values while internally tracking whether each setting was explicitly configured or should fall back to library defaults.
Option-Based Configuration Tracking
Internally, each setting is wrapped in an Option type (Some or None). This design allows the class to distinguish between three states:
-
Not configured: Stored as
None, getter returns library default -
Explicitly configured: Stored as Some(value), getter returns that value
-
Explicitly set to nil: Stored as Some(nil), getter returns
nil
This distinction is critical when building Settings and Dependencies objects, which need to know whether a value was user-specified (and should be enforced) or inherited (and can be overridden per-circuit).
Dual Interface
The class exposes two interfaces for each setting:
-
Setters (
attr_writer): Accept raw values, wrap them inSome -
Getters (custom methods): Unwrap the Option, returning the value or falling back to library defaults from Default
The #settings and #dependencies methods preserve the raw Option values, allowing downstream code to detect explicit configuration.
Instance Attribute Summary collapse
-
#cool_off_time ⇒ Object
writeonly
Sets the attribute cool_off_time.
-
#data_store ⇒ Object
writeonly
Sets the attribute data_store.
-
#error_notifier ⇒ Object
writeonly
Sets the attribute error_notifier.
- #notifiers ⇒ Object
-
#recovery_threshold ⇒ Object
writeonly
Sets the attribute recovery_threshold.
-
#skipped_errors ⇒ Object
writeonly
Sets the attribute skipped_errors.
-
#threshold ⇒ Object
writeonly
Sets the attribute threshold.
-
#tracked_errors ⇒ Object
writeonly
Sets the attribute tracked_errors.
-
#traffic_control ⇒ Object
writeonly
Sets the attribute traffic_control.
-
#traffic_recovery ⇒ Object
writeonly
Sets the attribute traffic_recovery.
-
#window_size ⇒ Object
writeonly
Sets the attribute window_size.
Instance Method Summary collapse
-
#initialize ⇒ DefaultConfiguration
constructor
A new instance of DefaultConfiguration.
-
#to_config! ⇒ Object
Builds and validates configuration.
Constructor Details
#initialize ⇒ DefaultConfiguration
Returns a new instance of DefaultConfiguration.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 48 def initialize @config = DefaultConfig.with @cool_off_time = T.undefined @threshold = T.undefined @recovery_threshold = T.undefined @window_size = T.undefined @tracked_errors = T.undefined @skipped_errors = T.undefined @traffic_control = T.undefined @traffic_recovery = T.undefined @error_notifier = T.undefined @data_store = T.undefined @notifiers = T.undefined end |
Instance Attribute Details
#cool_off_time=(value) ⇒ Object (writeonly)
Sets the attribute cool_off_time
65 66 67 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 65 def cool_off_time=(value) @cool_off_time = value end |
#data_store=(value) ⇒ Object (writeonly)
Sets the attribute data_store
74 75 76 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 74 def data_store=(value) @data_store = value end |
#error_notifier=(value) ⇒ Object (writeonly)
Sets the attribute error_notifier
73 74 75 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 73 def error_notifier=(value) @error_notifier = value end |
#notifiers ⇒ Object
63 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 63 def notifiers = @config.notifiers |
#recovery_threshold=(value) ⇒ Object (writeonly)
Sets the attribute recovery_threshold
67 68 69 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 67 def recovery_threshold=(value) @recovery_threshold = value end |
#skipped_errors=(value) ⇒ Object (writeonly)
Sets the attribute skipped_errors
70 71 72 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 70 def skipped_errors=(value) @skipped_errors = value end |
#threshold=(value) ⇒ Object (writeonly)
Sets the attribute threshold
66 67 68 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 66 def threshold=(value) @threshold = value end |
#tracked_errors=(value) ⇒ Object (writeonly)
Sets the attribute tracked_errors
69 70 71 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 69 def tracked_errors=(value) @tracked_errors = value end |
#traffic_control=(value) ⇒ Object (writeonly)
Sets the attribute traffic_control
71 72 73 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 71 def traffic_control=(value) @traffic_control = value end |
#traffic_recovery=(value) ⇒ Object (writeonly)
Sets the attribute traffic_recovery
72 73 74 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 72 def traffic_recovery=(value) @traffic_recovery = value end |
#window_size=(value) ⇒ Object (writeonly)
Sets the attribute window_size
68 69 70 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 68 def window_size=(value) @window_size = value end |
Instance Method Details
#to_config! ⇒ Object
Builds and validates configuration
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/stoplight/wiring/default_configuration.rb', line 78 def to_config! ConfigurationDsl.new( cool_off_time: @cool_off_time, threshold: @threshold, recovery_threshold: @recovery_threshold, window_size: @window_size, tracked_errors: @tracked_errors, skipped_errors: @skipped_errors, traffic_control: @traffic_control, traffic_recovery: @traffic_recovery, error_notifier: @error_notifier, data_store: @data_store, notifiers: @notifiers ).configure!(@config) end |