Class: AppMap::Event::MethodCall

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

Direct Known Subclasses

Rails::SQLHandler::SQLCall

Constant Summary

Constants inherited from MethodEvent

AppMap::Event::MethodEvent::LIMIT

Instance Attribute Summary collapse

Attributes inherited from MethodEventStruct

#event, #id, #thread_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MethodEvent

display_string, object_properties

Instance Attribute Details

#defined_classObject

Returns the value of attribute defined_class.



103
104
105
# File 'lib/appmap/event.rb', line 103

def defined_class
  @defined_class
end

#linenoObject

Returns the value of attribute lineno.



103
104
105
# File 'lib/appmap/event.rb', line 103

def lineno
  @lineno
end

#method_idObject

Returns the value of attribute method_id.



103
104
105
# File 'lib/appmap/event.rb', line 103

def method_id
  @method_id
end

#parametersObject

Returns the value of attribute parameters.



103
104
105
# File 'lib/appmap/event.rb', line 103

def parameters
  @parameters
end

#pathObject

Returns the value of attribute path.



103
104
105
# File 'lib/appmap/event.rb', line 103

def path
  @path
end

#receiverObject

Returns the value of attribute receiver.



103
104
105
# File 'lib/appmap/event.rb', line 103

def receiver
  @receiver
end

#staticObject Also known as: static?

Returns the value of attribute static.



103
104
105
# File 'lib/appmap/event.rb', line 103

def static
  @static
end

Class Method Details

.build_from_invocation(mc = MethodCall.new, defined_class, method, receiver, arguments) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/appmap/event.rb', line 106

def build_from_invocation(mc = MethodCall.new, defined_class, method, receiver, arguments)
  defined_class ||= 'Class'
  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

    # 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], *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: best_class_name(value),
        object_id: value.__id__,
        value: display_string(value),
        kind: param_type
      }
    end
    mc.receiver = {
      class: best_class_name(receiver),
      object_id: receiver.__id__,
      value: display_string(receiver)
    }
    mc.static = static
    MethodEvent.build_from_invocation(mc, :call)
  end
end

Instance Method Details

#to_hObject



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/appmap/event.rb', line 158

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