Class: TestBench::Session::Exception::FormatBacktrace
- Inherits:
-
Object
- Object
- TestBench::Session::Exception::FormatBacktrace
show all
- Defined in:
- lib/test_bench/session/exception/format_backtrace.rb,
lib/test_bench/session/exception/format_backtrace/substitute.rb
Defined Under Namespace
Modules: Defaults, Substitute
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#apex_directory ⇒ Object
10
11
12
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 10
def apex_directory
@apex_directory ||= ::Dir.pwd
end
|
#omit_patterns ⇒ Object
5
6
7
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 5
def omit_patterns
@omit_patterns ||= []
end
|
#styling ⇒ Object
Also known as:
styling?
Returns the value of attribute styling.
15
16
17
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 15
def styling
@styling
end
|
Class Method Details
.build ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 18
def self.build
instance = new
omit_patterns = Defaults.omit_patterns
instance.omit_patterns = omit_patterns
styling = Defaults.styling
instance.styling = styling
instance
end
|
30
31
32
33
34
35
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 30
def self.configure(receiver, attr_name: nil)
attr_name ||= :format_backtrace
instance = build
receiver.public_send(:"#{attr_name}=", instance)
end
|
Instance Method Details
#call(exception) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 37
def call(exception)
backtrace_locations = exception.backtrace_locations
if backtrace_locations.nil?
return
end
if styling?
omitted_text = "\e[2;3m*omitted*\e[23;22m"
else
omitted_text = '*omitted*'
end
backtrace = []
original_frame = exception.backtrace_locations.first.to_s
backtrace << original_frame
omitting = false
exception.backtrace_locations[1..-1].each do |backtrace_location|
if omit?(backtrace_location)
if not omitting
backtrace << omitted_text
end
omitting = true
else
omitting = false
end
if not omitting
backtrace << backtrace_location.to_s
end
end
backtrace.each do |backtrace_location_text|
delete_apex_directory_prefix(backtrace_location_text)
end
exception.set_backtrace(backtrace)
if exception.cause
self.(exception.cause)
end
location = exception.backtrace_locations.find do |backtrace_location|
!omit?(backtrace_location)
end
location ||= exception.backtrace_locations.first
location = "#{location.path}:#{location.lineno}"
delete_apex_directory_prefix(location)
location
end
|
#delete_apex_directory_prefix(backtrace_location_text) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 102
def delete_apex_directory_prefix(backtrace_location_text)
if styling?
relative_path_prefix = "\e[2m./\e[22m"
else
relative_path_prefix = './'
end
apex_directory_prefix = ::File.join(apex_directory, '')
if backtrace_location_text.delete_prefix!(apex_directory_prefix)
backtrace_location_text.insert(0, relative_path_prefix)
end
end
|
#omit?(backtrace_location) ⇒ Boolean
94
95
96
97
98
99
100
|
# File 'lib/test_bench/session/exception/format_backtrace.rb', line 94
def omit?(backtrace_location)
backtrace_path = backtrace_location.path
omit_patterns.any? do |omit_pattern|
::File.fnmatch?(omit_pattern, backtrace_path, ::File::FNM_EXTGLOB)
end
end
|