Module: RailsSpotlight::Utils

Defined in:
lib/rails_spotlight/utils.rb

Class Method Summary collapse

Class Method Details

.dev_callsite(caller_locations) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rails_spotlight/utils.rb', line 7

def dev_callsite(caller_locations)
  loc = caller_locations.detect { |c| c.path.start_with? RailsSpotlight.config.rails_root }
  return nil unless loc

  {
    filename: sub_source_path(loc.path),
    line: loc.lineno,
    method: loc.label
  }
rescue # rubocop:disable Style/RescueStandardError, Lint/SuppressedException
end

.sub_source_path(path) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rails_spotlight/utils.rb', line 19

def sub_source_path(path)
  rails_root = RailsSpotlight.config.rails_root
  source_path = RailsSpotlight.config.source_path
  return path if rails_root == source_path

  path.sub(rails_root, source_path)
end