lib/puppy.rb in puppy-1.0.0 vs lib/puppy.rb in puppy-1.0.1
- old
+ new
@@ -46,11 +46,11 @@
def trace( options = {}, &block )
Puppy::TracedObject.new( self, options, &block )
end
end
-module Puppy #:nodoc:
+module Puppy
# This is the class which encapsulates every object instances once
# the Object#trace method is invoked.
class TracedObject
# Undefine every instance method to use the #method_missing trick.
instance_methods.each do |m|
@@ -63,25 +63,33 @@
:step => false,
:indent => true,
:stream => STDERR
}
- #:nodoc:
def initialize( obj, opts = {}, &block )
+ @is_puppy_traced = true
@object, @opts, @block = obj, DEFAULTS.merge(opts), block
@stream = @opts[:stream]
end
- #:nodoc: We need this to directly use #inspect on the traced object
+ # We need this to directly use #inspect on the traced object
# without the invocation being traced itself.
def inspect
@object.send :inspect
end
- #:nodoc: Here it goes, trace it baby!
+ def trace
+ @is_puppy_traced = true
+ end
+
+ def untrace
+ @is_puppy_traced = false
+ end
+
+ # Here it goes, trace it baby!
def method_missing( m, *args )
begin
- if @block == nil || @block.call( @object, m, *args ) == true
+ if ( @block == nil || @block.call( @object, m, *args ) == true ) && @is_puppy_traced == true
@stream << '# '
@stream << ' ' * caller.size unless !@opts[:indent]
as = @opts[:as]