Class: MockServer::ScenarioHandle
- Inherits:
-
Object
- Object
- MockServer::ScenarioHandle
- Defined in:
- lib/mockserver/models.rb
Overview
A handle to a single named stateful scenario on the server, wrapping the
/mockserver/scenario/{name} control-plane endpoints.
Obtained via Client#scenario:
client.scenario('Deploy').set('Deploying', transition_after_ms: 5000, next_state: 'Deployed')
client.scenario('Deploy').trigger('Failed')
client.scenario('Deploy').state # => "Failed"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(client, name) ⇒ ScenarioHandle
constructor
A new instance of ScenarioHandle.
-
#set(state, transition_after_ms: nil, next_state: nil) ⇒ ScenarioState
PUT to set this scenario's state, optionally scheduling a timed transition to
next_stateaftertransition_after_msmilliseconds. -
#state ⇒ String?
GET the current state of this scenario (+nil+ if not yet set).
-
#trigger(new_state) ⇒ ScenarioState
PUT an external trigger advancing this scenario to
new_state.
Constructor Details
#initialize(client, name) ⇒ ScenarioHandle
Returns a new instance of ScenarioHandle.
2133 2134 2135 2136 |
# File 'lib/mockserver/models.rb', line 2133 def initialize(client, name) @client = client @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
2131 2132 2133 |
# File 'lib/mockserver/models.rb', line 2131 def name @name end |
Instance Method Details
#set(state, transition_after_ms: nil, next_state: nil) ⇒ ScenarioState
PUT to set this scenario's state, optionally scheduling a timed transition
to next_state after transition_after_ms milliseconds.
2152 2153 2154 2155 2156 2157 2158 |
# File 'lib/mockserver/models.rb', line 2152 def set(state, transition_after_ms: nil, next_state: nil) payload = { 'state' => state } payload['transitionAfterMs'] = transition_after_ms unless transition_after_ms.nil? payload['nextState'] = next_state unless next_state.nil? result = @client.scenario_request('PUT', scenario_path, JSON.generate(payload)) ScenarioState.from_hash(result) end |
#state ⇒ String?
GET the current state of this scenario (+nil+ if not yet set).
2140 2141 2142 2143 |
# File 'lib/mockserver/models.rb', line 2140 def state result = @client.scenario_request('GET', scenario_path) result['currentState'] end |
#trigger(new_state) ⇒ ScenarioState
PUT an external trigger advancing this scenario to new_state.
2164 2165 2166 2167 2168 |
# File 'lib/mockserver/models.rb', line 2164 def trigger(new_state) body = JSON.generate({ 'newState' => new_state }) result = @client.scenario_request('PUT', "#{scenario_path}/trigger", body) ScenarioState.from_hash(result) end |