module RubySnooper

Constants

CLASS_NAME_PATTERN
VERSION

Public Instance Methods

snoop(*method_names) click to toggle source
# File lib/ruby_snooper.rb, line 9
def snoop(*method_names)
  prepend to_prepend(method_names)
end
snoop_class_methods(*method_names) click to toggle source
# File lib/ruby_snooper.rb, line 13
def snoop_class_methods(*method_names)
  Kernel.const_get(caller_locations.first.label.match(CLASS_NAME_PATTERN)[1])
        .singleton_class
        .prepend(to_prepend(method_names))
end

Private Instance Methods

to_prepend(method_names) click to toggle source
Calls superclass method
# File lib/ruby_snooper.rb, line 21
def to_prepend(method_names)
  caller_path = caller_locations[1].path
  Module.new do
    method_names.each do |method_name|
      define_method(method_name) do |*args, &block|
        trace_writer = TraceWriter.new(
          method_name,
          caller_path,
        )
        trace_writer.trace_point.enable
        super(*args,&block).tap do
          trace_writer.trace_point.disable
          trace_writer.print
        end
      end
    end
  end
end