Class: R10K::Settings::EnumDefinition

Inherits:
Definition
  • Object
show all
Defined in:
lib/r10k/settings/enum_definition.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP

Instance Attribute Summary

Attributes inherited from Definition

#desc, #name, #value

Instance Method Summary collapse

Methods inherited from Definition

#assign, #evaluate, #initialize, #resolve

Methods included from Logging

add_outputters, debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods included from Helpers

included

Constructor Details

This class inherits a constructor from R10K::Settings::Definition

Instance Method Details

#validateObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/r10k/settings/enum_definition.rb', line 7

def validate
  if @value
    if @multi && @value.respond_to?(:select)
      invalid = @value.select { |val| !@enum.include?(val) }

      if invalid.size > 0
        raise ArgumentError, _("Setting %{name} may only contain %{enums}; the disallowed values %{invalid} were present") % {name: @name, enums: @enum.inspect, invalid: invalid.inspect}
      end
    else
      if !@enum.include?(@value)
        raise ArgumentError, _("Setting %{name} should be one of %{enums}, not '%{value}'") % {name: @name, enums: @enum.inspect, value: @value}
      end
    end
  end
end