Class: NextStation::State

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/next_station/state.rb

Overview

Holds the mutable state during operation execution.

It wraps a data hash and provides access to params and context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, context = {}, plugins = []) ⇒ State

Returns a new instance of State.

Parameters:

  • params (Hash) (defaults to: {})

    Initial parameters.

  • context (Hash) (defaults to: {})

    Shared context (immutable).



22
23
24
25
26
27
28
# File 'lib/next_station/state.rb', line 22

def initialize(params = {}, context = {}, plugins = [])
  @context = context.dup.freeze
  @data = { params: unwrap_params(params).dup }
  @step_attempt = 1
  @current_step = nil
  extend_with_plugins(plugins)
end

Instance Attribute Details

#contextHash (readonly)

Returns The execution context.

Returns:

  • (Hash)

    The execution context.



14
15
16
# File 'lib/next_station/state.rb', line 14

def context
  @context
end

#current_stepSymbol? (readonly)

Returns The name of the current step being executed.

Returns:

  • (Symbol, nil)

    The name of the current step being executed.



18
19
20
# File 'lib/next_station/state.rb', line 18

def current_step
  @current_step
end

#step_attemptInteger (readonly)

Returns The attempt number of the current step.

Returns:

  • (Integer)

    The attempt number of the current step.



16
17
18
# File 'lib/next_station/state.rb', line 16

def step_attempt
  @step_attempt
end

Instance Method Details

#paramsHash

Returns the input parameters.

Returns:

  • (Hash)


44
45
46
# File 'lib/next_station/state.rb', line 44

def params
  @data[:params]
end

#set_current_step(value) ⇒ Object

Sets the name of the current step.

Parameters:

  • value (Symbol, nil)


38
39
40
# File 'lib/next_station/state.rb', line 38

def set_current_step(value)
  @current_step = value
end

#set_step_attempt(value) ⇒ Object

Sets the current attempt number for the active step.

Parameters:

  • value (Integer)


32
33
34
# File 'lib/next_station/state.rb', line 32

def set_step_attempt(value)
  @step_attempt = value
end