Class: Dontbugme::SourceLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/dontbugme/source_location.rb

Class Method Summary collapse

Class Method Details

.captureObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dontbugme/source_location.rb', line 6

def capture
  return nil unless Dontbugme.config.recording?
  return nil if Dontbugme.config.source_mode == :off

  config = Dontbugme.config
  limit = config.source_stack_limit
  depth = config.source_mode == :shallow ? 1 : config.source_depth
  filters = config.source_filter

  locations = caller_locations(1, limit)
  return nil if locations.nil? || locations.empty?

  exclude_patterns = %w[dontbugme /gems/ bundler]
  app_frames = locations.select do |loc|
    path = loc.absolute_path || loc.path.to_s
    next false if exclude_patterns.any? { |p| path.include?(p) }
    filters.any? { |f| path.include?(f) }
  end

  return nil if app_frames.empty?

  frames_to_keep = app_frames.first(depth)
  frames_to_keep.map { |loc| format_location(loc) }.join(' <- ')
end