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 (
nilif 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.
1843 1844 1845 1846 |
# File 'lib/mockserver/models.rb', line 1843 def initialize(client, name) @client = client @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
1841 1842 1843 |
# File 'lib/mockserver/models.rb', line 1841 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.
1862 1863 1864 1865 1866 1867 1868 |
# File 'lib/mockserver/models.rb', line 1862 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).
1850 1851 1852 1853 |
# File 'lib/mockserver/models.rb', line 1850 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.
1874 1875 1876 1877 1878 |
# File 'lib/mockserver/models.rb', line 1874 def trigger(new_state) body = JSON.generate({ 'newState' => new_state }) result = @client.scenario_request('PUT', "#{scenario_path}/trigger", body) ScenarioState.from_hash(result) end |