Class: Nocode::Context
- Inherits:
-
Object
- Object
- Nocode::Context
- 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
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#registers ⇒ Object
readonly
Returns the value of attribute registers.
Instance Method Summary collapse
-
#initialize(io: $stdout, parameters: {}, registers: {}) ⇒ Context
constructor
A new instance of Context.
- #log(msg) ⇒ Object
- #log_line ⇒ Object
- #parameter(key) ⇒ Object
- #register(key) ⇒ Object
- #to_h ⇒ Object
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
#io ⇒ Object (readonly)
Returns the value of attribute io.
10 11 12 |
# File 'lib/nocode/context.rb', line 10 def io @io end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
10 11 12 |
# File 'lib/nocode/context.rb', line 10 def parameters @parameters end |
#registers ⇒ Object (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_line ⇒ Object
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_h ⇒ Object
30 31 32 33 34 35 |
# File 'lib/nocode/context.rb', line 30 def to_h { REGISTERS_KEY => registers, PARAMETERS_KEY => parameters } end |