79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/appmap/event.rb', line 79
def build_from_invocation(mc = MethodCall.new, defined_class, method, receiver, arguments)
mc.tap do
static = receiver.is_a?(Module)
mc.defined_class = defined_class
mc.method_id = method.name.to_s
if method.source_location
path = method.source_location[0]
path = path[Dir.pwd.length + 1..-1] if path.index(Dir.pwd) == 0
mc.path = path
mc.lineno = method.source_location[1]
else
mc.path = [ defined_class, static ? '.' : '#', method.name ].join
end
has_key = [[:dummy], *method.parameters].last.first.to_s.start_with?('key') && arguments[-1].is_a?(Hash)
kwargs = has_key && arguments[-1].dup || {}
mc.parameters = method.parameters.map.with_index do |method_param, idx|
param_type, param_name = method_param
param_name ||= 'arg'
value = case param_type
when :keyrest
kwargs
when /^key/
kwargs.delete param_name
when :rest
arguments[idx..(has_key ? -2 : -1)]
else
arguments[idx]
end
{
name: param_name,
class: value.class.name,
object_id: value.__id__,
value: display_string(value),
kind: param_type
}
end
mc.receiver = {
class: receiver.class.name,
object_id: receiver.__id__,
value: display_string(receiver)
}
mc.static = static
MethodEvent.build_from_invocation(mc, :call)
end
end
|