Class: AppMap::Hook::Method

Inherits:
Object show all
Defined in:
lib/appmap/hook/method.rb,
lib/appmap/hook/method/ruby2.rb,
lib/appmap/hook/method/ruby3.rb

Overview

Delegation methods for Ruby 3.

Constant Summary collapse

HOOK_DISABLE_KEY =
'AppMap::Hook.disable'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook_package, hook_class, hook_method) ⇒ Method

Returns a new instance of Method.



30
31
32
33
34
35
36
# File 'lib/appmap/hook/method.rb', line 30

def initialize(hook_package, hook_class, hook_method)
  @hook_package = hook_package
  @hook_class = hook_class
  @hook_method = hook_method
  @parameters = hook_method.parameters
  @arity = hook_method.arity
end

Instance Attribute Details

#arityObject (readonly)

Returns the value of attribute arity.



26
27
28
# File 'lib/appmap/hook/method.rb', line 26

def arity
  @arity
end

#hook_classObject (readonly)

Returns the value of attribute hook_class.



26
27
28
# File 'lib/appmap/hook/method.rb', line 26

def hook_class
  @hook_class
end

#hook_methodObject (readonly)

Returns the value of attribute hook_method.



26
27
28
# File 'lib/appmap/hook/method.rb', line 26

def hook_method
  @hook_method
end

#hook_packageObject (readonly)

Returns the value of attribute hook_package.



26
27
28
# File 'lib/appmap/hook/method.rb', line 26

def hook_package
  @hook_package
end

#parametersObject (readonly)

Returns the value of attribute parameters.



26
27
28
# File 'lib/appmap/hook/method.rb', line 26

def parameters
  @parameters
end

Instance Method Details

#activateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/appmap/hook/method.rb', line 38

def activate
  if Hook::LOG
    msg = if method_display_name
            "#{method_display_name}"
          else
            "#{hook_method.name} (class resolution deferred)"
          end
    warn "AppMap: Hooking #{msg} at line #{(hook_method.source_location || []).join(':')}"
  end

  hook_method_parameters = hook_method.parameters.dup.freeze
  SIGNATURES[[ hook_class, hook_method.name ]] = hook_method_parameters

  # irb(main):001:0> Kernel.public_instance_method(:system)
  # (irb):1:in `public_instance_method': method `system' for module `Kernel' is  private (NameError)
  if hook_class == Kernel
    hook_class.define_method_with_arity(hook_method.name, hook_method.arity, hook_method_def)
  else
    cls = defining_class(hook_class)
    if cls
      cls.define_method_with_arity(hook_method.name, hook_method.arity, hook_method_def)
    end
  end
end

#call(receiver, *args, **kwargs, &block) ⇒ Object



7
8
9
10
11
12
# File 'lib/appmap/hook/method/ruby3.rb', line 7

def call(receiver, *args, **kwargs, &block)
  call_event = trace? && with_disabled_hook { before_hook receiver, *args, **kwargs }
  # note we can't short-circuit directly to do_call because then the call stack
  # depth changes and eval handler doesn't work correctly
  trace_call call_event, receiver, *args, **kwargs, &block
end