module DAF::Configurable

Module used for configurable objects internally adds the has_option class method that creates an option for use on Monitor and Action subclasses - it exposes the options that are present, and required types, so that parsers and UI can view them if required

Public Class Methods

included(base) click to toggle source
# File lib/daf/configurable.rb, line 32
def self.included(base)
  base.send(:extend, ClassMethods)
end

Protected Instance Methods

process_options(options) click to toggle source

Processes given parameter into the defined options previously declared includes validation for types and any custom validators delcared

@param [Hash<String,Object>] Hash of option name/value pairs, values must conform to validation rules for options or exception will be raised

# File lib/daf/configurable.rb, line 13
def process_options(options)
  options.each do |key, value|
    key = key.to_s
    fail OptionException, "No Option #{key}" unless self.class.options[key]
    opt = send("#{key}")
    opt.value = value
    fail OptionException, "Bad value for option #{key}" unless opt.valid?
  end
  validate_required_options
end

Private Instance Methods

validate_required_options() click to toggle source
# File lib/daf/configurable.rb, line 24
def validate_required_options
  self.class.send('required_options').each do |name|
    opt = send("#{name}")
    fail OptionException,
         "Required option #{name} missing or invalid" unless opt.valid?
  end
end