module Rubylog::Tracing

Attributes

trace_levels[RW]
traceable_methods[R]

Public Instance Methods

trace(value=true) { || ... } click to toggle source

Turns trace on. If value is given and is false, turns trace off. If a block is given, calls the block with trace on.

# File lib/rubylog/tracing.rb, line 15
def trace value=true
  if not block_given?
    @trace = value
    @trace_levels = 0
    update_trace
  else
    begin
      trace
      return yield
    ensure
      trace false
    end
  end
end
trace?() click to toggle source

returns true if tracing is active

# File lib/rubylog/tracing.rb, line 31
def trace?
  @trace
end
traceable(method) click to toggle source
# File lib/rubylog/tracing.rb, line 36
def traceable method
  @traceable_methods ||= []
  @traceable_methods << method
end

Private Instance Methods

update_trace() click to toggle source
# File lib/rubylog/tracing.rb, line 43
def update_trace
  if trace?
    traceable_methods.each do |m|
      m.owner.send :define_method, m.name do |*args,&block|
        begin
          print " "*Rubylog.trace_levels
          Rubylog.trace_levels += 1
          print "#{inspect}.#{m.name}(#{args.map{|k|k.inspect}.join(", ")})?"
          gets

          return m.bind(self).call *args, &block
        ensure
          Rubylog.trace_levels -= 1
          print " "*Rubylog.trace_levels
          print "*"
          puts
        end
      end
    end
  else
    traceable_methods.each do |m|
      m.owner.send :define_method, m.name do |*args, &block|
        m.bind(self).call(*args, &block)
      end
    end
  end

end