visualize_ruby 0.5.0 → 0.6.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/lib/visualize_ruby/edge.rb +4 -2
- data/lib/visualize_ruby/graph.rb +1 -1
- data/lib/visualize_ruby/graphviz.rb +33 -17
- data/lib/visualize_ruby/node.rb +4 -0
- data/lib/visualize_ruby/parser/and.rb +1 -5
- data/lib/visualize_ruby/parser/ast_helper.rb +1 -0
- data/lib/visualize_ruby/parser/base.rb +19 -0
- data/lib/visualize_ruby/parser/begin.rb +1 -7
- data/lib/visualize_ruby/parser/block.rb +43 -0
- data/lib/visualize_ruby/parser/case.rb +1 -13
- data/lib/visualize_ruby/parser/if.rb +1 -13
- data/lib/visualize_ruby/parser/or.rb +3 -7
- data/lib/visualize_ruby/parser/send.rb +1 -5
- data/lib/visualize_ruby/parser/str.rb +1 -5
- data/lib/visualize_ruby/parser/type.rb +1 -5
- data/lib/visualize_ruby/parser.rb +2 -0
- data/lib/visualize_ruby/version.rb +1 -1
- data/visualize_ruby.gemspec +1 -1
- metadata +7 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99eee38b1b8d2b5fc815dc04c37b5fec84a73762b66295898bed31bee5ee235d
|
4
|
+
data.tar.gz: aa7d28887b07d5b4ae096b2341fc74e2906bbe7452effcb5f0a19db7ee42f2a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f552a2787de005e1459951380fb1d58e412e2901298a73c65a1a4b3d984eb2d1f28d7681b1e3ea62fec3d89131e6507263d644037b0e5037155f4492aa4bd1ad
|
7
|
+
data.tar.gz: 87539a36683428a0debda868deac2e9fc50c1f207ef4b64a9c87f7664482bb8929e5cdb5fbbfd2cea4cc8db8a0d1312e01e7739183bff415f833e15112b05f20
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 0.6.0 - 2018-06-27
|
5
|
+
### Enhancement
|
6
|
+
* Visualize Enumerable looping
|
7
|
+
* Display nodes for block arguments
|
8
|
+
|
4
9
|
## 0.5.0 - 2018-06-22
|
5
10
|
### Enhancement
|
6
11
|
* Change some visual display for flow charts.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -36,7 +36,7 @@ ruby_code = <<-RUBY
|
|
36
36
|
RUBY
|
37
37
|
|
38
38
|
results = VisualizeRuby::Builder.new(ruby_code: ruby_code).build
|
39
|
-
VisualizeRuby::Graphviz.new(*results).to_graph(
|
39
|
+
VisualizeRuby::Graphviz.new(*results).to_graph(path: "example.png")
|
40
40
|
```
|
41
41
|
|
42
42
|
## Development
|
@@ -47,7 +47,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
47
47
|
|
48
48
|
## Contributing
|
49
49
|
|
50
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/zeisler/visualize_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
51
51
|
|
52
52
|
## License
|
53
53
|
|
@@ -55,4 +55,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
55
55
|
|
56
56
|
## Code of Conduct
|
57
57
|
|
58
|
-
Everyone interacting in the VisualizeRuby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
58
|
+
Everyone interacting in the VisualizeRuby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zeisler/visualize_ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/visualize_ruby/edge.rb
CHANGED
@@ -4,14 +4,16 @@ module VisualizeRuby
|
|
4
4
|
:node_a,
|
5
5
|
:node_b,
|
6
6
|
:dir,
|
7
|
-
:style
|
7
|
+
:style,
|
8
|
+
:color
|
8
9
|
|
9
|
-
def initialize(name: nil, nodes:, dir: :forward, style: :solid)
|
10
|
+
def initialize(name: nil, nodes:, dir: :forward, style: :solid, color: nil)
|
10
11
|
@name = name.to_s if name
|
11
12
|
@node_a = nodes[0]
|
12
13
|
@node_b = nodes[1]
|
13
14
|
@dir = dir
|
14
15
|
@style = style
|
16
|
+
@color = color
|
15
17
|
end
|
16
18
|
|
17
19
|
def to_a
|
data/lib/visualize_ruby/graph.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "graphviz"
|
2
2
|
|
3
3
|
module VisualizeRuby
|
4
4
|
class Graphviz
|
@@ -9,19 +9,34 @@ module VisualizeRuby
|
|
9
9
|
@label = label
|
10
10
|
end
|
11
11
|
|
12
|
-
def to_graph(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def to_graph(format: nil, path: nil)
|
13
|
+
build
|
14
|
+
if format == String
|
15
|
+
str = StringIO.new
|
16
|
+
main_graph.dump_graph(str)
|
17
|
+
str.string
|
18
|
+
else
|
19
|
+
::Graphviz.output(main_graph, path: path, format: format)
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
def
|
23
|
-
graphs.
|
24
|
-
|
25
|
+
def label
|
26
|
+
if graphs.count == 1
|
27
|
+
@label = graphs.first.name
|
28
|
+
else
|
29
|
+
@label
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def build
|
34
|
+
create_edges(sub_graphs)
|
35
|
+
end
|
36
|
+
|
37
|
+
def sub_graphs
|
38
|
+
@sub_graphs ||= graphs.reverse.map.with_index do |graph, index|
|
39
|
+
sub_graph = create_sub_graph(graph, index)
|
25
40
|
create_nodes(graph, sub_graph)
|
26
41
|
[graph, sub_graph]
|
27
42
|
end
|
@@ -34,18 +49,19 @@ module VisualizeRuby
|
|
34
49
|
def create_edges(sub_graphs)
|
35
50
|
sub_graphs.each do |r_graph, g_graph|
|
36
51
|
r_graph.edges.each do |edge|
|
37
|
-
|
52
|
+
::Graphviz::Edge.new(
|
53
|
+
g_graph,
|
38
54
|
nodes[edge.node_a.name],
|
39
55
|
nodes[edge.node_b.name],
|
40
|
-
**compact({ label: edge.name, dir: edge.dir, style: edge.style })
|
56
|
+
**compact({ label: edge.name, dir: edge.dir, style: edge.style, color: edge.color })
|
41
57
|
)
|
42
58
|
end
|
43
59
|
end
|
44
60
|
end
|
45
61
|
|
46
|
-
def create_sub_graph(
|
47
|
-
|
48
|
-
"
|
62
|
+
def create_sub_graph(graph, index)
|
63
|
+
main_graph.add_subgraph(
|
64
|
+
"cluster_#{index}",
|
49
65
|
**compact({ label: graph.name, style: graphs.count == 1 ? :invis : :dotted })
|
50
66
|
)
|
51
67
|
end
|
@@ -60,8 +76,8 @@ module VisualizeRuby
|
|
60
76
|
end
|
61
77
|
end
|
62
78
|
|
63
|
-
def main_graph
|
64
|
-
|
79
|
+
def main_graph
|
80
|
+
@main_graph ||= ::Graphviz::Graph.new(:G, compact(label: label))
|
65
81
|
end
|
66
82
|
|
67
83
|
def compact(hash)
|
data/lib/visualize_ruby/node.rb
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
module VisualizeRuby
|
2
2
|
class Parser
|
3
|
-
class Begin
|
4
|
-
def initialize(ast)
|
5
|
-
@ast = ast
|
6
|
-
end
|
7
|
-
|
3
|
+
class Begin < Base
|
8
4
|
# @return [Array<VisualizeRuby::Node>, Array<VisualizeRuby::Edge>]
|
9
5
|
def parse
|
10
|
-
edges = []
|
11
|
-
nodes = []
|
12
6
|
last_node = nil
|
13
7
|
@ast.children.to_a.compact.reverse.each do |a|
|
14
8
|
_nodes, _edges = Parser.new(ast: a).parse
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module VisualizeRuby
|
2
|
+
class Parser
|
3
|
+
class Block < Base
|
4
|
+
# @return [Array<VisualizeRuby::Node>, Array<VisualizeRuby::Edge>]
|
5
|
+
def parse
|
6
|
+
iterator, arguments, action = @ast.children
|
7
|
+
item = arguments.children[0]
|
8
|
+
collection, iterator_type = iterator.to_a
|
9
|
+
if enumerable?(collection) || enumerable?(iterator_type)
|
10
|
+
enumerable(action, collection, iterator_type, item)
|
11
|
+
else
|
12
|
+
yield_block(action, item, iterator)
|
13
|
+
end
|
14
|
+
return nodes, edges
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def yield_block(action, item, on_object)
|
20
|
+
nodes << on_object_node = Node.new(name: AstHelper.new(on_object).description)
|
21
|
+
nodes << item_node = Node.new(name: AstHelper.new(item).description, type: :argument)
|
22
|
+
nodes << action_node = Node.new(name: AstHelper.new(action).description)
|
23
|
+
edges << Edge.new(nodes: [on_object_node, item_node])
|
24
|
+
edges << Edge.new(nodes: [item_node, action_node], color: "orange")
|
25
|
+
end
|
26
|
+
|
27
|
+
def enumerable(action, collection, iterator_type, item)
|
28
|
+
nodes << collection_node = Node.new(name: AstHelper.new(collection).description)
|
29
|
+
nodes << item_node = Node.new(name: AstHelper.new(item).description, type: :argument)
|
30
|
+
nodes << iterator_node = Node.new(name: iterator_type)
|
31
|
+
nodes << action_node = Node.new(name: AstHelper.new(action).description)
|
32
|
+
edges << Edge.new(nodes: [collection_node, iterator_node])
|
33
|
+
edges << Edge.new(nodes: [iterator_node, item_node], color: "blue")
|
34
|
+
edges << Edge.new(nodes: [item_node, action_node], color: "blue")
|
35
|
+
edges << Edge.new(nodes: [action_node, iterator_node], color: "blue", name: "↺")
|
36
|
+
end
|
37
|
+
|
38
|
+
def enumerable?(meth)
|
39
|
+
meth == :each || Enumerable.instance_methods.include?(meth)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module VisualizeRuby
|
2
2
|
class Parser
|
3
|
-
class Case
|
4
|
-
def initialize(ast)
|
5
|
-
@ast = ast
|
6
|
-
end
|
7
|
-
|
3
|
+
class Case < Base
|
8
4
|
# @return [Array<VisualizeRuby::Node>, Array<VisualizeRuby::Edge>]
|
9
5
|
def parse
|
10
6
|
condition, *_whens, _else = @ast.children
|
@@ -23,14 +19,6 @@ module VisualizeRuby
|
|
23
19
|
edges << _else_edge
|
24
20
|
return nodes, edges
|
25
21
|
end
|
26
|
-
|
27
|
-
def nodes
|
28
|
-
@nodes ||= []
|
29
|
-
end
|
30
|
-
|
31
|
-
def edges
|
32
|
-
@edges ||= []
|
33
|
-
end
|
34
22
|
end
|
35
23
|
end
|
36
24
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module VisualizeRuby
|
2
2
|
class Parser
|
3
|
-
class If
|
4
|
-
def initialize(ast)
|
5
|
-
@ast = ast
|
6
|
-
end
|
7
|
-
|
3
|
+
class If < Base
|
8
4
|
# @return [Array<VisualizeRuby::Node>, Array<VisualizeRuby::Edge>]
|
9
5
|
def parse
|
10
6
|
break_ast
|
@@ -44,14 +40,6 @@ module VisualizeRuby
|
|
44
40
|
def break_ast
|
45
41
|
@condition, @on_true, @on_false = @ast.children.to_a
|
46
42
|
end
|
47
|
-
|
48
|
-
def nodes
|
49
|
-
@nodes ||= []
|
50
|
-
end
|
51
|
-
|
52
|
-
def edges
|
53
|
-
@edges ||= []
|
54
|
-
end
|
55
43
|
end
|
56
44
|
end
|
57
45
|
end
|
@@ -1,19 +1,15 @@
|
|
1
1
|
module VisualizeRuby
|
2
2
|
class Parser
|
3
|
-
class Or
|
4
|
-
def initialize(ast)
|
5
|
-
@ast = ast
|
6
|
-
end
|
3
|
+
class Or < Base
|
7
4
|
|
8
5
|
# @return [Array<VisualizeRuby::Node>, Array<VisualizeRuby::Edge>]
|
9
6
|
def parse
|
10
7
|
last_node = nil
|
11
|
-
|
12
|
-
nodes = @ast.children.reverse.map do |c|
|
8
|
+
@ast.children.reverse.map do |c|
|
13
9
|
node = Node.new(name: AstHelper.new(c).description, type: :decision)
|
14
10
|
edges << Edge.new(name: "OR", nodes: [node, last_node]) if last_node
|
15
11
|
last_node = node
|
16
|
-
node
|
12
|
+
nodes << node
|
17
13
|
end.reverse
|
18
14
|
return nodes, edges
|
19
15
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module VisualizeRuby
|
2
2
|
class Parser
|
3
|
-
class Send
|
4
|
-
def initialize(ast)
|
5
|
-
@ast = ast
|
6
|
-
end
|
7
|
-
|
3
|
+
class Send < Base
|
8
4
|
# @return [Array<VisualizeRuby::Node>, Array<VisualizeRuby::Edge>]
|
9
5
|
def parse
|
10
6
|
return [Node.new(name: AstHelper.new(@ast).description, type: :action)], []
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module VisualizeRuby
|
2
2
|
class Parser
|
3
|
-
class Str
|
4
|
-
def initialize(ast)
|
5
|
-
@ast = ast
|
6
|
-
end
|
7
|
-
|
3
|
+
class Str < Base
|
8
4
|
# @return [Array<VisualizeRuby::Node>, Array<VisualizeRuby::Edge>]
|
9
5
|
def parse
|
10
6
|
return [Node.new(name: AstHelper.new(@ast).description, type: :action)], []
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "parser/current"
|
2
|
+
require_relative "parser/base"
|
2
3
|
require_relative "parser/or"
|
3
4
|
require_relative "parser/and"
|
4
5
|
require_relative "parser/ast_helper"
|
@@ -10,6 +11,7 @@ require_relative "parser/type"
|
|
10
11
|
require_relative "parser/true"
|
11
12
|
require_relative "parser/false"
|
12
13
|
require_relative "parser/case"
|
14
|
+
require_relative "parser/block"
|
13
15
|
|
14
16
|
module VisualizeRuby
|
15
17
|
class Parser
|
data/visualize_ruby.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.1"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.7"
|
28
28
|
|
29
|
-
spec.add_runtime_dependency "
|
29
|
+
spec.add_runtime_dependency "graphviz", "~> 1.0"
|
30
30
|
spec.add_runtime_dependency "dissociated_introspection", "~> 0.9.1"
|
31
31
|
spec.add_runtime_dependency "parser", "~> 2.1", ">= 2.5.1.0"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visualize_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Zeisler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,25 +59,19 @@ dependencies:
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.7'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: graphviz
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '1.
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 1.2.3
|
67
|
+
version: '1.0'
|
71
68
|
type: :runtime
|
72
69
|
prerelease: false
|
73
70
|
version_requirements: !ruby/object:Gem::Requirement
|
74
71
|
requirements:
|
75
72
|
- - "~>"
|
76
73
|
- !ruby/object:Gem::Version
|
77
|
-
version: '1.
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 1.2.3
|
74
|
+
version: '1.0'
|
81
75
|
- !ruby/object:Gem::Dependency
|
82
76
|
name: dissociated_introspection
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,7 +135,9 @@ files:
|
|
141
135
|
- lib/visualize_ruby/parser.rb
|
142
136
|
- lib/visualize_ruby/parser/and.rb
|
143
137
|
- lib/visualize_ruby/parser/ast_helper.rb
|
138
|
+
- lib/visualize_ruby/parser/base.rb
|
144
139
|
- lib/visualize_ruby/parser/begin.rb
|
140
|
+
- lib/visualize_ruby/parser/block.rb
|
145
141
|
- lib/visualize_ruby/parser/case.rb
|
146
142
|
- lib/visualize_ruby/parser/false.rb
|
147
143
|
- lib/visualize_ruby/parser/if.rb
|