Class: RBS::CLI::Validate::Errors
- Inherits:
-
Object
- Object
- RBS::CLI::Validate::Errors
- Defined in:
- lib/rbs/cli/validate.rb,
sig/cli/validate.rbs
Instance Method Summary collapse
- #add(error) ⇒ void
- #build_message(error) ⇒ String
-
#finish ⇒ Integer
Throws the
@tagwith 0 or 1. -
#initialize(limit:) ⇒ Errors
constructor
A new instance of Errors.
- #try { ... } ⇒ Integer
Constructor Details
#initialize(limit:) ⇒ Errors
Returns a new instance of Errors.
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.
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
38 39 40 41 42 43 44 45 |
# File 'lib/rbs/cli/validate.rb', line 38 def (error) if error.respond_to?(:detailed_message) highlight = RBS.logger_output ? RBS.logger_output.tty? : true error.(highlight: highlight) else "#{error.} (#{error.class})" end end |
#finish ⇒ Integer
Throws the @tag with 0 or 1
Must be called from the block passed to #try method.
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((error)) end throw @tag, 1 end 0 end |
#try { ... } ⇒ 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 |