class Unused::CallListener

Public Class Methods

new() click to toggle source
# File lib/unused/call_listener.rb, line 10
def initialize
  @trace = define_tracepoint
end

Public Instance Methods

disable() click to toggle source
# File lib/unused/call_listener.rb, line 18
def disable
  @trace.disable
end
enable() click to toggle source
# File lib/unused/call_listener.rb, line 14
def enable
  @trace.enable
end

Private Instance Methods

define_tracepoint() click to toggle source
# File lib/unused/call_listener.rb, line 24
def define_tracepoint
  TracePoint.new(:call) do |tp|
    next unless tp.path.start_with?(Unused.config.path)

    tracked_objects = Registry.tracked_objects
    method = tp.method_id
    owner = tp.self._method_UNUSED_ALIAS_(method).owner
    next unless tracked_objects.include? owner.object_id

    if owner.singleton_class?
      Registry.log_class_method(owner.object_id, method)
    else
      Registry.log_instance_method(owner.object_id, method)
    end
  end
end