cobradeps 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bin/cobradeps +50 -0
- data/cobradeps.gemspec +39 -0
- data/lib/cobradeps.rb +89 -0
- data/lib/cobradeps/gemfile_scraper.rb +93 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 995be0ba3bdb1d3cdcae0a097b800a46534db785
|
4
|
+
data.tar.gz: c338653327cf27c0ae37d6e683d53744f5b4ce18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5efcc9f3c41d77dfa4a04a0a9361c01f2b6b7ea4025b913be9b4556c1840b4e45b380b6983b8f868f2dab8c6d009a8f38797a27167e46e537f3ee7d9fa6657a6
|
7
|
+
data.tar.gz: bd4b369f022a5999f61f9c7507155baec464dbfd511fd92848b56369e614c241eb254054e31e8c7e26dc583974aff862537800a5c63729a9f7f8915ff6dcd79a
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Stephan Hagemann
|
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,71 @@
|
|
1
|
+
# cobradeps [![Build Status](https://travis-ci.org/shageman/cobradeps.svg?branch=master)](https://travis-ci.org/shageman/cobradeps) [![Gem Version](https://badge.fury.io/rb/cobradeps.svg)](http://badge.fury.io/rb/cobradeps) [![Code Climate](https://codeclimate.com/github/shageman/cobradeps.png)](https://codeclimate.com/github/shageman/cobradeps) [![Dependency Status](https://gemnasium.com/shageman/cobradeps.svg)](https://gemnasium.com/shageman/cobradeps)
|
2
|
+
|
3
|
+
Prints and exports the dependencies within component-based Ruby/Rails applications (#cobra)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cobradeps'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cobradeps
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
cobradeps [OPTION] [application path]
|
22
|
+
|
23
|
+
Component-based Ruby/Rails dependency grapher.
|
24
|
+
|
25
|
+
Options are...
|
26
|
+
-t, --text DEFAULT Outputs a textual representation of the dependencies
|
27
|
+
-g, --graph Outputs graph.png to the current directory
|
28
|
+
-d, --dot Outputs graph.dot to the current directory
|
29
|
+
|
30
|
+
-h, -H, --help Display this help message.
|
31
|
+
|
32
|
+
## Example
|
33
|
+
|
34
|
+
There are sample #cobra folder structures in `spec/examples`. Here is the graph generated for the letters app structure:
|
35
|
+
|
36
|
+
![Letters graph](https://raw.githubusercontent.com/shageman/cobradeps/master/spec/examples/letters.png)
|
37
|
+
|
38
|
+
## #cobra extension to Gemfile
|
39
|
+
|
40
|
+
The :path option used for #cobras is typically a relative path. Because of that all gems and apps transitively including a
|
41
|
+
gem need to state the relative path to every gem with a path relatuive to their root. For an app, this is the reason why it is
|
42
|
+
unclear which gems it really directly depends on. That's why all dependencies of apps are omitted from the output graph.
|
43
|
+
|
44
|
+
To include direct dependencies of an application, add an additional option to the `gem` line from the Gemfile like so:
|
45
|
+
|
46
|
+
gem "B", path: "../B", direct: true
|
47
|
+
gem "C", path: "../C"
|
48
|
+
gem "D", path: "../D"
|
49
|
+
gem "E1", path: "../E1"
|
50
|
+
gem "E2", path: "../E2"
|
51
|
+
gem "F", path: "../F"
|
52
|
+
|
53
|
+
This is the [Gemfile of app A](https://github.com/shageman/cobradeps/blob/master/spec/examples/letters/A/Gemfile)
|
54
|
+
from the letters example of which you see the graph above.
|
55
|
+
|
56
|
+
##TODOs
|
57
|
+
|
58
|
+
* support windows folders (searching for a couple slashes)
|
59
|
+
* support windows: don't shell out to find gemspecs and gemfiles
|
60
|
+
* info if no gem file found for gem
|
61
|
+
* warn if gem has name different than folder
|
62
|
+
* warn if same gem name is found with path and without
|
63
|
+
* error if there are multiple gem specs
|
64
|
+
* error if there is not gem file in root
|
65
|
+
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
Copyright (c) 2014 Stephan Hagemann, stephan.hagemann@gmail.com, [@shageman](http://twitter.com/shageman)
|
70
|
+
|
71
|
+
Released under the MIT license. See LICENSE file for details.
|
data/Rakefile
ADDED
data/bin/cobradeps
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require_relative "../lib/cobradeps"
|
4
|
+
|
5
|
+
def help_text
|
6
|
+
<<-USAGE
|
7
|
+
cobradeps [OPTION] [application path]
|
8
|
+
|
9
|
+
Component-based Ruby/Rails dependency grapher.
|
10
|
+
|
11
|
+
Options are...
|
12
|
+
-t, --text DEFAULT Outputs a textual representation of the dependencies
|
13
|
+
-g, --graph Outputs graph.png to the current directory
|
14
|
+
-d, --dot Outputs graph.dot to the current directory
|
15
|
+
|
16
|
+
-h, -H, --help Display this help message.
|
17
|
+
USAGE
|
18
|
+
end
|
19
|
+
|
20
|
+
option = "-t"
|
21
|
+
path = nil
|
22
|
+
|
23
|
+
case ARGV.size
|
24
|
+
when 0
|
25
|
+
when 1
|
26
|
+
if ARGV[0].start_with? "-"
|
27
|
+
option = ARGV[0]
|
28
|
+
else
|
29
|
+
path = ARGV[0]
|
30
|
+
end
|
31
|
+
when 2
|
32
|
+
option = ARGV[0]
|
33
|
+
path = ARGV[1]
|
34
|
+
else
|
35
|
+
puts "Incorrect invocation. Please see help:\n\n"
|
36
|
+
puts help_text
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
if option
|
41
|
+
if %w(--help -h -H).include? option
|
42
|
+
puts help_text
|
43
|
+
elsif %w(-g --graph).include? option
|
44
|
+
Cbradeps.output_graph path
|
45
|
+
elsif %w(-d --dot).include? option
|
46
|
+
Cbradeps.output_dot path
|
47
|
+
elsif %w(-t --text).include? option
|
48
|
+
Cbradeps.output_text path
|
49
|
+
end
|
50
|
+
end
|
data/cobradeps.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'cobradeps'
|
7
|
+
spec.version = '0.1.1'
|
8
|
+
spec.authors = ['Stephan Hagemann']
|
9
|
+
spec.email = ['stephan.hagemann@gmail.com']
|
10
|
+
spec.summary = %q{Prints and exports the dependencies within component-based Ruby/Rails applications}
|
11
|
+
spec.description = <<-DOC
|
12
|
+
Component-based Ruby/Rails applications use local 'path' gem references to structure an application. This gem provides
|
13
|
+
utilities for printing and exporting such dependencies.
|
14
|
+
DOC
|
15
|
+
|
16
|
+
spec.homepage = 'https://github.com/shageman/cobradeps'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = %w(
|
20
|
+
bin/cobradeps
|
21
|
+
cobradeps.gemspec
|
22
|
+
Gemfile
|
23
|
+
lib/cobradeps/gemfile_scraper.rb
|
24
|
+
lib/cobradeps.rb
|
25
|
+
LICENSE
|
26
|
+
Rakefile
|
27
|
+
README.md
|
28
|
+
)
|
29
|
+
|
30
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
31
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.add_dependency 'ruby-graphviz'
|
35
|
+
|
36
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
37
|
+
spec.add_development_dependency 'rake'
|
38
|
+
spec.add_development_dependency 'rspec'
|
39
|
+
end
|
data/lib/cobradeps.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'pathname'
|
3
|
+
require 'graphviz'
|
4
|
+
|
5
|
+
module Cbradeps
|
6
|
+
require_relative "cobradeps/gemfile_scraper"
|
7
|
+
|
8
|
+
def self.output_text(root_path = nil)
|
9
|
+
path = root_path || current_path
|
10
|
+
app = GemfileScraper.new(path)
|
11
|
+
|
12
|
+
outputs "APP"
|
13
|
+
outputs app.to_s
|
14
|
+
|
15
|
+
outputs "\n\nDEPENDENCIES"
|
16
|
+
cobra_deps = app.transitive_cobra_dependencies.to_set
|
17
|
+
|
18
|
+
cobra_deps.each do |dep|
|
19
|
+
outputs "\n#{dep[:options][:path]}"
|
20
|
+
gem = GemfileScraper.new(dep[:options][:path])
|
21
|
+
outputs gem.to_s
|
22
|
+
|
23
|
+
cobra_deps = cobra_deps.merge gem.cobra_dependencies
|
24
|
+
end
|
25
|
+
|
26
|
+
outputs "\n\n ALL PARTS"
|
27
|
+
outputs cobra_deps.to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.output_graph(root_path = nil)
|
31
|
+
path = root_path || current_path
|
32
|
+
graph(path).output(:png => "graph.png")
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.output_dot(root_path = nil)
|
36
|
+
path = root_path || current_path
|
37
|
+
graph(path).output(:dot => "graph.dot")
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.current_path
|
41
|
+
`pwd`.chomp
|
42
|
+
end
|
43
|
+
|
44
|
+
private_class_method :current_path
|
45
|
+
|
46
|
+
def self.graph(path)
|
47
|
+
g = GraphViz.new(:G, :type => :digraph, concentrate: true)
|
48
|
+
|
49
|
+
app = GemfileScraper.new(path)
|
50
|
+
|
51
|
+
app_node = g.add_nodes(app.name)
|
52
|
+
outputs "Added #{app.name} node"
|
53
|
+
|
54
|
+
cobra_deps = app.transitive_cobra_dependencies.to_set
|
55
|
+
gem_nodes = {}
|
56
|
+
|
57
|
+
cobra_deps.each do |dep|
|
58
|
+
gem = GemfileScraper.new(dep[:options][:path])
|
59
|
+
gem_node = g.add_nodes(gem.name)
|
60
|
+
gem_nodes[gem.name] = gem_node
|
61
|
+
outputs "Added #{gem.name} node"
|
62
|
+
if dep[:options][:direct]
|
63
|
+
outputs "Added edge from #{app.name} to #{gem.name}"
|
64
|
+
g.add_edges(app_node, gem_node)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
cobra_deps.each do |dep|
|
69
|
+
gem = GemfileScraper.new(dep[:options][:path])
|
70
|
+
gem_node = gem_nodes[gem.name]
|
71
|
+
|
72
|
+
gem_cobra_deps = gem.cobra_dependencies
|
73
|
+
gem_cobra_deps.each do |nest_dep|
|
74
|
+
nest_gem = GemfileScraper.new(nest_dep[:options][:path])
|
75
|
+
g.add_edges(gem_node, gem_nodes[nest_gem.name])
|
76
|
+
outputs "Added edge from #{gem.name} to #{nest_gem.name}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
g
|
80
|
+
end
|
81
|
+
|
82
|
+
private_class_method :graph
|
83
|
+
|
84
|
+
def self.outputs(arg)
|
85
|
+
puts arg
|
86
|
+
end
|
87
|
+
|
88
|
+
private_class_method :outputs
|
89
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Cbradeps
|
2
|
+
class GemfileScraper
|
3
|
+
def initialize(root_path)
|
4
|
+
@root_path = root_path
|
5
|
+
end
|
6
|
+
|
7
|
+
def name
|
8
|
+
Pathname.new(@root_path).basename.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
cobra_dependencies
|
13
|
+
end
|
14
|
+
|
15
|
+
def cobra_dependencies
|
16
|
+
dirdep = direct_dependencies
|
17
|
+
transitive_cobra_dependencies.select do |dep|
|
18
|
+
dirdep.include?(dep[:name]) || dep[:options][:direct]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def transitive_cobra_dependencies
|
23
|
+
gem_dependencies.inject([]) do |memo, dep|
|
24
|
+
if !!dep[:options][:path]
|
25
|
+
absolute_dep = dep.clone
|
26
|
+
absolute_dep[:options][:path] = File.expand_path(File.join(@root_path, dep[:options][:path]))
|
27
|
+
memo << dep
|
28
|
+
end
|
29
|
+
memo
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def raw_gemspec
|
36
|
+
path = File.expand_path(File.join(@root_path, "#{underscore(name)}.gemspec"))
|
37
|
+
File.exist?(path) ? File.read(path) : ""
|
38
|
+
end
|
39
|
+
|
40
|
+
def direct_dependencies
|
41
|
+
raw_gemspec.split("\n").inject([]) do |memo, line|
|
42
|
+
match = line.match(/add_(?:development_)?dependency\s+["']([^'"]+)["']/)
|
43
|
+
memo << match[1] if match
|
44
|
+
memo
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def raw_gemfile
|
49
|
+
path = File.expand_path(File.join(@root_path, "Gemfile"))
|
50
|
+
File.read(path)
|
51
|
+
end
|
52
|
+
|
53
|
+
def gem_dependencies
|
54
|
+
raw_gemfile.split("\n").inject([]) do |memo, line|
|
55
|
+
match = line.match(/gem\s+["']([^'"]+)["'](.*)/)
|
56
|
+
if match
|
57
|
+
memo << {name: match[1], options: OptionParser.new(match[2]).parse}
|
58
|
+
end
|
59
|
+
memo
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def underscore(string)
|
64
|
+
string.gsub(/::/, '/').
|
65
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
66
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
67
|
+
tr("-", "_").
|
68
|
+
downcase
|
69
|
+
end
|
70
|
+
|
71
|
+
class OptionParser
|
72
|
+
def initialize(options)
|
73
|
+
@options = options
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse
|
77
|
+
{}.merge(path).merge(direct)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def path
|
83
|
+
match = @options.match(/path(?:\s*=>|:)\s+["']([^'"]+)["']/)
|
84
|
+
match ? {path: match[1]} : {}
|
85
|
+
end
|
86
|
+
|
87
|
+
def direct
|
88
|
+
match = @options.match(/direct(?:\s*=>|:)\s+true/)
|
89
|
+
match ? {direct: true} : {}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cobradeps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephan Hagemann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
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: '0'
|
20
|
+
type: :runtime
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: |
|
70
|
+
Component-based Ruby/Rails applications use local 'path' gem references to structure an application. This gem provides
|
71
|
+
utilities for printing and exporting such dependencies.
|
72
|
+
email:
|
73
|
+
- stephan.hagemann@gmail.com
|
74
|
+
executables:
|
75
|
+
- cobradeps
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- bin/cobradeps
|
80
|
+
- cobradeps.gemspec
|
81
|
+
- Gemfile
|
82
|
+
- lib/cobradeps/gemfile_scraper.rb
|
83
|
+
- lib/cobradeps.rb
|
84
|
+
- LICENSE
|
85
|
+
- Rakefile
|
86
|
+
- README.md
|
87
|
+
homepage: https://github.com/shageman/cobradeps
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Prints and exports the dependencies within component-based Ruby/Rails applications
|
111
|
+
test_files: []
|