Class: Orthoses::LazyTracePoint
- Inherits:
-
TracePoint
- Object
- TracePoint
- Orthoses::LazyTracePoint
- Defined in:
- lib/orthoses/lazy_trace_point.rb
Overview
TracePoint wrapper that allows setting hooks even if the target is undefined
LazyTracePoint.new(:call) do |tp|
...
end.enable(target: 'Class#class_attribute') do
require 'active_support/core_ext/class/attribute'
...
end
Defined Under Namespace
Modules: MethodAddedHook
Constant Summary collapse
- METHOD_METHOD =
::Kernel.instance_method(:method)
- INSTANCE_METHOD_METHOD =
::Module.instance_method(:instance_method)
- UNBOUND_NAME_METHOD =
::Module.instance_method(:name)
- METHOD_ADDED_HOOKS =
{}
- SINGLETON_METHOD_ADDED_HOOKS =
{}
Instance Method Summary collapse
Instance Method Details
#enable(target: nil, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/orthoses/lazy_trace_point.rb', line 49 def enable(target: nil, &block) return super unless target.kind_of?(String) case when target.include?('#') @mod_name, instance_method_id = target.split('#', 2) @instance_method_id = instance_method_id.to_sym @singleton_method_id = nil trace_instance_method(&block) when target.include?('.') @mod_name, singleton_method_id = target.split('.', 2) @singleton_method_id = singleton_method_id.to_sym @instance_method_id = nil trace_singleton_method(&block) else raise ArgumentError, "argument shuold be 'Foo#foo' or 'Foo.foo' format" end end |