ograph 0.0.1
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.
- data/History.txt +4 -0
- data/Manifest.txt +5 -0
- data/README.txt +56 -0
- data/Rakefile +14 -0
- data/lib/ograph.rb +72 -0
- metadata +58 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= ObjectGraph
|
2
|
+
|
3
|
+
http://rubyforge.org/projects/seattlerb
|
4
|
+
http://seattlerb.rubyforge.org/
|
5
|
+
|
6
|
+
== DESCRIPTION
|
7
|
+
|
8
|
+
ObjectGraph will output Graphviz dot files of your objects in memory. It will
|
9
|
+
ferret out your instance variables and enumerate over your enumerables to
|
10
|
+
give you a graph of your object and its relationships.
|
11
|
+
|
12
|
+
For sample output and more sample code see:
|
13
|
+
|
14
|
+
* http://flickr.com/photos/aaronp/tags/graphviz/
|
15
|
+
* http://tenderlovemaking.com/2007/01/13/graphing-objects-in-memory-with-ruby/
|
16
|
+
|
17
|
+
== PROBLEMS
|
18
|
+
|
19
|
+
The output graph kind of lies when displaying Hashes. A Hash will point to
|
20
|
+
an Array with a key and value. If the hash contains 7 pairs, it will point
|
21
|
+
to 7 Arrays.
|
22
|
+
|
23
|
+
== SYNOPSYS
|
24
|
+
|
25
|
+
list = %w{ hello world how are you? }
|
26
|
+
hash = { :list => list, :string => "tenderlovemaking.com" }
|
27
|
+
puts ObjectGraph.graph(hash)
|
28
|
+
|
29
|
+
== INSTALL
|
30
|
+
|
31
|
+
* sudo gem install ograph
|
32
|
+
|
33
|
+
== LICENSE
|
34
|
+
|
35
|
+
(The MIT License)
|
36
|
+
|
37
|
+
Copyright (c) 2007 Aaron Patterson, Seattle.rb
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
'Software'), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
54
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
55
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
56
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
require './lib/ograph.rb'
|
4
|
+
|
5
|
+
Hoe.new('ograph', ObjectGraph::VERSION) do |p|
|
6
|
+
p.rubyforge_name = 'ograph'
|
7
|
+
p.author = 'Aaron Patterson'
|
8
|
+
p.email = 'aaronp@rubyforge.org'
|
9
|
+
p.summary = p.paragraphs_of('README.txt', 3).join("\n\n")
|
10
|
+
p.description = p.paragraphs_of('README.txt', 3..5).join("\n\n")
|
11
|
+
p.url = p.paragraphs_of('README.txt', 1).first.split(/\n/)[1..-1].first.strip
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
end
|
14
|
+
|
data/lib/ograph.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
class ObjectGraph
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
|
4
|
+
def self.graph(target, opts = {})
|
5
|
+
opts = { :class_filter => /./,
|
6
|
+
:show_ivars => true,
|
7
|
+
:show_nil => true,
|
8
|
+
}.merge(opts)
|
9
|
+
|
10
|
+
stack = [target]
|
11
|
+
object_links = []
|
12
|
+
seen_objects = []
|
13
|
+
seen_hash = {}
|
14
|
+
|
15
|
+
while stack.length > 0
|
16
|
+
object = stack.pop
|
17
|
+
next if seen_hash.key? object.object_id
|
18
|
+
seen_hash[object.object_id] = 1
|
19
|
+
|
20
|
+
if object.is_a?(Enumerable) && ! object.is_a?(String)
|
21
|
+
object.each { |iv|
|
22
|
+
next if iv.nil? && ! opts[:show_nil]
|
23
|
+
if iv.class.to_s =~ opts[:class_filter] || object.is_a?(Enumerable)
|
24
|
+
object_links.push([object.object_id, iv.object_id, nil])
|
25
|
+
stack.push(iv)
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
ivars = object.instance_variables.sort
|
31
|
+
ivars.each_with_index do |iv_sym, i|
|
32
|
+
iv = object.instance_variable_get iv_sym
|
33
|
+
next if iv.nil? && ! opts[:show_nil]
|
34
|
+
if iv.class.to_s =~ opts[:class_filter] || iv.is_a?(Enumerable)
|
35
|
+
object_links.push([ object.object_id,
|
36
|
+
iv.object_id,
|
37
|
+
opts[:show_ivars] ? i : nil])
|
38
|
+
stack.push(iv)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
seen_objects.push([ object.object_id,
|
43
|
+
object.class ] + (opts[:show_ivars] ? ivars : []))
|
44
|
+
end
|
45
|
+
|
46
|
+
s = <<END
|
47
|
+
digraph g {
|
48
|
+
graph [ rankdir = "LR" ];
|
49
|
+
node [ fontsize = "8"
|
50
|
+
shape = "ellipse"
|
51
|
+
];
|
52
|
+
edge [ ];
|
53
|
+
END
|
54
|
+
seen_objects.each { |id, *rest|
|
55
|
+
s += "\"#{id}\" [\nlabel="
|
56
|
+
list = []
|
57
|
+
[id, *rest].each_with_index { |field, i|
|
58
|
+
list << "<f#{i}>#{field}"
|
59
|
+
}
|
60
|
+
s += "\"#{list.join('|')}\"\n"
|
61
|
+
s += <<END
|
62
|
+
shape = "record"
|
63
|
+
]
|
64
|
+
END
|
65
|
+
}
|
66
|
+
object_links.each_with_index { |(from, to, x), i|
|
67
|
+
s += "\"#{from}\":f#{x ? x + 2 : 0} -> \"#{to}\":f0 [ id = #{i} ]\n"
|
68
|
+
}
|
69
|
+
s += "}\n"
|
70
|
+
s
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: ograph
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-01-20 00:00:00 -08:00
|
8
|
+
summary: ObjectGraph will output Graphviz dot files of your objects in memory. It will ferret out your instance variables and enumerate over your enumerables to give you a graph of your object and its relationships.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: aaronp@rubyforge.org
|
12
|
+
homepage: http://seattlerb.rubyforge.org/
|
13
|
+
rubyforge_project: ograph
|
14
|
+
description: "ObjectGraph will output Graphviz dot files of your objects in memory. It will
|
15
|
+
ferret out your instance variables and enumerate over your enumerables to give
|
16
|
+
you a graph of your object and its relationships. For sample output and more
|
17
|
+
sample code see: * http://flickr.com/photos/aaronp/tags/graphviz/ *
|
18
|
+
http://tenderlovemaking.com/2007/01/13/graphing-objects-in-memory-with-ruby/"
|
19
|
+
autorequire:
|
20
|
+
default_executable:
|
21
|
+
bindir: bin
|
22
|
+
has_rdoc: true
|
23
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
24
|
+
requirements:
|
25
|
+
-
|
26
|
+
- ">"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.0.0
|
29
|
+
version:
|
30
|
+
platform: ruby
|
31
|
+
signing_key:
|
32
|
+
cert_chain:
|
33
|
+
post_install_message:
|
34
|
+
authors:
|
35
|
+
- Aaron Patterson
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- lib/ograph.rb
|
42
|
+
test_files: []
|
43
|
+
rdoc_options: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
requirements: []
|
48
|
+
dependencies:
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: hoe
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
53
|
+
requirements:
|
54
|
+
-
|
55
|
+
- ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.1.6
|
58
|
+
version:
|