class DAF::YAMLDataSource
A datasource that is parsed out of a YAML file does not permit any dynamic updates, but useful for a basic command parser
Attributes
action[R]
monitor[R]
Public Class Methods
new(file_path)
click to toggle source
Accepts the path of the YAML file to be parsed into commands - will throw a CommandException
should it have invalid parameters
@param filePath [String] Path for YAML file
# 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
Public Instance Methods
action_options()
click to toggle source
# 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
Protected Instance Methods
action_monitor_classes(configuration)
click to toggle source
# File lib/daf/datasources/yaml_data_source.rb, line 37 def action_monitor_classes(configuration) begin action_class = get_class(configuration['Action']['Type']) monitor_class = get_class(configuration['Monitor']['Type']) rescue raise CommandException, 'Invalid Action or Monitor type' end [action_class, monitor_class] end
get_class(class_name)
click to toggle source
# File lib/daf/datasources/yaml_data_source.rb, line 47 def get_class(class_name) Object.const_get(class_name) end