Skip to content

Commit c3bcfa0

Browse files
authored
Minor refactors (#2392)
* Simplify Attachment#infer_filename * Small refactor on Profiler's frames collection
1 parent 5980531 commit c3bcfa0

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

sentry-ruby/lib/sentry/attachment.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Attachment
88

99
def initialize(bytes: nil, filename: nil, content_type: nil, path: nil)
1010
@bytes = bytes
11-
@filename = infer_filename(filename, path)
11+
@filename = filename || infer_filename(path)
1212
@path = path
1313
@content_type = content_type
1414
end
@@ -29,9 +29,7 @@ def payload
2929

3030
private
3131

32-
def infer_filename(filename, path)
33-
return filename if filename
34-
32+
def infer_filename(path)
3533
if path
3634
File.basename(path)
3735
else

sentry-ruby/lib/sentry/profiler.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,12 @@ def to_hash
9090

9191
frame_map = {}
9292

93-
frames = results[:frames].to_enum.with_index.map do |frame, idx|
94-
frame_id, frame_data = frame
95-
93+
frames = results[:frames].map.with_index do |(frame_id, frame_data), idx|
9694
# need to map over stackprof frame ids to ours
9795
frame_map[frame_id] = idx
9896

9997
file_path = frame_data[:file]
98+
lineno = frame_data[:line]
10099
in_app = in_app?(file_path)
101100
filename = compute_filename(file_path, in_app)
102101
function, mod = split_module(frame_data[:name])
@@ -109,7 +108,7 @@ def to_hash
109108
}
110109

111110
frame_hash[:module] = mod if mod
112-
frame_hash[:lineno] = frame_data[:line] if frame_data[:line] && frame_data[:line] >= 0
111+
frame_hash[:lineno] = lineno if lineno && lineno >= 0
113112

114113
frame_hash
115114
end

0 commit comments

Comments
 (0)