Class: Stoplight::Wiring::DefaultConfiguration

Inherits:
Object
  • Object
show all
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:

  1. Not configured: Stored as None, getter returns library default

  2. Explicitly configured: Stored as Some(value), getter returns that value

  3. 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 in Some

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

Examples:

Configuring Stoplight defaults

Stoplight.configure do |config|
  config.data_store = Redis.new
  config.threshold = 5
  # window_size not set - will use library default
end

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefaultConfiguration

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

Parameters:

  • value

    the value to set the attribute cool_off_time to.



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

Parameters:

  • value

    the value to set the attribute data_store to.



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

Parameters:

  • value

    the value to set the attribute error_notifier to.



73
74
75
# File 'lib/stoplight/wiring/default_configuration.rb', line 73

def error_notifier=(value)
  @error_notifier = value
end

#notifiersObject



63
# File 'lib/stoplight/wiring/default_configuration.rb', line 63

def notifiers = @config.notifiers

#recovery_threshold=(value) ⇒ Object (writeonly)

Sets the attribute recovery_threshold

Parameters:

  • value

    the value to set the attribute recovery_threshold to.



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

Parameters:

  • value

    the value to set the attribute skipped_errors to.



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

Parameters:

  • value

    the value to set the attribute threshold to.



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

Parameters:

  • value

    the value to set the attribute tracked_errors to.



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

Parameters:

  • value

    the value to set the attribute traffic_control to.



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

Parameters:

  • value

    the value to set the attribute traffic_recovery to.



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

Parameters:

  • value

    the value to set the attribute window_size to.



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