puppy 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/Gemfile +5 -0
- data/LICENSE +28 -0
- data/README.md +77 -0
- data/Rakefile +3 -0
- data/lib/puppy.rb +111 -0
- data/puppy.gemspec +22 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjZlMjdlODQzNjlmYmNhMmU3ZTg3N2QyNzZlY2NhOWJkNjAxYWNjZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGIwOWVhYmIzMjFlMGYxODc3Njg2NTMyMzBlOWFlMTAxZTQzNTZjOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzkwYTUxZTI0NTg3ZGZiOTBlMDhkMTVkMTVkNzBkMzg3YzgzOWY2OTM5MWMy
|
10
|
+
ZTNjMDQ1YWUzNjdkNDNkN2EyZTAyZDVmZTNkZTY2NDQ2Mzg0ODVkMDViZTZi
|
11
|
+
NzVkMTY1N2QyYWJhN2I0MTZkOTMxODBlOWViZTc0M2MxYWY0MTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjZhMzNkZjYxYzQ2OWE3YzcyM2IzOTRhZTNiZDRlNmM0MTcyMTA4NmU4ZjQz
|
14
|
+
MTA1ODI2NGEzNzIzZjA3OGQwNTE3NjNmNDZkYTVkODE5NGQ4YTdkYWE0NDBi
|
15
|
+
ZGRkY2NjNzQyMzcwZGExODUwOTU4Yjk3YWM3NGI0NzYxZmE5NTY=
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Software License Agreement (BSD License)
|
2
|
+
|
3
|
+
Copyright (c) 2013, Simone Margaritelli <http://www.evilsocket.net/>
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
* Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
* Neither the name of Puppy nor the names of its contributors may be used
|
15
|
+
to endorse or promote products derived from this software without
|
16
|
+
specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
21
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
22
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
23
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
Puppy
|
2
|
+
========================
|
3
|
+
|
4
|
+
Puppy is a tiny gem which will help you to perform easy object tracing and debugging.
|
5
|
+
It simply defines a *trace* instance method on the Object class, once this method is invoked on an object of any kind,
|
6
|
+
Puppy will start following and tracing like there's no tomorrow! :D
|
7
|
+
|
8
|
+
Methods
|
9
|
+
------------------------
|
10
|
+
|
11
|
+
Basically the only method that you are going to use is *trace* defined on every Object derived class, which can be invoked with
|
12
|
+
a set of options and with an optional code block to perform conditional tracing, original object instance, method and arguments
|
13
|
+
list are passed to the code block.
|
14
|
+
|
15
|
+
Options are:
|
16
|
+
|
17
|
+
- :as - how to represent the instance as string, if a Symbol is given it will be invoked as a method, otherwise as a string. Default: :class
|
18
|
+
- :caller - a boolean to enable or disable printing caller data. Default: true
|
19
|
+
- :step - if true stop the execution on each method invoked and wait for the user to press a key. Default: false
|
20
|
+
- :indent - if true method invocations will be indented as their nesting goes deeper. Default: true
|
21
|
+
- :stream - the stream to use to print the report while tracing the object, must overload the << operator. Default: STDERR
|
22
|
+
|
23
|
+
Examples
|
24
|
+
------------------------
|
25
|
+
|
26
|
+
Basic usage.
|
27
|
+
|
28
|
+
foo = 1.trace
|
29
|
+
puts foo
|
30
|
+
|
31
|
+
Output:
|
32
|
+
|
33
|
+
# Fixnum.to_ary() [puppy.rb:71:in `puts']
|
34
|
+
# Fixnum.respond_to?(:to_ary) [puppy.rb:71:in `puts']
|
35
|
+
# Fixnum.to_s() [puppy.rb:71:in `puts']
|
36
|
+
1
|
37
|
+
|
38
|
+
Follow the object without reporting the caller and represent it using its variable name instead of its class.
|
39
|
+
|
40
|
+
bar = "something".trace :as => 'bar', :caller => false
|
41
|
+
puts bar
|
42
|
+
|
43
|
+
Output:
|
44
|
+
|
45
|
+
# bar.to_ary()
|
46
|
+
# bar.respond_to?(:to_ary)
|
47
|
+
# bar.to_s()
|
48
|
+
something
|
49
|
+
|
50
|
+
Use a block to conditionally trace only when arguments list is filled with something.
|
51
|
+
|
52
|
+
count = 3.trace { |object,method,*args| args.size > 0 }
|
53
|
+
puts count.size # this won't be traced
|
54
|
+
puts count.to_s(2) # this will
|
55
|
+
|
56
|
+
Installation and Usage
|
57
|
+
------------------------
|
58
|
+
|
59
|
+
You can verify your installation using this piece of code:
|
60
|
+
|
61
|
+
gem install puppy
|
62
|
+
|
63
|
+
And
|
64
|
+
|
65
|
+
require 'puppy'
|
66
|
+
1.respond_to? :trace
|
67
|
+
|
68
|
+
License
|
69
|
+
------------------------
|
70
|
+
|
71
|
+
Released under the BSD license.
|
72
|
+
Copyright © 2013, Simone Margaritelli
|
73
|
+
|
74
|
+
<http://www.evilsocket.net/>
|
75
|
+
All rights reserved.
|
76
|
+
|
77
|
+
|
data/Rakefile
ADDED
data/lib/puppy.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# This is where the magic happens, open the Object class and define
|
2
|
+
# the new #trace instance method for every object instances.
|
3
|
+
class Object
|
4
|
+
# Starts tracing the object instance and prints every call to
|
5
|
+
# its instance methods with given arguments.
|
6
|
+
# Can be invoked with a code block to perform conditional tracing,
|
7
|
+
# original object instance, method and arguments list are passed
|
8
|
+
# to the code block.
|
9
|
+
#
|
10
|
+
# ==== Important Note:
|
11
|
+
# If you assign the traced variable to another object which is
|
12
|
+
# not traced, you will lose the ability to trace the new instance
|
13
|
+
# unless you call the #trace method explicitly.
|
14
|
+
#
|
15
|
+
# ==== Examples:
|
16
|
+
#
|
17
|
+
# # The following will print:
|
18
|
+
# # Fixnum.to_ary() [puppy.rb:71:in `puts']
|
19
|
+
# # Fixnum.respond_to?(:to_ary) [puppy.rb:71:in `puts']
|
20
|
+
# # Fixnum.to_s() [puppy.rb:71:in `puts']
|
21
|
+
# # 1
|
22
|
+
# foo = 1.trace
|
23
|
+
# puts foo
|
24
|
+
#
|
25
|
+
# # Trace the object without reporting the caller and represent
|
26
|
+
# # it using its variable name instead of its #class, will print:
|
27
|
+
# # # bar.to_ary()
|
28
|
+
# # # bar.respond_to?(:to_ary)
|
29
|
+
# # # bar.to_s()
|
30
|
+
# # something
|
31
|
+
# bar = "something".trace :as => 'bar', :caller => false
|
32
|
+
# puts bar
|
33
|
+
#
|
34
|
+
# # Trace only when arguments list is filled with something.
|
35
|
+
# count = 3.trace { |object,method,*args| args.size > 0 }
|
36
|
+
# puts count.size # this won't be traced
|
37
|
+
# puts count.to_s(2) # this will
|
38
|
+
#
|
39
|
+
# ==== Options:
|
40
|
+
#
|
41
|
+
# - :as - how to represent the instance as string, if a Symbol is given it will be invoked as a method, otherwise as a string. Default: :class
|
42
|
+
# - :caller - a boolean to enable or disable printing caller data. Default: true
|
43
|
+
# - :step - if true stop the execution on each method invoked and wait for the user to press a key. Default: false
|
44
|
+
# - :indent - if true method invocations will be indented as their nesting goes deeper. Default: true
|
45
|
+
# - :stream - the stream to use to print the report while tracing the object, must overload the << operator. Default: STDERR
|
46
|
+
def trace( options = {}, &block )
|
47
|
+
Puppy::TracedObject.new( self, options, &block )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Puppy #:nodoc:
|
52
|
+
# This is the class which encapsulates every object instances once
|
53
|
+
# the Object#trace method is invoked.
|
54
|
+
class TracedObject
|
55
|
+
# Undefine every instance method to use the #method_missing trick.
|
56
|
+
instance_methods.each do |m|
|
57
|
+
undef_method m unless m == :object_id || m == :__id__ || m == :__send__
|
58
|
+
end
|
59
|
+
|
60
|
+
DEFAULTS = {
|
61
|
+
:as => :class,
|
62
|
+
:caller => true,
|
63
|
+
:step => false,
|
64
|
+
:indent => true,
|
65
|
+
:stream => STDERR
|
66
|
+
}
|
67
|
+
|
68
|
+
#:nodoc:
|
69
|
+
def initialize( obj, opts = {}, &block )
|
70
|
+
@object, @opts, @block = obj, DEFAULTS.merge(opts), block
|
71
|
+
@stream = @opts[:stream]
|
72
|
+
end
|
73
|
+
|
74
|
+
#:nodoc: We need this to directly use #inspect on the traced object
|
75
|
+
# without the invocation being traced itself.
|
76
|
+
def inspect
|
77
|
+
@object.send :inspect
|
78
|
+
end
|
79
|
+
|
80
|
+
#:nodoc: Here it goes, trace it baby!
|
81
|
+
def method_missing( m, *args )
|
82
|
+
begin
|
83
|
+
if @block == nil || @block.call( @object, m, *args ) == true
|
84
|
+
@stream << '# '
|
85
|
+
|
86
|
+
@stream << ' ' * caller.size unless !@opts[:indent]
|
87
|
+
|
88
|
+
as = @opts[:as]
|
89
|
+
|
90
|
+
@stream << if as.is_a? Symbol
|
91
|
+
@object.send as
|
92
|
+
elsif as != nil
|
93
|
+
as.to_s
|
94
|
+
elsif
|
95
|
+
@object.to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
@stream << ".#{m}(#{args.map { |a| a.inspect }.join(', ')})"
|
99
|
+
@stream << " [#{caller[0]}] " unless @opts[:caller] == false
|
100
|
+
@stream << "\n"
|
101
|
+
|
102
|
+
gets unless !@opts[:step]
|
103
|
+
end
|
104
|
+
|
105
|
+
@object.send m, *args
|
106
|
+
rescue Exception => e
|
107
|
+
raise
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/puppy.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{puppy}
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.license = "BSD"
|
5
|
+
|
6
|
+
s.authors = ["Simone Margaritelli"]
|
7
|
+
s.description = %q{Puppy is a tiny gem to perform easy object tracing and debugging.}
|
8
|
+
s.email = %q{evilsocket@gmail.com}
|
9
|
+
s.files = Dir.glob("lib/**/*") + [
|
10
|
+
"LICENSE",
|
11
|
+
"README.md",
|
12
|
+
"Rakefile",
|
13
|
+
"Gemfile",
|
14
|
+
"puppy.gemspec"
|
15
|
+
]
|
16
|
+
s.homepage = %q{http://github.com/evilsocket/puppy}
|
17
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.summary = %q{Puppy is a tiny gem to perform easy object tracing and debugging.}
|
20
|
+
end
|
21
|
+
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simone Margaritelli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Puppy is a tiny gem to perform easy object tracing and debugging.
|
14
|
+
email: evilsocket@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/puppy.rb
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- Gemfile
|
24
|
+
- puppy.gemspec
|
25
|
+
homepage: http://github.com/evilsocket/puppy
|
26
|
+
licenses:
|
27
|
+
- BSD
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options:
|
31
|
+
- --charset=UTF-8
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.0.6
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Puppy is a tiny gem to perform easy object tracing and debugging.
|
50
|
+
test_files: []
|