Class: Henry::Input

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

Overview

Henry Input

Direct Known Subclasses

Config

Constant Summary collapse

EXPORT_KEY =

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

Returns:

  • (String)

    the env config key.

'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.



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

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:



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

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

.export_keyString

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

Returns:

  • (String)

    the env config key.



15
16
17
# File 'lib/henry/input.rb', line 15

def self.export_key
  Henry::Input::EXPORT_KEY 
end

.import!Input

Initialize and import the Input from the target ENV namespece.

Returns:



45
46
47
# File 'lib/henry/input.rb', line 45

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

Instance Method Details

#export!Input

Exports the Input to the target ENV namespace.

Returns:



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

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

#import!Input

Imports the Input from the target ENV namespace.

Returns:



52
53
54
55
56
57
58
59
60
# File 'lib/henry/input.rb', line 52

def import!
  if ENV[self.class.export_key]
    @params = JSON.parse(ENV[self.class.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