Sha256: a709c48c8d901f5fa52a69ebae2a537777fdd75169c2779a98ed7f915156d136

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true

module TraceLocation
  class Event # :nodoc:
    CLASS_FORMAT = /\A#<(?:Class|refinement)\:([A-Za-z0-9\:]+).*>\z/.freeze
    attr_reader :id, :event, :path, :lineno, :caller_path, :caller_lineno, :method_id, :defined_class, :hierarchy

    def initialize(id:, event:, path:, lineno:, caller_path:, caller_lineno:, method_id:, defined_class:, hierarchy:)
      @id = id
      @event = event
      @path = path
      @lineno = lineno
      @caller_path = caller_path
      @caller_lineno = caller_lineno
      @method_id = method_id
      @defined_class = defined_class
      @hierarchy = hierarchy.to_i
    end

    def valid?
      hierarchy >= 0
    end

    def invalid?
      !valid?
    end

    def call?
      event == :call
    end

    def return?
      event == :return
    end

    def method_str
      match = defined_class.to_s.match(CLASS_FORMAT)

      if match
        "#{match[1]}.#{method_id}"
      else
        "#{defined_class}##{method_id}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trace_location-0.9.1 lib/trace_location/event.rb
trace_location-0.9.0 lib/trace_location/event.rb