Class: Cl::Opts::Validate::Requires

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:



53
54
55
# File 'lib/cl/opts/validate.rb', line 53

def apply
  raise RequiresOpts.new(invert(missing)) if missing.any?
end

#missingObject



57
58
59
60
61
62
# File 'lib/cl/opts/validate.rb', line 57

def missing
  @missing ||= requires.map do |opt|
    missing = opt.requires.select { |key| !values.key?(key) }
    [opt.name, missing] if missing.any?
  end.compact
end

#requiresObject



64
65
66
# File 'lib/cl/opts/validate.rb', line 64

def requires
  opts.select(&:requires?).select { |opt| orig.key?(opt.name) }
end