backtrace_line.rb
811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class BacktraceLine
include Mongoid::Document
IN_APP_PATH = %r{^\[PROJECT_ROOT\](?!(\/vendor))/?}
GEMS_PATH = %r{\[GEM_ROOT\]\/gems\/([^\/]+)}
field :number, :type => Integer
field :column, :type => Integer
field :file
field :method
embedded_in :backtrace
scope :in_app, where(:file => IN_APP_PATH)
delegate :app, :to => :backtrace
def to_s
"#{file_relative}:#{number}" << (column.present? ? ":#{column}" : "")
end
def in_app?
!!(file =~ IN_APP_PATH)
end
def path
File.dirname(file).gsub(/^\.$/, '') + "/"
end
def file_relative
file.to_s.sub(IN_APP_PATH, '')
end
def file_name
File.basename file
end
def decorated_path
path.sub(BacktraceLine::IN_APP_PATH, '').
sub(BacktraceLine::GEMS_PATH, "<strong>\\1</strong>")
end
end