Class: OrangeTap::MethodRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/orange_tap/method_registry.rb

Overview

Holds the set of methods to be traced, keyed by [owner, name] rather than by Method/UnboundMethod object identity. Method/UnboundMethod instances are freshly allocated on every obj.method(:foo) call, so identity-based bookkeeping would make untrace_method impossible to use correctly. Using owner (the singleton class for class/singleton methods) + name gives a stable identity for instance methods, class methods, and singleton methods on a specific object alike.

Constant Summary collapse

CLASS_METHOD_NOTATION =

"Foo::Bar.baz" -> class/singleton method; "Foo::Bar#baz" -> instance method. The class-path side never contains "." or "#", so a greedy match up to the last separator is unambiguous.

/\A(.+)\.([^.#]+)\z/
INSTANCE_METHOD_NOTATION =
/\A(.+)#([^.#]+)\z/

Instance Method Summary collapse

Constructor Details

#initializeMethodRegistry

Returns a new instance of MethodRegistry.



18
19
20
21
# File 'lib/orange_tap/method_registry.rb', line 18

def initialize
  @entries = {}
  @mutex = Mutex.new
end

Instance Method Details

#register(*method_objs) ⇒ Object



23
24
25
26
# File 'lib/orange_tap/method_registry.rb', line 23

def register(*method_objs)
  method_objs.each { |m| register_one(m) }
  nil
end

#register_all_instance_methods(klass) ⇒ Object



33
34
35
36
# File 'lib/orange_tap/method_registry.rb', line 33

def register_all_instance_methods(klass)
  klass.instance_methods(false).each { |m| register(klass.instance_method(m)) }
  nil
end

#targetsObject

Snapshot of currently registered ISeqs, taken once per Session#open.



39
40
41
# File 'lib/orange_tap/method_registry.rb', line 39

def targets
  @mutex.synchronize { @entries.values.dup }
end

#unregister(*method_objs) ⇒ Object



28
29
30
31
# File 'lib/orange_tap/method_registry.rb', line 28

def unregister(*method_objs)
  method_objs.each { |m| unregister_one(m) }
  nil
end