Class: Stoplight::Infrastructure::Storage::CompatibilityState

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/infrastructure/storage/compatibility_state.rb

Overview

Temporary adapter that bridges Domain::Storage::State to existing DataStore.

This compatibility layer allows the state abstraction to be introduced without breaking existing data store implementations. It delegates all state operations to the data store’s original methods.

This adapter will be removed in a future versions once all data stores have native state storage implementations.

Examples:

Creating state storage for a circuit

state = CompatibilityState.new(
  data_store: redis_store,
  config: circuit_config
)
state.set_state(State::LOCKED_RED)
snapshot = state.state_snapshot

Instance Method Summary collapse

Constructor Details

#initialize(data_store:, config:) ⇒ CompatibilityState

Returns a new instance of CompatibilityState.



24
25
26
27
# File 'lib/stoplight/infrastructure/storage/compatibility_state.rb', line 24

def initialize(data_store:, config:)
  @data_store = data_store
  @config = config
end

Instance Method Details

#clearObject



35
# File 'lib/stoplight/infrastructure/storage/compatibility_state.rb', line 35

def clear = data_store.delete_light(config)

#set_state(state) ⇒ Object



31
# File 'lib/stoplight/infrastructure/storage/compatibility_state.rb', line 31

def set_state(state) = data_store.set_state(config, state)

#state_snapshotObject



29
# File 'lib/stoplight/infrastructure/storage/compatibility_state.rb', line 29

def state_snapshot = data_store.get_state_snapshot(config)

#transition_to_color(color) ⇒ Object



33
# File 'lib/stoplight/infrastructure/storage/compatibility_state.rb', line 33

def transition_to_color(color) = data_store.transition_to_color(config, color)