wanderer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/example/AR_new.png +0 -0
- data/example/demo.png +0 -0
- data/example/demo.rb +29 -0
- data/lib/wanderer.rb +34 -1
- data/lib/wanderer/version.rb +1 -1
- data/wanderer.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 799cc038da9d1f8815b28b24c75bc82d814b7a52
|
4
|
+
data.tar.gz: 40127b67e1ef5b93cd738c82c6a9934d1edb526b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 806b7f26ac35c0abfe398daf3a67bce09459d1686ebd0a545f165c1505422f1c56701822e718ddd1d1b7a3dc3288fd6780cb6ca7f66f2815b99edabe92950f28
|
7
|
+
data.tar.gz: 09227bb041f2888f6f48fa0f089c0ff276bb75deb2cab90331609d517bf989eb17c7cd4683a93104d14305d69c182987992cf1ec1d05b20a535487ca446215f8
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Wanderer
|
2
2
|
|
3
|
-
|
3
|
+
Ruby method look-up chain visualization
|
4
|
+
|
5
|
+
For example:
|
6
|
+
* How method look-up work when we call `new` method on an instance of
|
7
|
+
`ActiveRecord`(like `User`)?
|
8
|
+
|
9
|
+
![How ActiveRecard look up new method on User model](https://github.com/ipmsteven/wanderer/blob/master/example/AR_new.png)
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
data/example/AR_new.png
ADDED
Binary file
|
data/example/demo.png
ADDED
Binary file
|
data/example/demo.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'wanderer'
|
2
|
+
|
3
|
+
class Animal
|
4
|
+
def initialize(name)
|
5
|
+
@name = name
|
6
|
+
end
|
7
|
+
|
8
|
+
def info
|
9
|
+
puts "I'm a #{self.class}."
|
10
|
+
puts "My name is '#{@name}'."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Dog < Animal
|
15
|
+
def info
|
16
|
+
puts "I #{make_noise}."
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def make_noise
|
21
|
+
'bark "Woof woof"'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
lassie = Dog.new "Lassie"
|
26
|
+
|
27
|
+
routes = Wanderer.walk(lassie, :info)
|
28
|
+
|
29
|
+
puts routes.join("\n")
|
data/lib/wanderer.rb
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
require "wanderer/version"
|
2
|
+
require 'graphviz'
|
2
3
|
|
3
4
|
module Wanderer
|
4
|
-
|
5
|
+
|
6
|
+
def self.walk(receiver, look_up_method)
|
7
|
+
visited = search(receiver, look_up_method)
|
8
|
+
|
9
|
+
g = GraphViz.new( :G, :type => :digraph )
|
10
|
+
|
11
|
+
visited[0...-1].each_with_index do |item, index|
|
12
|
+
a = g.add_nodes(item.to_s)
|
13
|
+
b = g.add_nodes(visited[index+1].to_s)
|
14
|
+
g.add_edges(a, b)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Generate output image
|
18
|
+
g.output( :png => "chain.png" )
|
19
|
+
visited
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.search(receiver, look_up_method)
|
23
|
+
visited = []
|
24
|
+
ancestors = receiver.singleton_class.ancestors
|
25
|
+
|
26
|
+
ancestors.each do |ancestor|
|
27
|
+
visited << ancestor
|
28
|
+
return visited if ancestor.instance_methods(false).include?(look_up_method.to_sym)
|
29
|
+
end
|
30
|
+
|
31
|
+
visited << "method_missing"
|
32
|
+
|
33
|
+
ancestors.each do |ancestor|
|
34
|
+
visited << ancestor
|
35
|
+
return visited if ancestor.instance_methods(false).include? :method_missing
|
36
|
+
end
|
37
|
+
end
|
5
38
|
end
|
data/lib/wanderer/version.rb
CHANGED
data/wanderer.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "ruby-graphviz", "~> 1.2.1"
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
24
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wanderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yunlei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-graphviz
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,6 +64,9 @@ files:
|
|
50
64
|
- LICENSE.txt
|
51
65
|
- README.md
|
52
66
|
- Rakefile
|
67
|
+
- example/AR_new.png
|
68
|
+
- example/demo.png
|
69
|
+
- example/demo.rb
|
53
70
|
- lib/wanderer.rb
|
54
71
|
- lib/wanderer/version.rb
|
55
72
|
- wanderer.gemspec
|