Class: Cl::Opts::Validate::Enum

Inherits:
Validator
  • Object
show all
Defined in:
lib/cl/opts/validate.rb

Instance Attribute Summary

Attributes inherited from Validator

#cmd, #opts, #orig, #values

Instance Method Summary collapse

Methods inherited from Validator

#compact, #invert, #only

Methods included from Regex

#format_regex

Instance Method Details

#applyObject

Raises:



83
84
85
# File 'lib/cl/opts/validate.rb', line 83

def apply
  raise UnknownValues.new(unknown) if unknown.any?
end

#unknownObject



87
88
89
90
91
92
93
94
# File 'lib/cl/opts/validate.rb', line 87

def unknown
  @unknown ||= opts.select(&:enum?).map do |opt|
    unknown = opt.unknown(values[opt.name])
    next if unknown.empty?
    known = opt.enum.map { |str| format_regex(str) }
    [opt.name, unknown, known]
  end.compact
end