Sha256: f03b949ddc701a89bc38a56c8748f4c3660506333aaec746fef02d85d4805567

Contents?: true

Size: 899 Bytes

Versions: 4

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

module Nocode
  # Describes the environment for each running step.  An instance is initialized when a job
  # kicks off and then is passed from step to step.
  class Context
    PARAMETERS_KEY = 'parameters'
    REGISTERS_KEY  = 'registers'

    attr_reader :io,
                :parameters,
                :registers

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

      freeze
    end

    def register(key)
      registers[key]
    end

    def parameter(key)
      parameters[key]
    end

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

    def log_line
      log('-' * 50)
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nocode-0.0.10 lib/nocode/context.rb
nocode-0.0.9 lib/nocode/context.rb
nocode-0.0.8 lib/nocode/context.rb
nocode-0.0.7 lib/nocode/context.rb