gem_dependencies_visualizer 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +12 -2
- data/lib/gem_dependencies_visualizer/version.rb +1 -1
- data/lib/gem_dependencies_visualizer.rb +45 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdb9a51b51a557ad4b43df551279a765d3bf9451
|
4
|
+
data.tar.gz: 781f4d337725ec8e109346e24fab39e2188c6692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ba22599307500b44a3b515bebcfcc1a2a188ccd9f3311845a5abc7327175fe3baecdca9dc18ac722b22c1803356db4492245464f7fd87d11fdc95ca062ac559
|
7
|
+
data.tar.gz: 195fda093daf34168c430a74192c287d5c9a34282f7cfc828874dd112da6e3f7ac4ac7cb6ecc6226ae7c7d8617a2400593ad9c125aef53fd46a00f252d5b4916
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -18,14 +18,24 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
To produce a graph of your gem dependencies, pass the content of a Gemfile.lock as is as an input to the visualizer. You can (optionaly) pass a graph name you might want to give to the .png file to be produced.
|
21
|
+
To produce a graph of your gem dependencies, pass the content of a Gemfile.lock and, if available, the content of the Gemfile as is as an input to the visualizer. You can (optionaly) pass a graph name you might want to give to the .png file to be produced.
|
22
22
|
|
23
23
|
To use it just run the following in your code:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
GemDependenciesVisualizer.produce_gems_graph(
|
26
|
+
GemDependenciesVisualizer.produce_gems_graph(gemfile_content, gemfile_lock_content, graph_name, options = {})
|
27
27
|
```
|
28
28
|
|
29
|
+
Available options you could use are:
|
30
|
+
|
31
|
+
* :graph_direction, which will set how your graph will be produced with options
|
32
|
+
** top-bottom, for the graph to start on the top towards the bottom
|
33
|
+
** bottom-top, for the graph to start on the bottom towards the top
|
34
|
+
** right-left, for the graph to start on the left towards the right
|
35
|
+
** anything else is set to default, which is left to right.
|
36
|
+
* :keep_gem_version, which will keep the versions set in the Gemfile.lock
|
37
|
+
* :specific_directory, which will mark the folder in which the graphs should be rendered. All graphs are always created inside gem_dependencies_graphs folder. Default namespace used is app/assets/images.
|
38
|
+
|
29
39
|
For example by using the produced Gemfile.lock in this gem, we can get the following:
|
30
40
|
|
31
41
|
![Sample produced graph](https://raw.githubusercontent.com/arcanoid/gem_dependencies_visualizer/master/sample_images/graph_sample.png)
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require "gem_dependencies_visualizer/version"
|
2
2
|
|
3
3
|
module GemDependenciesVisualizer
|
4
|
-
def self.produce_gems_graph(
|
5
|
-
|
4
|
+
def self.produce_gems_graph(gem_file_content, gem_file_lock_content, graph_name = nil, options = {})
|
5
|
+
if gem_file_lock_content.nil?
|
6
|
+
puts 'Please insert both Gemfile and Gemfile.lock contents to proceed or just Gemfile.lock content.'
|
7
|
+
else
|
6
8
|
g = GraphViz::new( :G, :type => :digraph )
|
7
|
-
g[:rankdir] =
|
9
|
+
g[:rankdir] = rankdir(options)
|
8
10
|
|
9
|
-
data = populate_gem_data
|
11
|
+
data = populate_gem_data gem_file_content, gem_file_lock_content, options
|
10
12
|
populate_gem_graph g, data, graph_name, options
|
11
13
|
end
|
12
14
|
end
|
@@ -15,8 +17,23 @@ module GemDependenciesVisualizer
|
|
15
17
|
protected
|
16
18
|
#########
|
17
19
|
|
18
|
-
def self.
|
19
|
-
|
20
|
+
def self.rankdir(options = {})
|
21
|
+
case options[:graph_direction]
|
22
|
+
when 'top-bottom' then 'TB'
|
23
|
+
when 'bottom-top' then 'BT'
|
24
|
+
when 'right-left' then 'RL'
|
25
|
+
else 'LR'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.collect_gems_from_gemfile(gem_file_content, options = {})
|
30
|
+
unless gem_file_content.nil?
|
31
|
+
(gem_file_content.scan /.*gem ['"](\S*)['"]/).flatten.uniq.sort
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.collect_gems_from_gemfile_lock(gem_file_lock_content, options = {})
|
36
|
+
string_array = gem_file_lock_content.gsub("\r\n", "\n").split("\n")
|
20
37
|
gem_list_index = 0
|
21
38
|
gem_list = {}
|
22
39
|
|
@@ -67,12 +84,28 @@ module GemDependenciesVisualizer
|
|
67
84
|
gem_list
|
68
85
|
end
|
69
86
|
|
87
|
+
def self.populate_gem_data(gem_file_content, gemfile_lock_content, options = {})
|
88
|
+
gem_dependencies = collect_gems_from_gemfile_lock gemfile_lock_content, options
|
89
|
+
gems = collect_gems_from_gemfile gem_file_content, options
|
90
|
+
|
91
|
+
{
|
92
|
+
:gems => gems,
|
93
|
+
:gem_dependencies => gem_dependencies
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
70
97
|
def self.populate_gem_graph(graph, data, graph_name = nil, options = {})
|
71
|
-
|
98
|
+
unless data[:gems].empty?
|
99
|
+
default_node = graph.add_nodes('Default', :label => "<<b>Default</b>>", :color => 'dodgerblue3')
|
100
|
+
|
101
|
+
data[:gems].each do |gem|
|
102
|
+
new_node = graph.add_nodes(gem, :shape => :msquare, :color => 'firebrick3')
|
103
|
+
graph.add_edges(default_node, new_node, :color => 'dodgerblue3')
|
104
|
+
end
|
105
|
+
end
|
72
106
|
|
73
|
-
data.each do |dependency_item|
|
107
|
+
data[:gem_dependencies].sort_by { |dependency_item| dependency_item[0] }.each do |dependency_item|
|
74
108
|
graph_parent_node = graph.add_nodes(dependency_item[0], :shape => :msquare, :color => 'firebrick3')
|
75
|
-
graph.add_edges(default_node, graph_parent_node, :color => 'dodgerblue3')
|
76
109
|
|
77
110
|
dependency_item[1].each do |child_gem|
|
78
111
|
graph_child_node = graph.add_nodes(child_gem, :shape => :msquare)
|
@@ -103,4 +136,7 @@ module GemDependenciesVisualizer
|
|
103
136
|
private_class_method :populate_gem_graph
|
104
137
|
private_class_method :populate_gem_data
|
105
138
|
private_class_method :clear_gem_name_from_version
|
139
|
+
private_class_method :rankdir
|
140
|
+
private_class_method :collect_gems_from_gemfile
|
141
|
+
private_class_method :collect_gems_from_gemfile_lock
|
106
142
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_dependencies_visualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasilis Kalligas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|