Class: AppMap::Event::MethodCall

Inherits:
MethodEvent show all
Defined in:
lib/appmap/event.rb

Direct Known Subclasses

Handler::Rails::SQLHandler::SQLCall

Defined Under Namespace

Classes: MethodMetadata

Constant Summary collapse

@@method_metadata =
{}

Constants inherited from MethodEvent

AppMap::Event::MethodEvent::MAX_ARRAY_ENUMERATION, AppMap::Event::MethodEvent::MAX_HASH_ENUMERATION, AppMap::Event::MethodEvent::MAX_STRING_LENGTH

Instance Attribute Summary collapse

Attributes inherited from MethodEventStruct

#event, #id, #thread_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MethodEvent

add_schema, add_size, best_class_name, custom_display_string, default_display_string, display_string, encode_display_string, #ready?

Instance Attribute Details

#defined_classObject

Returns the value of attribute defined_class.



166
167
168
# File 'lib/appmap/event.rb', line 166

def defined_class
  @defined_class
end

#linenoObject

Returns the value of attribute lineno.



166
167
168
# File 'lib/appmap/event.rb', line 166

def lineno
  @lineno
end

#method_idObject

Returns the value of attribute method_id.



166
167
168
# File 'lib/appmap/event.rb', line 166

def method_id
  @method_id
end

#parametersObject

Returns the value of attribute parameters.



166
167
168
# File 'lib/appmap/event.rb', line 166

def parameters
  @parameters
end

#pathObject

Returns the value of attribute path.



166
167
168
# File 'lib/appmap/event.rb', line 166

def path
  @path
end

#receiverObject

Returns the value of attribute receiver.



166
167
168
# File 'lib/appmap/event.rb', line 166

def receiver
  @receiver
end

#staticObject Also known as: static?

Returns the value of attribute static.



166
167
168
# File 'lib/appmap/event.rb', line 166

def static
  @static
end

Class Method Details

.build_from_invocation(defined_class, method, receiver, arguments, parameters: method.parameters, event: MethodCall.new) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/appmap/event.rb', line 196

def build_from_invocation(defined_class, method, receiver, arguments, parameters: method.parameters, event: MethodCall.new)
  event ||= MethodCall.new
  defined_class ||= 'Class'

  event.tap do
     = (defined_class, method, receiver)

    event.defined_class = .defined_class
    event.method_id = .method_id
    event.path = .path
    event.lineno = .lineno
    event.static = .static

    # Check if the method has key parameters. If there are any they'll always be last.
    # If yes, then extract it from arguments.
    has_key = [[:dummy], *parameters].last.first.to_s.start_with?('key') && arguments[-1].is_a?(Hash)
    kwargs = has_key && arguments[-1].dup || {}

    event.parameters = 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: best_class_name(value),
        object_id: value.__id__,
        value: display_string(value),
        kind: param_type
      }.tap do |param|
        add_size param, value
      end
    end
    event.receiver = {
      class: best_class_name(receiver),
      object_id: receiver.__id__,
      value: display_string(receiver)
    }

    MethodEvent.build_from_invocation(:call, event: event)
  end
end

Instance Method Details

#to_hObject



248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/appmap/event.rb', line 248

def to_h
  super.tap do |h|
    h[:defined_class] = defined_class
    h[:method_id] = method_id
    h[:path] = path
    h[:lineno] = lineno
    h[:static] = static
    h[:parameters] = parameters
    h[:receiver] = receiver
    h.delete_if { |_, v| v.nil? }
  end
end