lapidarius 2.1.2 → 3.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7710821237e08e7528d2d68e033af6d44c20e33d
4
- data.tar.gz: 5c349cf60b82a03b47531a7d7695adffb4abec9e
3
+ metadata.gz: 047e73cb5b2d4a23b395e2780448ba0f60bc322d
4
+ data.tar.gz: 4309e419d45fbb06bb9b8db9c20c6ff6b55480af
5
5
  SHA512:
6
- metadata.gz: 469186864c12e739586fece5372397f816b6946f4f6872448f39c085da92601ff2a256715f1768877a355fcee45b5069c9c8c386afdc40a4b4b17f88f2a94e69
7
- data.tar.gz: 9759cf03c8d0b1d46fdd73c7e4a173dbdda758682e92b96e222b6f48241edc7d19c437e1523efbe926c3b729129258c3437aab526f8a65a454c270fd3e3ef809
6
+ metadata.gz: 118527bfce62dba8aaa7a7bd4f905eb2bc1d460aaa82f116252f6c18a7c6f257e51a47c9343cba978aa0698bb3021a86b3e61539b468325da219cdc5a00d8611
7
+ data.tar.gz: 458a14c7713453b520691ae574f825b372fca8a3b3efc15508b9fd2991f8b200e1302b11a0c7dbef50342d91fdfe879042fd8e75580371b79556e02c9b25dafc
data/README.md CHANGED
@@ -6,8 +6,7 @@
6
6
  * [bundle viz](#bundle-viz)
7
7
  * [Usage](#usage)
8
8
  * [Warning](#warning)
9
- * [Unique dependencies](#unique-dependencies)
10
- * [Recursive print](#recursive-print)
9
+ * [Output](#output)
11
10
 
12
11
  ## Scope
13
12
  This gem is aimed to list recursively the **runtime dependencies** footprint of the specified gem.
@@ -26,43 +25,20 @@ While it is great to visualize inter-dependencies, i have hard times figuring ou
26
25
  The library relies on the *Gem::Commands::DependencyCommand* class (the one invoked by the *gem dep* command line), invoking it recursively to deeply fetch dependencies.
27
26
 
28
27
  ### Warning
29
- Consider only the gems installed on your system are scanned for their own dependencies, no remote fetching is performed.
28
+ Consider only the gems installed on your system are scanned.
29
+ No remote fetching is performed.
30
30
 
31
- ### Unique dependencies
32
- The command outcome includes all of the unique (by name) nested runtime dependencies:
31
+ ### Output
32
+ The output of the library mimics the `tree` shell utility that lists file system nested entries.
33
+ Although all of the nested runtime dependencies are included in the output, just the unique ones are counted:
33
34
  ```
34
- $ lapidarius --gem=grape
35
-
36
- grape (1.0.1) 16
37
- ------------------------------
38
- activesupport (>= 0)
39
- builder (>= 0)
40
- mustermann-grape (~> 1.0.0)
41
- rack (>= 1.3.0)
42
- rack-accept (>= 0)
43
- virtus (>= 1.0.0)
44
- i18n (~> 0.7)
45
- minitest (~> 5.1)
46
- thread_safe (>= 0.3.4, ~> 0.3)
47
- tzinfo (~> 1.1)
48
- mustermann (~> 1.0.0)
49
- axiom-types (~> 0.1)
50
- coercible (~> 1.0)
51
- descendants_tracker (>= 0.0.3, ~> 0.0)
52
- equalizer (>= 0.0.9, ~> 0.0)
53
- ice_nine (~> 0.11.0)
54
- ```
55
-
56
- ### Recursive print
57
- To print dependencies hierarchy recursively, provide the *--recursive* flag. Duplicates are not counted:
58
- ```
59
- $ lapidarius --gem=sinatra --recursive
60
-
61
- sinatra (1.4.7) 3
62
- ------------------------------
63
- rack (~> 1.5)
64
- rack-protection (~> 1.4)
65
- rack (>= 0)
66
- tilt (< 3, >= 1.3)
67
-
35
+ $ lapidarius --gem=sinatra
36
+ sinatra (2.0.0)
37
+ ├── mustermann (~> 1.0)
38
+ ├── rack (~> 2.0)
39
+ ├── rack-protection (= 2.0.0)
40
+ │ └── rack (>= 0)
41
+ └── tilt (~> 2.0)
42
+
43
+ 4 runtime dependencies
68
44
  ```
@@ -1,6 +1,5 @@
1
1
  require "optparse"
2
2
  require "lapidarius/cutter"
3
- require "lapidarius/renderer"
4
3
 
5
4
  module Lapidarius
6
5
  class CLI
@@ -8,30 +7,25 @@ module Lapidarius
8
7
  @args = args
9
8
  @io = io
10
9
  @gem = nil
11
- @recursive = nil
12
10
  end
13
11
 
14
12
  def call(cmd_klass = Command)
15
13
  parser.parse!(@args)
16
14
  return @io.puts("specify gem name as: '-g gem_name'") unless @gem
17
15
  obj = Lapidarius::Cutter.new(@gem, cmd_klass).call
18
- Lapidarius::Renderer::new(obj, @recursive).call(@io)
16
+ @io.puts Lapidarius::Tree::new(obj).out
19
17
  rescue Gem::NotInstalledError => e
20
18
  @io.puts e.message.sub("specified", "\e[1m#{@gem}\e[0m")
21
19
  end
22
20
 
23
21
  private def parser
24
22
  OptionParser.new do |opts|
25
- opts.banner = "Usage: ./bin/lapidarius --gem=sinatra --recursive"
23
+ opts.banner = "Usage: ./bin/lapidarius --gem=sinatra"
26
24
 
27
25
  opts.on("-gGEM", "--gem=GEM", "The gem name to scan") do |gem|
28
26
  @gem = gem
29
27
  end
30
28
 
31
- opts.on("-r", "--recursive", "Print dependencies recursively") do |recursive|
32
- @recursive = recursive
33
- end
34
-
35
29
  opts.on("-h", "--help", "Prints this help") do
36
30
  @io.puts opts
37
31
  exit
@@ -1,13 +1,18 @@
1
+ require "forwardable"
2
+ require "lapidarius/tree"
3
+
1
4
  module Lapidarius
2
5
  class Gem
6
+ extend Forwardable
7
+
8
+ def_delegators :@deps, :size, :each_with_index
9
+
3
10
  class KindError < ArgumentError; end
4
11
  class NotInstalledError < ArgumentError; end
5
12
 
6
- LEVEL_DEPTH = 5
7
-
8
13
  def self.factory(token)
9
14
  token.match(/^No gems found matching/) do |m|
10
- fail NotInstalledError, "no version of specified gem is installed!"
15
+ fail NotInstalledError, "no version of specified gem installed"
11
16
  end
12
17
  token.match(/Gem ([a-zA-Z0-9\-_]+)-(.+)/) do |m|
13
18
  return new(name: m[1], version: m[2])
@@ -35,22 +40,11 @@ module Lapidarius
35
40
  gem.name == name && gem.version == version
36
41
  end
37
42
 
38
- def to_s(recursive: false)
39
- return fullname unless recursive
40
- fullname.tap do |s|
41
- deps.each do |dep|
42
- s << "\n"
43
- s << indentation
44
- s << dep.to_s(recursive: recursive)
45
- end
46
- end
47
- end
48
-
49
- def fullname
43
+ def to_s
50
44
  "#{name} (#{version})"
51
45
  end
52
46
 
53
- def deep_count
47
+ def count
54
48
  flatten_deps.size
55
49
  end
56
50
 
@@ -63,10 +57,6 @@ module Lapidarius
63
57
  end
64
58
  end
65
59
 
66
- private def indentation
67
- " " * (caller.size / LEVEL_DEPTH)
68
- end
69
-
70
60
  private def gem?(gem)
71
61
  %i{name version deps}.all? { |msg| gem.respond_to?(msg) }
72
62
  end
@@ -0,0 +1,39 @@
1
+ require "ostruct"
2
+
3
+ module Lapidarius
4
+ class Tree
5
+ CURVED = "└── "
6
+ EMPTY = " "
7
+ NESTED = "├── "
8
+ STRAIGHT = "│ "
9
+
10
+ def initialize(gem)
11
+ @gem = gem
12
+ @out = []
13
+ end
14
+
15
+ def out
16
+ return @out unless @out.empty?
17
+ @out.tap do |out|
18
+ out << @gem
19
+ recurse
20
+ out << ""
21
+ out << "#{@gem.count} runtime dependencies"
22
+ end
23
+ end
24
+
25
+ private def recurse(gem = @gem, prefix = "")
26
+ last_index = gem.size - 1
27
+ gem.each_with_index do |dep, i|
28
+ pointer, preadd = branches(i == last_index)
29
+ @out << "#{prefix}#{pointer}#{dep}"
30
+ recurse(dep, "#{prefix}#{preadd}") if dep.size > 0
31
+ end
32
+ end
33
+
34
+ private def branches(last)
35
+ return [CURVED, EMPTY] if last
36
+ [NESTED, STRAIGHT]
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Lapidarius
2
- VERSION = "2.1.2"
2
+ VERSION = "3.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lapidarius
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-20 00:00:00.000000000 Z
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,7 +74,7 @@ files:
74
74
  - lib/lapidarius/command.rb
75
75
  - lib/lapidarius/cutter.rb
76
76
  - lib/lapidarius/gem.rb
77
- - lib/lapidarius/renderer.rb
77
+ - lib/lapidarius/tree.rb
78
78
  - lib/lapidarius/ui.rb
79
79
  - lib/lapidarius/version.rb
80
80
  homepage: https://github.com/costajob/lapidarius
@@ -1,39 +0,0 @@
1
- module Lapidarius
2
- class Renderer
3
- class NoEntGemError< ArgumentError; end
4
-
5
- def initialize(gem, recursive = false)
6
- fail NoEntGemError, "gem not found on this system!" unless gem
7
- @gem = gem
8
- @recursive = recursive
9
- @out = []
10
- end
11
-
12
- def call(io = STDOUT)
13
- io.puts out
14
- end
15
-
16
- def out
17
- collect_header
18
- collect_body
19
- @out
20
- end
21
-
22
- private def collect_header
23
- @out << ("\n#{@gem.fullname}".ljust(29) << "\e[1m#{@gem.deep_count}\e[0m".rjust(3))
24
- @out << hr
25
- end
26
-
27
- private def collect_body
28
- return if @gem.deps.empty?
29
- @gem.deps.each do |dep|
30
- @out << dep.to_s(recursive: @recursive)
31
- end
32
- @out << "\n"
33
- end
34
-
35
- private def hr
36
- "#{"-" * 30}\n"
37
- end
38
- end
39
- end