Sha256: 06622f93424a84ed60ab72fee75cf087b143573780ae30f6682a17b44be3a3e1

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

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

    def initialize(event:, path:, lineno:, method_id:, defined_class:, hierarchy:)
      @event = event
      @path = path
      @lineno = 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.4.0 lib/trace_location/event.rb
trace_location-0.3.0 lib/trace_location/event.rb