Skip to content

Commit 7329462

Browse files
Jan Jedrychowskirohitpaulk
authored andcommitted
Ignored paths inside application
1 parent de081f7 commit 7329462

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

meta_request/lib/meta_request/config.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,17 @@ def storage_pool_size
1818
def source_path
1919
@source_path ||= ENV['SOURCE_PATH'] || Rails.root.to_s
2020
end
21+
22+
# List of relative paths inside Rails app. Used in Location calculation.
23+
def ignored_paths
24+
self.ignored_paths = %w[bin vendor] unless @ignored_paths
25+
@ignored_paths
26+
end
27+
28+
def ignored_paths=(paths)
29+
@ignored_paths = paths.map do |path|
30+
Rails.root.join(path).to_s.freeze
31+
end.freeze
32+
end
2133
end
2234
end

meta_request/lib/meta_request/utils.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Utils
55
module_function
66

77
def dev_callsite(caller)
8-
app_line = caller.detect { |c| c.start_with? MetaRequest.rails_root }
8+
app_line = caller.detect { |c| valid_application_path? c }
99
return nil unless app_line
1010

1111
_, filename, _, line, _, method = app_line.split(/^(.*?)(:(\d+))(:in `(.*)')?$/)
@@ -24,5 +24,15 @@ def sub_source_path(path)
2424

2525
path.sub(rails_root, source_path)
2626
end
27+
28+
def valid_application_path?(path)
29+
path.start_with?(MetaRequest.rails_root) && !ignored_path?(path)
30+
end
31+
32+
def ignored_path?(path)
33+
MetaRequest.config.ignored_paths.any? do |ignored_path|
34+
path.start_with?(ignored_path.to_s)
35+
end
36+
end
2737
end
2838
end

meta_request/spec/meta_request/utils_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,29 @@
4545
# revert configuration
4646
MetaRequest.config.source_path = MetaRequest.rails_root
4747
end
48+
49+
it 'ignores ignored paths' do
50+
filename = File.join(MetaRequest.rails_root, 'test_file.rb')
51+
line = 87
52+
method = 'app_func'
53+
vendor_filename = File.join(MetaRequest.rails_root, 'vendor', 'test_file.rb')
54+
55+
stacktrace = [
56+
"/gem/gem_file.rb:1:in `func'`",
57+
"#{vendor_filename}:#{line}:in `#{method}'",
58+
"#{filename}:#{line}:in `#{method}'",
59+
"#{vendor_filename}:#{line}:in `#{method}'",
60+
"/gem/gem_file.rb:1:in `func2'`"
61+
]
62+
63+
expect(MetaRequest::Utils.dev_callsite(stacktrace)).to eq(
64+
filename: filename, line: line, method: method
65+
)
66+
67+
stacktrace = [
68+
"#{vendor_filename}:#{line}:in `#{method}'"
69+
]
70+
71+
expect(MetaRequest::Utils.dev_callsite(stacktrace)).to be(nil)
72+
end
4873
end

meta_request/spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
module Rails
1616
def self.root
17-
Dir.pwd
17+
Pathname(Dir.pwd)
1818
end
1919
end
2020

0 commit comments

Comments
 (0)