Class: TTY::Option::ErrorAggregator

Inherits:
Object
  • Object
show all
Includes:
Inflection
Defined in:
lib/tty/option/error_aggregator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inflection

dasherize, demodulize, underscore

Constructor Details

#initialize(errors = [], raise_on_parse_error: false) ⇒ ErrorAggregator

Returns a new instance of ErrorAggregator.



13
14
15
16
# File 'lib/tty/option/error_aggregator.rb', line 13

def initialize(errors = [], raise_on_parse_error: false)
  @errors = errors
  @raise_on_parse_error = raise_on_parse_error
end

Instance Attribute Details

#errorsObject (readonly)

Collected errors



11
12
13
# File 'lib/tty/option/error_aggregator.rb', line 11

def errors
  @errors
end

Instance Method Details

#call(error, message = nil) ⇒ Object

Record or raise an error

Parameters:



24
25
26
27
28
29
30
31
32
# File 'lib/tty/option/error_aggregator.rb', line 24

def call(error, message = nil)
  if error.is_a?(Class)
    error = message.nil? ? error.new : error.new(message)
  end

  raise(error) if @raise_on_parse_error

  @errors << error
end