class DopCommon::Step

Public Class Methods

new(hash) click to toggle source
# File lib/dop_common/step.rb, line 10
def initialize(hash)
  @hash = HashParser.symbolize_keys(hash)
  HashParser.key_aliases(@hash, :commands, [:command])
end

Public Instance Methods

commands() click to toggle source
# File lib/dop_common/step.rb, line 64
def commands
  @commands ||= commands_valid? ? create_commands : nil
end
delete_plugin_defaults() click to toggle source
# File lib/dop_common/step.rb, line 73
def delete_plugin_defaults
  @delete_plugin_defaults ||= delete_plugin_defaults_valid? ?
    parse_plugin_pattern_array(:delete_plugin_defaults) : []
end
exclude_nodes() click to toggle source
# File lib/dop_common/step.rb, line 39
def exclude_nodes
  @exclude_nodes ||= exclude_nodes_valid? ?
    HashParser.parse_pattern_list(@hash, :exclude_nodes) : []
end
exclude_nodes_by_config() click to toggle source
# File lib/dop_common/step.rb, line 49
def exclude_nodes_by_config
  @exclude_nodes_by_config ||= exclude_nodes_by_config_valid? ?
    HashParser.parse_hash_of_pattern_lists(@hash, :exclude_nodes_by_config) : {}
end
exclude_roles() click to toggle source
# File lib/dop_common/step.rb, line 59
def exclude_roles
  @exclude_roles ||= exclude_roles_valid? ?
    HashParser.parse_pattern_list(@hash, :exclude_roles) : []
end
name() click to toggle source
# File lib/dop_common/step.rb, line 15
def name
  @name ||= @hash[:name] or
    raise PlanParsingError, "Every step needs to have a 'name' key defined"
end
nodes() click to toggle source
# File lib/dop_common/step.rb, line 34
def nodes
  @nodes ||= nodes_valid? ?
    HashParser.parse_pattern_list(@hash, :nodes) : []
end
nodes_by_config() click to toggle source
# File lib/dop_common/step.rb, line 44
def nodes_by_config
  @nodes_by_config ||= nodes_by_config_valid? ?
    HashParser.parse_hash_of_pattern_lists(@hash, :nodes_by_config) : {}
end
roles() click to toggle source
# File lib/dop_common/step.rb, line 54
def roles
  @roles ||= roles_valid? ?
    HashParser.parse_pattern_list(@hash, :roles) : []
end
set_plugin_defaults() click to toggle source
# File lib/dop_common/step.rb, line 68
def set_plugin_defaults
  @set_plugin_defaults ||= set_plugin_defaults_valid? ?
    parse_plugin_pattern_array(:set_plugin_defaults) : []
end
validate() click to toggle source
# File lib/dop_common/step.rb, line 20
def validate
  valitdate_shared_options
  log_validation_method('name')
  log_validation_method('nodes_valid?')
  log_validation_method('exclude_nodes_valid?')
  log_validation_method('nodes_by_config_valid?')
  log_validation_method('exclude_nodes_by_config_valid?')
  log_validation_method('roles_valid?')
  log_validation_method('exclude_roles_valid?')
  log_validation_method('commands_valid?')
  r_name = @name || 'unknown' # name may not be set because of a previous error
  try_validate_obj("Step #{r_name}: Can't validate the commands part because of a previous error"){commands}
end

Private Instance Methods

commands_valid?() click to toggle source
# File lib/dop_common/step.rb, line 116
def commands_valid?
  @hash[:commands] or
    raise PlanParsingError, "Step #{@name}: A commands key has to be defined"
  case @hash[:commands]
  when String, Hash
    true
  when Array
    @hash[:commands].all?{|c| c.kind_of?(String) or c.kind_of?(Hash)} or
      raise PlanParsingError, "Step #{@name}: All commands must be Strings or Hashes"
  else
    raise PlanParsingError,
      "Step #{@name}: The value for commands has to be a string, a hash or an array"
  end
end
create_commands() click to toggle source
# File lib/dop_common/step.rb, line 131
def create_commands
  [@hash[:commands]].flatten.map do |command|
    ::DopCommon::Command.new(command)
  end
end
delete_plugin_defaults_valid?() click to toggle source
# File lib/dop_common/step.rb, line 153
def delete_plugin_defaults_valid?
  return false if @hash[:delete_plugin_defaults].nil? # is optional
  @hash[:delete_plugin_defaults].kind_of?(Array) or
  @hash[:delete_plugin_defaults].kind_of?(String) or
  @hash[:delete_plugin_defaults].kind_of?(Symbol) or
    raise PlanParsingError, "Step #{@name}: The value of 'delete_plugin_defaults' has to be an array or :all"
  unless @hash[:delete_plugin_defaults].kind_of?(Array)
    ['all', 'All', 'ALL', :all].include?(@hash[:delete_plugin_defaults]) or
      raise PlanParsingError, "Step #{@name}: The value of 'delete_plugin_defaults' has to be an array or :all"
  else
    return false unless plugin_pattern_array_valid?(:delete_plugin_defaults)
    @hash[:delete_plugin_defaults].all? do |entry|
      HashParser.key_aliases(entry, :delete_keys, ['delete_keys', :delete_key, 'delete_key'])
      entry[:delete_keys].nil? and
        raise PlanParsingError, "Step #{@name}: Each entry in the 'delete_plugin_defaults' array needs a valid value for 'delete_keys'"
      entry[:delete_keys].kind_of?(Array) or
      entry[:delete_keys].kind_of?(String) or
      entry[:delete_keys].kind_of?(Symbol) or
        raise PlanParsingError, "Step #{@name}: The value for 'delete_keys' in 'delete_plugin_defaults' has to be a string or an array"
      if entry[:delete_keys].kind_of?(Array)
        entry[:delete_keys].all?{|e| e.kind_of?(String) or e.kind_of?(Symbol)} or
          raise PlanParsingError, "Step #{@name}: The elements in 'delete_keys' in 'delete_plugin_defaults' have to me strings or symbols"
      end
    end
  end
  true
end
exclude_nodes_by_config_valid?() click to toggle source
# File lib/dop_common/step.rb, line 92
def exclude_nodes_by_config_valid?
  hash_of_pattern_lists_valid?(@hash, :exclude_nodes_by_config)
end
exclude_nodes_valid?() click to toggle source
# File lib/dop_common/step.rb, line 84
def exclude_nodes_valid?
  pattern_list_valid?(@hash, :exclude_nodes)
end
exclude_roles_valid?() click to toggle source
# File lib/dop_common/step.rb, line 100
def exclude_roles_valid?
  pattern_list_valid?(@hash, :exclude_roles)
end
hash_of_pattern_lists_valid?(hash, key, optional = true) click to toggle source
# File lib/dop_common/step.rb, line 110
def hash_of_pattern_lists_valid?(hash, key, optional = true)
  HashParser.hash_of_pattern_lists_valid?(hash, key, optional)
rescue PlanParsingError => e
  raise PlanParsingError, "Step #{@name}: #{e.message}"
end
nodes_by_config_valid?() click to toggle source
# File lib/dop_common/step.rb, line 88
def nodes_by_config_valid?
  hash_of_pattern_lists_valid?(@hash, :nodes_by_config)
end
nodes_valid?() click to toggle source
# File lib/dop_common/step.rb, line 80
def nodes_valid?
  pattern_list_valid?(@hash, :nodes)
end
parse_plugin_pattern_array(key) click to toggle source
# File lib/dop_common/step.rb, line 181
def parse_plugin_pattern_array(key)
  unless @hash[key].kind_of?(Array)
    :all
  else
    @hash[key].map do |entry|
      result = entry.dup
      result[:plugins] = HashParser.parse_pattern_list(entry, :plugins)
      delete_keys = case entry[:delete_keys]
      when 'all', 'All', 'ALL', :all then :all
      when String, Array then [entry[:delete_keys]].flatten
      else nil
      end
      result[:delete_keys] = delete_keys if delete_keys
      result
    end
  end
end
pattern_list_valid?(hash, key, optional = true) click to toggle source
# File lib/dop_common/step.rb, line 104
def pattern_list_valid?(hash, key, optional = true)
  HashParser.pattern_list_valid?(hash, key, optional)
rescue PlanParsingError => e
  raise PlanParsingError, "Step #{@name}: #{e.message}"
end
plugin_pattern_array_valid?(key) click to toggle source
# File lib/dop_common/step.rb, line 137
def plugin_pattern_array_valid?(key)
  @hash[key].all? do |entry|
    entry.kind_of?(Hash) or
      raise PlanParsingError, "Step #{@name}: Each entry in the '#{key}' array has to be a hash"
    HashParser.key_aliases(entry, :plugins, ['plugins', :plugin, 'plugin'])
    pattern_list_valid?(entry, :plugins, false)
  end
end
roles_valid?() click to toggle source
# File lib/dop_common/step.rb, line 96
def roles_valid?
  pattern_list_valid?(@hash, :roles)
end
set_plugin_defaults_valid?() click to toggle source
# File lib/dop_common/step.rb, line 146
def set_plugin_defaults_valid?
  return false if @hash[:set_plugin_defaults].nil? # is optional
  @hash[:set_plugin_defaults].kind_of?(Array) or
    raise PlanParsingError, "Step #{@name}: The value of 'set_plugin_defaults' has to be an array"
  plugin_pattern_array_valid?(:set_plugin_defaults)
end