summaryrefslogtreecommitdiff
path: root/lib/gitlab/sherlock/location.rb
blob: 4bba60f3490c8bad1c5d73153e71587af4e328ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module Gitlab
  module Sherlock
    class Location
      attr_reader :path, :line

      SHERLOCK_DIR = File.dirname(__FILE__)

      # Creates a new Location from a `Thread::Backtrace::Location`.
      def self.from_ruby_location(location)
        new(location.path, location.lineno)
      end

      # path - The full path of the frame as a String.
      # line - The line number of the frame as a Fixnum.
      def initialize(path, line)
        @path = path
        @line = line
      end

      # Returns true if the current frame originated from the application.
      def application?
        @path.start_with?(Rails.root.to_s) && !path.start_with?(SHERLOCK_DIR)
      end
    end
  end
end