Class: Betterp::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/betterp/source.rb

Overview

Parses a line from a stack trace to generate file path, line number, and method name.

Instance Method Summary collapse

Constructor Details

#initialize(source, base_path) ⇒ Source

Returns a new instance of Source.



6
7
8
9
10
# File 'lib/betterp/source.rb', line 6

def initialize(source, base_path)
  @source = source
  @base_path = base_path
  @path, @line_no, @method_info = source.split(':')
end

Instance Method Details

#line_noObject



18
19
20
# File 'lib/betterp/source.rb', line 18

def line_no
  @line_no.to_i
end

#method_nameObject



22
23
24
# File 'lib/betterp/source.rb', line 22

def method_name
  @method_info.partition('`').last.chomp("'")
end

#pathObject



12
13
14
15
16
# File 'lib/betterp/source.rb', line 12

def path
  Pathname.new(@path).relative_path_from(Pathname.new(@base_path)).to_s
rescue ArgumentError
  @path
end