Class: OrangeTap::MethodRegistry
- Inherits:
-
Object
- Object
- OrangeTap::MethodRegistry
- 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
-
#c_targets ⇒ Object
Snapshot of registered C-method keys ([owner, name]), taken once per Session#open.
-
#initialize ⇒ MethodRegistry
constructor
A new instance of MethodRegistry.
- #register(*method_objs) ⇒ Object
- #register_all_instance_methods(klass) ⇒ Object
-
#targets ⇒ Object
Snapshot of currently registered ISeqs, taken once per Session#open.
- #unregister(*method_objs) ⇒ Object
Constructor Details
#initialize ⇒ MethodRegistry
Returns a new instance of MethodRegistry.
20 21 22 23 24 25 26 27 |
# File 'lib/orange_tap/method_registry.rb', line 20 def initialize @entries = {} # [owner, name] keys for C-implemented (ISeq-less) methods, traced via a # global :c_call/:c_return TracePoint. Only populated when # OrangeTap.config.trace_c_methods is enabled at registration time. @c_entries = Set.new @mutex = Mutex.new end |
Instance Method Details
#c_targets ⇒ Object
Snapshot of registered C-method keys ([owner, name]), taken once per Session#open. Empty unless trace_c_methods was enabled at registration time. Session uses this to decide whether to build a global C TracePoint.
52 53 54 |
# File 'lib/orange_tap/method_registry.rb', line 52 def c_targets @mutex.synchronize { @c_entries.dup } end |
#register(*method_objs) ⇒ Object
29 30 31 32 |
# File 'lib/orange_tap/method_registry.rb', line 29 def register(*method_objs) method_objs.each { |m| register_one(m) } nil end |
#register_all_instance_methods(klass) ⇒ Object
39 40 41 42 |
# File 'lib/orange_tap/method_registry.rb', line 39 def register_all_instance_methods(klass) klass.instance_methods(false).each { |m| register(klass.instance_method(m)) } nil end |
#targets ⇒ Object
Snapshot of currently registered ISeqs, taken once per Session#open.
45 46 47 |
# File 'lib/orange_tap/method_registry.rb', line 45 def targets @mutex.synchronize { @entries.values.dup } end |
#unregister(*method_objs) ⇒ Object
34 35 36 37 |
# File 'lib/orange_tap/method_registry.rb', line 34 def unregister(*method_objs) method_objs.each { |m| unregister_one(m) } nil end |