Class: Henry::Environment

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

Overview

Henry Environmet. To be used as proxy to access the Task execution params from the tests

Constant Summary collapse

DEFAULT_OUTPUT_DIRECTORY =

The path to the default file export directory

Returns:

  • (String)
".output"

Class Method Summary collapse

Class Method Details

.configObject



23
24
25
# File 'lib/henry/environment.rb', line 23

def self.config
  @@config ||= Henry::Config.import!.params 
end

.executionExecution

Gets the Task Execution instance via DBr.

Returns:

  • (Execution)

    the Task Execution instance.



48
49
50
# File 'lib/henry/environment.rb', line 48

def self.execution
  return @@execution ||= DRbObject.new_with_uri(ENV['DRB_EXECUTION_URI'])
end

.export_file(path) ⇒ Object

Copies the file from the given path to the default export directory

Parameters:

  • path (String)

    the path of the file to be exported.



60
61
62
63
# File 'lib/henry/environment.rb', line 60

def self.export_file(path)
  FileUtils.mkdir_p(Henry::Environment.output_path)
  FileUtils.copy_file(path, "#{Henry::Environment.output_path}/#{File.basename(path)}")
end

.loggerLogger

Gets the Task Logger instance via DBr.

Returns:

  • (Logger)

    the Task Logger.



37
38
39
40
41
42
43
# File 'lib/henry/environment.rb', line 37

def self.logger
  if ENV['DRB_LOGGER_URI']
    return @@logger ||= DRbObject.new_with_uri(ENV['DRB_LOGGER_URI'])
  end
  
  return @@logger ||= Logger.new
end

.output_pathObject

Returns the current output path for attachments.

Parameters:

  • the (String)

    attachments path.



68
69
70
# File 'lib/henry/environment.rb', line 68

def self.output_path
  File.path("#{Henry::Environment.config['output_directory']}/output" || DEFAULT_OUTPUT_DIRECTORY)
end

.paramsHash

Imports and returs the Task execution parameters.

Returns:

  • (Hash)

    the Task execution parameters



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

def self.params
  @@params ||= Input.import!.params 
end

.warning!(message = nil) ⇒ Object



52
53
54
55
# File 'lib/henry/environment.rb', line 52

def self.warning!(message = nil)
  self.execution.code = 'WARNING'
  self.execution.message = message || 'WARNING'
end