Class: Nocode::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/nocode/context.rb

Overview

Describes the environment for each running step. An instance is initialized when a job kicks off and then is passed from step to step.

Constant Summary collapse

PARAMETERS_KEY =
'parameters'
REGISTERS_KEY =
'registers'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io: $stdout, parameters: {}, registers: {}) ⇒ Context

Returns a new instance of Context.



14
15
16
17
18
19
20
# File 'lib/nocode/context.rb', line 14

def initialize(io: $stdout, parameters: {}, registers: {})
  @io         = io || $stdout
  @parameters = Util::Dictionary.ensure(parameters)
  @registers  = Util::Dictionary.ensure(registers)

  freeze
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



10
11
12
# File 'lib/nocode/context.rb', line 10

def io
  @io
end

#parametersObject (readonly)

Returns the value of attribute parameters.



10
11
12
# File 'lib/nocode/context.rb', line 10

def parameters
  @parameters
end

#registersObject (readonly)

Returns the value of attribute registers.



10
11
12
# File 'lib/nocode/context.rb', line 10

def registers
  @registers
end

Instance Method Details

#log(msg) ⇒ Object



41
42
43
# File 'lib/nocode/context.rb', line 41

def log(msg)
  io.puts(msg)
end

#log_lineObject



37
38
39
# File 'lib/nocode/context.rb', line 37

def log_line
  log('-' * 50)
end

#parameter(key) ⇒ Object



26
27
28
# File 'lib/nocode/context.rb', line 26

def parameter(key)
  parameters[key]
end

#register(key) ⇒ Object



22
23
24
# File 'lib/nocode/context.rb', line 22

def register(key)
  registers[key]
end

#to_hObject



30
31
32
33
34
35
# File 'lib/nocode/context.rb', line 30

def to_h
  {
    REGISTERS_KEY => registers,
    PARAMETERS_KEY => parameters
  }
end