class DopCommon::Command

Attributes

hash[R]

Public Class Methods

new(hash) click to toggle source
# File lib/dop_common/command.rb, line 12
def initialize(hash)
  @hash = symbolize_keys(hash)
  @defaults = {
    :plugin_timeout => 300,
    :verify_after_run => false,
  }
end

Public Instance Methods

extended_validator=(obj) click to toggle source

Add the plugin specific validator

# File lib/dop_common/command.rb, line 36
def extended_validator=(obj)
  @extended_validator = obj if obj.respond_to?(:validate)
end
overwrite_defaults=(defaults_hash) click to toggle source
# File lib/dop_common/command.rb, line 31
def overwrite_defaults=(defaults_hash)
  @defaults.merge!(defaults_hash)
end
plugin() click to toggle source
# File lib/dop_common/command.rb, line 40
def plugin
  @plugin ||= plugin_valid? ? parse_plugin : nil
end
plugin_timeout() click to toggle source
# File lib/dop_common/command.rb, line 48
def plugin_timeout
  @plugin_timeout = plugin_timeout_valid? ? @hash[:plugin_timeout] : @defaults[:plugin_timeout]
end
title() click to toggle source
# File lib/dop_common/command.rb, line 44
def title
  @title ||= title_valid? ? @hash[:title] : plugin
end
validate() click to toggle source
# File lib/dop_common/command.rb, line 20
def validate
  log_validation_method('plugin_valid?')
  log_validation_method('verify_after_run_valid?')
  if @hash.kind_of?(Hash)
    log_validation_method('plugin_timeout_valid?')
    log_validation_method('verify_commands_valid?')
    r_plugin = @plugin || 'unknown' # name may not be set because of a previous error
    try_validate_obj("Command #{r_plugin}: Can't validate the verify_commands part because of a previous error"){verify_commands}
  end
end
verify_after_run() click to toggle source
# File lib/dop_common/command.rb, line 56
def verify_after_run
  @verify_after_run = verify_after_run_valid? ? @hash[:verify_after_run] : @defaults[:verify_after_run]
end
verify_commands() click to toggle source
# File lib/dop_common/command.rb, line 52
def verify_commands
  @verify_commands ||= verify_commands_valid? ? create_verify_commands : []
end

Private Instance Methods

create_verify_commands() click to toggle source
# File lib/dop_common/command.rb, line 109
def create_verify_commands
  case @hash[:verify_commands]
    when String, Hash then [ ::DopCommon::Command.new(@hash[:verify_commands]) ]
    when Array then @hash[:verify_commands].map {|c| ::DopCommon::Command.new(c)}
    else []
  end
end
parse_plugin() click to toggle source
# File lib/dop_common/command.rb, line 81
def parse_plugin
  case @hash
    when String then @hash
    when Hash   then @hash[:plugin]
  end
end
plugin_timeout_valid?() click to toggle source
# File lib/dop_common/command.rb, line 95
def plugin_timeout_valid?
  return false unless @hash.kind_of?(Hash)
  return false if @hash[:plugin_timeout].nil? # plugin_timeout is optional
  @hash[:plugin_timeout].kind_of?(Fixnum) or
    raise PlanParsingError, "The value for 'plugin_timeout' has to be a number"
end
plugin_valid?() click to toggle source
# File lib/dop_common/command.rb, line 62
def plugin_valid?
  if @hash.kind_of?(String)
    @hash.empty? and
      raise PlanParsingError, "The value for 'command' can not be an empty string"
  elsif @hash.kind_of?(Hash)
    @hash.empty? and
      raise PlanParsingError, "The value for 'command' can not be an empty hash"
    @hash[:plugin] or
      raise PlanParsingError, "The 'plugin key is missing in the 'command' hash"
    @hash[:plugin].kind_of?(String) or
      raise PlanParsingError, "The value for 'plugin' has to be a String with valid plugin name"
    @hash[:plugin].empty? and
      raise PlanParsingError, "The value for 'plugin' can not be an empty string"
  else
    raise PlanParsingError, "The value for 'command' must be a String with a plugin name or a hash"
  end
  true
end
title_valid?() click to toggle source
# File lib/dop_common/command.rb, line 88
def title_valid?
  return false unless @hash.kind_of?(Hash)
  return false if @hash[:title].nil?
  @hash[:title].kind_of?(String) or
    raise PlanParsingError, "The command title has to be a string"
end
verify_after_run_valid?() click to toggle source
# File lib/dop_common/command.rb, line 117
def verify_after_run_valid?
  return false unless @hash.kind_of?(Hash)
  return false if @hash[:verify_after_run].nil?
  @hash[:verify_after_run].kind_of?(TrueClass) or @hash[:verify_after_run].kind_of?(FalseClass) or
    raise PlanParsingError, "The value for 'verify_after_run' must be boolean"
end
verify_commands_valid?() click to toggle source
# File lib/dop_common/command.rb, line 102
def verify_commands_valid?
  return false unless @hash.kind_of?(Hash)
  return false if @hash[:verify_commands].nil?
  [Array, Hash, String].include? @hash[:verify_commands].class or
    raise PlanParsingError, "The value for 'verify_commands' has to be a String, Hash or an Array"
end