Class: DeadEnd::RipperErrors

Inherits:
Ripper
  • Object
show all
Defined in:
lib/dead_end/ripper_errors.rb

Overview

Capture parse errors from ripper

Example:

puts RipperErrors.new(" def foo").call.errors
# => ["syntax error, unexpected end-of-input, expecting ';' or '\\n'"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/dead_end/ripper_errors.rb', line 11

def errors
  @errors
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
# File 'lib/dead_end/ripper_errors.rb', line 27

def call
  @run_once ||= begin
    @errors = []
    parse
    true
  end
  self
end

#on_parse_error(msg) ⇒ Object Also known as: on_alias_error, on_assign_error, on_class_name_error, on_param_error, compile_error

Comes from ripper, called on every parse error, msg is a string



16
17
18
19
# File 'lib/dead_end/ripper_errors.rb', line 16

def on_parse_error(msg)
  @errors ||= []
  @errors << msg
end