ruby_ast_visualizer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0a287d9b67d359220d57194ab7e53a08e5d17f2
4
- data.tar.gz: 4fdbdea5a5652be3a3c246b8c6faf7e6c1041ddc
3
+ metadata.gz: 4ec81c0daa6acddeb64dff7b8a6d263a415ece0d
4
+ data.tar.gz: f4d40be35bc7e2c7f6129d2981b899c14bdaad74
5
5
  SHA512:
6
- metadata.gz: cd6a54d7c18f300ae96d9a4470d2b2e3d78619d7b1345da9e1ea81e642b6cae5a39fd0cb2880cc7617f385537fe6b4d1e0fe2acbb3bb6e54f49081da82b65dd3
7
- data.tar.gz: 09f2b1c00eb273d582724bae29d365013071ca775207dd363fd41b863c0cb314d40a24e8fc350c53ef75cc13161aea92ee1739018f5cc0813947e3c1f5393e8f
6
+ metadata.gz: a2b1310c613358e90ff7e2e61297461dd930da2717071e1a33d7ae2567e739f402a256c1cda3c699ebc42aaf87c62f784515783b2faaa1c3ee3fa35b395e4246
7
+ data.tar.gz: 81f726b857fe3a70e871cf6dffe22747844411ffaa17b153499debc8a891ae48b67bbc5418ba8d082528bcc483a4b8ffc81760acb351bfbdbc56994ec97f9893
data/README.md CHANGED
@@ -1,16 +1,24 @@
1
- # Ruby AST Visualizer
1
+ # Ruby AST Visualizer [![Gem Version](https://badge.fury.io/rb/ruby_ast_visualizer.svg)](http://badge.fury.io/rb/ruby_ast_visualizer)
2
2
 
3
3
  Ruby AST Visualizer. Based on [Parser](https://github.com/whitequark/parser).
4
4
 
5
- ## USAGE
5
+ ## Usage
6
6
 
7
7
  An example `ruby_ast_visualizer` command.
8
8
 
9
9
  ```
10
- $ ruby_ast_visualizer 'puts "hello"'
10
+ $ cat hello.rb
11
+ puts 'hello, world'
12
+ $ ruby_ast_visualizer hello.rb
11
13
  ```
12
14
 
13
- Following image file is generated.
15
+ or
16
+
17
+ ```
18
+ $ ruby_ast_visualizer -e 'puts "hello, world"'
19
+ ```
20
+
21
+ AST image file is generated.
14
22
 
15
23
  <img src="https://raw.githubusercontent.com/koic/ruby_ast_visualizer/master/images/hello_world.png" alt="hello, world"/>
16
24
 
@@ -19,14 +27,14 @@ Following image file is generated.
19
27
  You can specify output path in the `-o` option. That value is default a.png.
20
28
 
21
29
  ```
22
- $ ruby_ast_visualizer -o path/to/file 'puts "hello"'
30
+ $ ruby_ast_visualizer -o path/to/file -e 'puts "hello, world"'
23
31
  ```
24
32
 
25
- ## REQUIREMENTS
33
+ ## Requirements
26
34
 
27
35
  * Graphviz
28
36
 
29
- ## INSTALL
37
+ ## Install
30
38
 
31
39
  Add these lines to your application's Gemfile:
32
40
 
@@ -15,20 +15,25 @@ Version = RubyAstVisualizer::VERSION
15
15
 
16
16
  options = {}
17
17
 
18
- opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] 'ruby code'")
18
+ opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] [-e 'command'] [programfile]")
19
19
 
20
+ opt.on('-e', "--eval 'command'") {|v| options[:eval] = v }
20
21
  opt.on('-o', '--output path/to/file (DEFAULT a.png)') {|v| options[:output] = v }
21
22
 
22
23
  begin
23
24
  opt.permute!(ARGV)
24
25
 
25
- raise unless ARGV.size == 1
26
+ source = options[:eval]
26
27
 
27
- source = ARGV.shift
28
+ if source.nil? || source.empty?
29
+ raise unless ARGV.size == 1
30
+
31
+ source = File.read(ARGV.shift)
32
+ end
28
33
 
29
34
  file_name = options[:output] || 'a.png'
30
35
 
31
- result = RubyAstVisualizer::Core.new(source).reconfigure
36
+ result = RubyAstVisualizer::Core.new(source).visualize
32
37
 
33
38
  result.output(png: file_name)
34
39
 
@@ -8,19 +8,19 @@ module RubyAstVisualizer
8
8
  @source = source
9
9
  end
10
10
 
11
- def reconfigure
11
+ def visualize
12
12
  g = GraphViz.new(:G, type: :digraph)
13
13
 
14
14
  node = Parser::CurrentRuby.parse(@source)
15
15
 
16
- _reconfigure(g, node)
16
+ reconfigure(g, node)
17
17
 
18
18
  g
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- def _reconfigure(g, node)
23
+ def reconfigure(g, node)
24
24
  self_node = g.add_nodes(fetch_node_id(node), label: node.type)
25
25
 
26
26
  node.children.each {|node|
@@ -35,7 +35,7 @@ module RubyAstVisualizer
35
35
 
36
36
  self_node << g.add_nodes(fetch_node_id(node), label: label)
37
37
 
38
- _reconfigure(g, node) if node.respond_to? :children
38
+ reconfigure(g, node) if node.respond_to? :children
39
39
  }
40
40
  end
41
41
 
@@ -1,3 +1,3 @@
1
1
  module RubyAstVisualizer
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_ast_visualizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser