Class: Rung::Runner::RunContext

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rung/runner/run_context.rb

Overview

Internal Runner context. It encapsulates operation instance, state hash and internal flags

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation_instance, initial_state) ⇒ RunContext

Returns a new instance of RunContext.

Parameters:


10
11
12
13
14
15
# File 'lib/rung/runner/run_context.rb', line 10

def initialize(operation_instance, initial_state)
  @operation_instance = operation_instance
  @state = initial_state
  @failed = false
  @stopped = false
end

Instance Attribute Details

#operation_instanceObject (readonly)

Returns the value of attribute operation_instance


20
21
22
# File 'lib/rung/runner/run_context.rb', line 20

def operation_instance
  @operation_instance
end

#stateObject (readonly)

Returns the value of attribute state


20
21
22
# File 'lib/rung/runner/run_context.rb', line 20

def state
  @state
end

Instance Method Details

#fail!Object

Marks operation run as failure


27
28
29
# File 'lib/rung/runner/run_context.rb', line 27

def fail!
  @failed = true
end

#operation_classObject


22
23
24
# File 'lib/rung/runner/run_context.rb', line 22

def operation_class
  operation_instance.class
end

#stop!Object

immediately stops operation run


32
33
34
# File 'lib/rung/runner/run_context.rb', line 32

def stop!
  @stopped = true
end

#stopped?false, true

Returns:

  • (false)

    if #stop! was called

  • (true)

    otherwise


38
39
40
# File 'lib/rung/runner/run_context.rb', line 38

def stopped?
  @stopped
end

#success?false, true

Returns:

  • (false)

    if #fail! was called

  • (true)

    otherwise


44
45
46
# File 'lib/rung/runner/run_context.rb', line 44

def success?
  !@failed
end

#to_stateRung::State

Transforms internal state to public state

Returns:


50
51
52
# File 'lib/rung/runner/run_context.rb', line 50

def to_state
  State.new state, success?, operation_instance
end