Class: RBS::CLI::Validate::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/cli/validate.rb,
sig/cli/validate.rbs

Instance Method Summary collapse

Constructor Details

#initialize(limit:) ⇒ Errors

Returns a new instance of Errors.

Parameters:

  • limit: (Integer, nil)


7
8
9
10
# File 'lib/rbs/cli/validate.rb', line 7

def initialize(limit:)
  @limit = limit
  @errors = []
end

Instance Method Details

#add(error) ⇒ void

This method returns an undefined value.

Parameters:



12
13
14
15
# File 'lib/rbs/cli/validate.rb', line 12

def add(error)
  @errors << error
  finish if @limit == 1
end

#build_message(error) ⇒ String

Parameters:

Returns:

  • (String)


38
39
40
41
42
43
44
45
# File 'lib/rbs/cli/validate.rb', line 38

def build_message(error)
  if error.respond_to?(:detailed_message)
    highlight = RBS.logger_output ? RBS.logger_output.tty? : true
    error.detailed_message(highlight: highlight)
  else
    "#{error.message} (#{error.class})"
  end
end

#finishInteger

Throws the @tag with 0 or 1

Must be called from the block passed to #try method.

Returns:

  • (Integer)


19
20
21
22
23
24
25
26
27
28
# File 'sig/cli/validate.rbs', line 19

def finish
  unless @errors.empty?
    @errors.each do |error|
      RBS.logger.error(build_message(error))
    end
    throw @tag, 1
  end

  0
end

#try { ... } ⇒ Integer

Yields:

Yield Returns:

  • (void)

Returns:

  • (Integer)


17
18
19
20
21
22
23
# File 'lib/rbs/cli/validate.rb', line 17

def try(&block)
  catch(:finish) do |tag|
    @tag = tag
    yield
    finish()
  end
end