Class: DEBUGGER__::ObjectTracer

Inherits:
Tracer show all
Defined in:
lib/debug/tracer.rb

Instance Attribute Summary

Attributes inherited from Tracer

#key, #type

Instance Method Summary collapse

Methods inherited from Tracer

#colorize, #disable, #enable, #enabled?, #header, #minfo, #out, #skip?, #skip_with_pattern?, #to_s

Methods included from Color

#color_pp, #colored_inspect, #colorize, #colorize_blue, #colorize_code, #colorize_cyan, #colorize_dim, #colorize_magenta, #irb_colorize, #with_inspection_error_guard

Methods included from SkipPathHelper

#skip_config_skip_path?, #skip_internal_path?, #skip_location?, #skip_path?

Constructor Details

#initialize(ui, obj_id, obj_inspect, **kw) ⇒ ObjectTracer

Returns a new instance of ObjectTracer.



169
170
171
172
173
174
# File 'lib/debug/tracer.rb', line 169

def initialize ui, obj_id, obj_inspect, **kw
  @obj_id = obj_id
  @obj_inspect = obj_inspect
  super(ui, **kw)
  @key = [@type, @obj_id, @pattern, @into].freeze
end

Instance Method Details

#colorized_obj_inspectObject



180
181
182
# File 'lib/debug/tracer.rb', line 180

def colorized_obj_inspect
  colorize_magenta(@obj_inspect)
end

#descriptionObject



176
177
178
# File 'lib/debug/tracer.rb', line 176

def description
  " for #{@obj_inspect}"
end

#setupObject



184
185
186
187
188
189
190
191
192
193
194
195
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
# File 'lib/debug/tracer.rb', line 184

def setup
  @tracer = TracePoint.new(:a_call){|tp|
    next if skip?(tp)

    if M_OBJECT_ID.bind_call(tp.self) == @obj_id
      klass = tp.defined_class
      method = tp.method_id
      method_info =
        if klass.singleton_class?
          if tp.self.is_a?(Class)
            ".#{method} (#{klass}.#{method})"
          else
            ".#{method}"
          end
        else
          "##{method} (#{klass}##{method})"
        end

      out tp, " #{colorized_obj_inspect} receives #{colorize_blue(method_info)}"
    elsif !tp.parameters.empty?
      b = tp.binding
      method_info = colorize_blue(minfo(tp))

      tp.parameters.each{|type, name|
        next unless name

        colorized_name = colorize_cyan(name)

        case type
        when :req, :opt, :key, :keyreq
          if b.local_variable_get(name).object_id == @obj_id
            out tp, " #{colorized_obj_inspect} is used as a parameter #{colorized_name} of #{method_info}"
          end
        when :rest
          next if name == :"*"

          ary = b.local_variable_get(name)
          ary.each{|e|
            if e.object_id == @obj_id
              out tp, " #{colorized_obj_inspect} is used as a parameter in #{colorized_name} of #{method_info}"
            end
          }
        when :keyrest
          next if name == :'**'
          h = b.local_variable_get(name)
          h.each{|k, e|
            if e.object_id == @obj_id
              out tp, " #{colorized_obj_inspect} is used as a parameter in #{colorized_name} of #{method_info}"
            end
          }
        end
      }
    end
  }
end