Class: SyntaxSuggest::PathnameFromMessage
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/syntax_suggest/pathname_from_message.rb |
Overview
Converts a SyntaxError message to a path
Handles the case where the filename has a colon in it such as on a windows file system: github.com/ruby/syntax_suggest/issues/111
Example:
= "/tmp/scratch:2:in `require_relative': /private/tmp/bad.rb:1: syntax error, unexpected `end' (SyntaxError)"
puts PathnameFromMessage.new( ).call.name
# => "/tmp/scratch.rb"
Constant Summary
-
EVAL_RE =
# File 'lib/syntax_suggest/pathname_from_message.rb', line 16/^\(eval.*\):\d+/
-
STREAMING_RE =
# File 'lib/syntax_suggest/pathname_from_message.rb', line 17/^-:\d+/
Class Method Summary
- .new(message, io: $stderr) ⇒ PathnameFromMessage constructor
Instance Attribute Summary
- #name readonly
- #skip_missing_file_name? ⇒ Boolean readonly
- #stop? ⇒ Boolean readonly
Instance Method Summary
Constructor Details
.new(message, io: $stderr) ⇒ PathnameFromMessage
# File 'lib/syntax_suggest/pathname_from_message.rb', line 20
def initialize(, io: $stderr) @line = .lines.first @parts = @line.split(":") @guess = [] @name = nil @io = io end
Instance Attribute Details
#name (readonly)
[ GitHub ]# File 'lib/syntax_suggest/pathname_from_message.rb', line 18
attr_reader :name
#skip_missing_file_name? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/syntax_suggest/pathname_from_message.rb', line 55
def skip_missing_file_name? @line.match?(EVAL_RE) || @line.match?(STREAMING_RE) end
#stop? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/syntax_suggest/pathname_from_message.rb', line 48
def stop? return true if @parts.empty? return false if @guess.empty? @name&.exist? end
Instance Method Details
#call
[ GitHub ]# File 'lib/syntax_suggest/pathname_from_message.rb', line 28
def call if skip_missing_file_name? if ENV["SYNTAX_SUGGEST_DEBUG"] @io.puts "SyntaxSuggest: Could not find filename from #{@line.inspect}" end else until stop? @guess << @parts.shift @name = Pathname(@guess.join(":")) end if @parts.empty? @io.puts "SyntaxSuggest: Could not find filename from #{@line.inspect}" @name = nil end end self end