rrg 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b51311e9dcb171ca60d47e533c8f490da8f221d
4
+ data.tar.gz: c301e1735d5e0fbbabfdec83db759a8dd326e643
5
+ SHA512:
6
+ metadata.gz: 3938447b673b5f932d31d0afa25cafde4b844c0ea8da2aac0d4e790f598b0e76c3d0c0836e7144a9581cad2b9bb3915ba686a7fe10883a981ce6581dfbb5c2e0
7
+ data.tar.gz: e0c1b304edc0a4a13834ee4090c8dfc5333592b4301c47210a1ce0e27d17cd88f77d03f0ddb3b5f71c54dc82c98b611ef5939f3147f31bfcfc998ae4196cd27d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rrg.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Antonio Terceiro
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Rrg
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ With rubygems:
8
+
9
+ $ gem install rrg
10
+
11
+ ## Usage
12
+
13
+ Just run `rrg` at the root of your project. `rrg` will parse the code inside
14
+ `lib/`, and generate a graph description in the Graphviz format. You can pipe
15
+ the output to Graphviz directly, or store it in a file and process it the
16
+ generate an image.
17
+
18
+ If you call `rrgv`, it wil automatically process the graph with Graphviz,
19
+ generate a PNG image, and open it with `xdg-open` or `open`.
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork the [project on GitLab](https://gitlab.com/terceiro/rrg)
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create a new Merge Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ pkg = Gem::Specification.load('rrg.gemspec')
4
+
5
+ task 'deb:install' => :build do
6
+ chdir 'pkg' do
7
+ sh 'gem2deb', '-p', pkg.name, "#{pkg.name}-#{pkg.version}.gem"
8
+ sh 'sudo', 'dpkg', '-i', "#{pkg.name}_#{pkg.version}-1_all.deb"
9
+ end
10
+ end
data/bin/rrg ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'set'
4
+ require 'tmpdir'
5
+
6
+ require 'ruby_parser'
7
+
8
+ #######################################################################
9
+ # Process the code
10
+ #######################################################################
11
+
12
+ project_files = []
13
+ nodes = Set.new
14
+ requires = []
15
+
16
+ Dir.chdir 'lib' do
17
+ Dir.glob('**/*.rb').each do |f|
18
+ fname = f.sub(/\.rb$/, '')
19
+ nodes << fname
20
+ project_files << fname
21
+ parser = RubyParser.new
22
+ tree = parser.parse(File.read(f))
23
+ tree.each do |node|
24
+ if node[0] == :call and node[2] == :require
25
+ nodes << node[3][1]
26
+ requires << [fname, node[3][1]]
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ #######################################################################
34
+ # Decide what to do with the data based in the called program name
35
+ # rrg: output to stdout
36
+ # rrgv: view image directly
37
+ #######################################################################
38
+
39
+ # TODO refactor this to polymorphism
40
+ if File.basename($PROGRAM_NAME) == 'rrg'
41
+ output = $stdout
42
+ view_output = lambda { true } # nothing
43
+ else
44
+ tmpdir = Dir.mktmpdir
45
+ image = File.join(tmpdir, 'requires.png')
46
+ output = IO.popen(['dot', '-Tpng', '-o', image], 'w')
47
+
48
+ # FIXME hardcoded list of image viewers for now
49
+ image_viewer = %w[xdg-open eog gwenview ristretto open].find do |prog|
50
+ system("which #{prog} >/dev/null 2>&1")
51
+ end
52
+
53
+ unless image_viewer
54
+ echo "E: could find a suitable image viewer. Please report a bug."
55
+ exit(1)
56
+ end
57
+
58
+ view_output = lambda do
59
+ system(image_viewer, image)
60
+ end
61
+ end
62
+
63
+ #######################################################################
64
+ # Generate output
65
+ #######################################################################
66
+
67
+ output.puts 'digraph require_graph {'
68
+ nodes.each do |req|
69
+ if project_files.include?(req)
70
+ color = ''
71
+ else
72
+ color = ', color="#888a85", fontcolor="#888a85"'
73
+ end
74
+ output.puts " \"#{req}\" [shape=box#{color}];"
75
+ end
76
+ requires.each do |call|
77
+ output.puts " \"#{call[0]}\" -> \"#{call[1]}\";"
78
+ end
79
+ output.puts '}'
80
+ output.close
81
+
82
+ #######################################################################
83
+ # visualize the output
84
+ #######################################################################
85
+ view_output.call
data/bin/rrgv ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.expand_path('../rrg', __FILE__)
data/lib/rrg.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "rrg/version"
2
+
3
+ module Rrg
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Rrg
2
+ VERSION = "0.1"
3
+ end
data/rrg.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rrg/version'
5
+
6
+ description = <<DESCRIPTION
7
+ rrg will read the source code of a Ruby project and generate a graph based on
8
+ the require statements in the code, when nodes are the source files and an
9
+ arrow from A to B means that A calls `require 'B'`.
10
+ DESCRIPTION
11
+
12
+ Gem::Specification.new do |spec|
13
+ spec.name = "rrg"
14
+ spec.version = Rrg::VERSION
15
+ spec.authors = ["Antonio Terceiro"]
16
+ spec.email = ["terceiro@softwarelivre.org"]
17
+ spec.summary = %q{require graph extractor and viewer for Ruby projects}
18
+ spec.description = description
19
+ spec.homepage = "https://gitlab.com/terceiro/rrg"
20
+ spec.license = "MIT"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0")
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "rake"
29
+
30
+ spec.add_runtime_dependency "ruby_parser"
31
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rrg
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Antonio Terceiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby_parser
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |
56
+ rrg will read the source code of a Ruby project and generate a graph based on
57
+ the require statements in the code, when nodes are the source files and an
58
+ arrow from A to B means that A calls `require 'B'`.
59
+ email:
60
+ - terceiro@softwarelivre.org
61
+ executables:
62
+ - rrg
63
+ - rrgv
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/rrg
73
+ - bin/rrgv
74
+ - lib/rrg.rb
75
+ - lib/rrg/version.rb
76
+ - rrg.gemspec
77
+ homepage: https://gitlab.com/terceiro/rrg
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: require graph extractor and viewer for Ruby projects
101
+ test_files: []
102
+ has_rdoc: