Class: Optimist::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/optimist.rb

Overview

Abstract class for a constraint. Do not use by itself.

Instance Method Summary collapse

Constructor Details

#initialize(syms) ⇒ Constraint

Returns a new instance of Constraint.



42
43
44
# File 'lib/optimist.rb', line 42

def initialize(syms)
  @idents = syms
end

Instance Method Details

#validate(given_args:, specs:) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/optimist.rb', line 45

def validate(given_args:, specs:)
  overlap = @idents & given_args.keys
  if error_condition(overlap.size)
    longargs = @idents.map { |sym| "--#{specs[sym].long.long}" }
    raise CommandlineError, error_message(longargs)
  end
end