Class: DAF::YAMLDataSource

Inherits:
CommandDataSource show all
Defined in:
lib/daf/datasources/yaml_data_source.rb

Overview

A datasource that is parsed out of a YAML file does not permit any dynamic updates, but useful for a basic command parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ YAMLDataSource

Accepts the path of the YAML file to be parsed into commands - will throw a CommandException should it have invalid parameters

Parameters:

  • filePath (String)

    Path for YAML file



16
17
18
19
20
21
22
# File 'lib/daf/datasources/yaml_data_source.rb', line 16

def initialize(file_path)
  configuration = YAML.load_file(file_path)
  @action_class, @monitor_class = action_monitor_classes(configuration)
  @monitor = @monitor_class.new(configuration['Monitor']['Options'])
  @action = @action_class.new
  @action_options = configuration['Action']['Options']
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



9
10
11
# File 'lib/daf/datasources/yaml_data_source.rb', line 9

def action
  @action
end

#monitorObject (readonly)

Returns the value of attribute monitor.



9
10
11
# File 'lib/daf/datasources/yaml_data_source.rb', line 9

def monitor
  @monitor
end

Instance Method Details

#action_optionsObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/daf/datasources/yaml_data_source.rb', line 24

def action_options
  # Attempt resolution to outputs of monitor
  return @action_options unless @monitor_class.outputs.length > 0
  action_options = @action_options.clone
  @monitor_class.outputs.each do |output, _type|
    action_options.each do |option_key, option_value|
      action_options[option_key] =
        option_value.gsub("{{#{output}}}", @monitor.send(output).to_s)
    end
  end
  action_options
end