Class: TTY::Option::Parser::ArityCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/option/parser/arity_check.rb

Instance Method Summary collapse

Constructor Details

#initialize(error_aggregator) ⇒ ArityCheck

Returns a new instance of ArityCheck.



7
8
9
10
# File 'lib/tty/option/parser/arity_check.rb', line 7

def initialize(error_aggregator)
  @multiplies = []
  @error_aggregator = error_aggregator
end

Instance Method Details

#add(param) ⇒ Object Also known as: <<



12
13
14
# File 'lib/tty/option/parser/arity_check.rb', line 12

def add(param)
  @multiplies << param
end

#call(arities) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if parameter matches arity

Raises:



22
23
24
25
26
27
28
29
30
# File 'lib/tty/option/parser/arity_check.rb', line 22

def call(arities)
  @multiplies.each do |param|
    arity = arities[param.key]

    if arity < param.min_arity
      @error_aggregator.(InvalidArity.new(param, arity))
    end
  end
end