Class: Henry::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/henry/input.rb

Overview

Henry Input

Constant Summary collapse

EXPORT_KEY =

ENV key where the Input will be exported to/imported from.

'HENRY_INPUT'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Input

Initialize the Input with the given params or empty.

Parameters:

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

    the Input params.



13
14
15
# File 'lib/henry/input.rb', line 13

def initialize(params={})
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/henry/input.rb', line 5

def params
  @params
end

Class Method Details

.export!(params) ⇒ Input

Initialize and export the Input to the target ENV namespace.

Parameters:

  • params (Hash)

    the Input params to be exported.

Returns:



21
22
23
# File 'lib/henry/input.rb', line 21

def self.export!(params)
  self.new(params).export!
end

.import!Input

Initialize and import the Input from the target ENV namespece.

Returns:



36
37
38
# File 'lib/henry/input.rb', line 36

def self.import!
  self.new.import!
end

Instance Method Details

#export!Input

Exports the Input to the target ENV namespace.

Returns:



28
29
30
31
# File 'lib/henry/input.rb', line 28

def export!
  ENV[EXPORT_KEY] = JSON.dump(@params)
  self
end

#import!Input

Imports the Input from the target ENV namespace.

Returns:



43
44
45
46
47
48
49
50
51
# File 'lib/henry/input.rb', line 43

def import!
  if ENV[EXPORT_KEY]
    @params = JSON.parse(ENV[EXPORT_KEY])
  else
    warn("Could not load the execution params.\nAre you running this Task via the henry-ruby-container? You should!".red)
  end

  self
end