lapidarius 3.4.0 → 4.0.1

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
  SHA256:
3
- metadata.gz: 8e47ba3f42ec60db9d0842f79b8289326e8654f10d0ec7d8893c23be55fc16bb
4
- data.tar.gz: ef2ea270800d9f78102e03b271da4faca4014ebfb2732162789d9fc1d586dc20
3
+ metadata.gz: aa85a20faa777803fdff22b4f680bf050de0e09229181f91efd54c03e50858d2
4
+ data.tar.gz: fb490c7133b98e4c364032ac1fbff5cb4d8b350dc0a1df61eaace7eaf716ad2e
5
5
  SHA512:
6
- metadata.gz: e481ada2be52866b19189925b0a222f08cd2810e878b9d78f22fce46432a58cf7d19014e8c2de036043e13db451d058dca43120d40b7147a69415805fc87d60d
7
- data.tar.gz: acf4e8bee952dfc6138e5830dc031e1892bd1c460b7f434f3a803ae2119abc06e1ceceec33de6b80afce2d5f5c00cb1a0d3a011ce554dbbd3066c4d646b1d698
6
+ metadata.gz: cc2067d98c1c09e9297e6642e79ace764a0c282e677f04e6894121d8aed861935cdaf78a2bb6ef4cf666c461f1a3f6c6774064ba14478230ec29554fa5db3a2b
7
+ data.tar.gz: e2251cd404033b04a5c680b94d62d7ba5178eef71ce7415721969e87ce6b4b4012c670cd8acac1732ce9fc5c33631669ba72ce03772169ca1d65e943306ece26
data/.travis.yml CHANGED
@@ -4,4 +4,5 @@ rvm:
4
4
  - 2.1.8
5
5
  - 2.2.1
6
6
  - 2.4.1
7
+ - 2.5.0
7
8
  before_install: gem install bundler -v 1.12.5
data/README.md CHANGED
@@ -4,10 +4,10 @@
4
4
  * [Alternatives](#alternatives)
5
5
  * [gem dep](#gem-dep)
6
6
  * [bundle viz](#bundle-viz)
7
- * [Warning](#warning)
8
7
  * [Installation](#installation)
9
8
  * [Usage](#usage)
10
9
  * [Version](#version)
10
+ * [Remote](#remote)
11
11
 
12
12
  ## Scope
13
13
  This gem is aimed to recursively collect the `runtime dependencies` footprint of the specified gem.
@@ -17,16 +17,12 @@ The output of the library mimics the `tree` shell utility, highlighting the nest
17
17
  Some alternatives exists:
18
18
 
19
19
  #### gem dep
20
- The standard *gem dep* command just unearth one level of dependencies.
20
+ The standard `gem dep` command just unearth one level of dependencies.
21
21
 
22
22
  #### bundle viz
23
- The *bundle viz* command relies on the Gemfile and the [graphviz](http://www.graphviz.org/) library to generate a visual representation of the gem inter-dependencies.
23
+ The `bundle viz` command relies on the Gemfile and the [graphviz](http://www.graphviz.org/) library to generate a visual representation of the gem inter-dependencies.
24
24
  While it is great to visualize inter-dependencies, i have hard times figuring out gem's runtime footprint.
25
25
 
26
- ## Warning
27
- Consider only the gems local to your system are scanned by the library.
28
- No remote fetching is performed.
29
-
30
26
  ## Installation
31
27
  Install the gem from your shell:
32
28
  ```shell
@@ -35,10 +31,25 @@ gem install lapidarius
35
31
 
36
32
  ## Usage
37
33
  This library invokes the `Gem::Commands::DependencyCommand` class recursively to collect all the levels of dependency.
38
- Both runtime and development dependencies are counted (identical dependencies are counted once).
39
- Just the runtime dependencies tree is printed to screen:
34
+ Both runtime and development dependencies are counted (identical dependencies are counted once), but just the former are printed on screen:
40
35
 
41
36
  ```shell
37
+ > lapidarius sinatra
38
+ sinatra (2.0.0)
39
+ ├── mustermann (~> 1.0)
40
+ ├── rack (~> 2.0)
41
+ ├── rack-protection (= 2.0.0)
42
+ │ └── rack (>= 0)
43
+ └── tilt (~> 2.0)
44
+
45
+ 4 runtime, 4 development
46
+ ```
47
+
48
+ ### Version
49
+ By default this library scans for the first version `>= 0` found at [rubygems.org](https://rubygems.org/).
50
+ In case you are interested on a specific version just specify the `-v` option:
51
+ ```shell
52
+ > lapidarius sinatra -v 1.4.7
42
53
  sinatra (1.4.7)
43
54
  ├── rack (~> 1.5)
44
55
  ├── rack-protection (~> 1.4)
@@ -48,17 +59,12 @@ sinatra (1.4.7)
48
59
  3 runtime, 4 development
49
60
  ```
50
61
 
51
- ### Version
52
- By default this library scans for the first version `>= 0`.
53
- In case you have multiple versions of a gem installed, just specify the version you need to cut as the second argument:
62
+ ### Remote
63
+ By default this library scan for local gems, if you want to scan for remote ones specify the `-r` option (be aware of slowness):
54
64
  ```shell
55
- $ lapidarius sinatra 2.0.0
56
- sinatra (2.0.0)
57
- ├── mustermann (~> 1.0)
58
- ├── rack (~> 2.0)
59
- ├── rack-protection (= 2.0.0)
60
- │ └── rack (>= 0)
61
- └── tilt (~> 2.0)
65
+ $ lapidarius roda -v 3.3.0 -r
66
+ roda (3.3.0)
67
+ └── rack (>= 0)
62
68
 
63
- 4 runtime, 4 development
69
+ 1 runtime, 10 development
64
70
  ```
data/bin/lapidarius CHANGED
@@ -4,4 +4,4 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  require "lapidarius"
6
6
 
7
- Lapidarius::CLI.new(ARGV.clone.first(2)).call
7
+ Lapidarius::CLI.new(args: ARGV.clone).call
@@ -1,47 +1,59 @@
1
+ require "optparse"
1
2
  require "lapidarius/cutter"
2
3
 
3
4
  module Lapidarius
4
5
  class CLI
5
6
  HELP_FLAGS = %w[-h --help]
6
- COL_WIDTH = 23
7
-
8
- attr_reader :name, :version
9
-
10
- def initialize(input,
11
- out = STDOUT,
12
- command = Command,
13
- cutter = Cutter,
14
- tree = Tree)
15
- @name, @version = Array(input).map(&:strip)
16
- @out = out
17
- @cutter = cutter.new(name: @name, cmd_klass: command, version: @version)
7
+
8
+ attr_reader :name, :version, :remote
9
+
10
+ def initialize(args: [], io: STDOUT, command: Command, cutter: Cutter, tree: Tree)
11
+ @args = args
12
+ @io = io
18
13
  @tree = tree
14
+ @command = command
15
+ @cutter = cutter
16
+ @name = @args.shift unless help?
17
+ parser.parse!(@args)
19
18
  end
20
19
 
21
20
  def call
22
- @out.puts output
21
+ @io.puts output
22
+ end
23
+
24
+ private def cutter
25
+ @cutter.new(name: @name, cmd_klass: @command, version: @version, remote: @remote)
23
26
  end
24
27
 
25
28
  private def output
26
- return help if help?
27
29
  return unless @name
28
- gem = @cutter.call
30
+ gem = cutter.call
29
31
  @tree::new(gem).to_s
30
32
  rescue Gem::NotInstalledError => e
31
33
  e.message
32
34
  end
33
35
 
34
- private def help?
35
- HELP_FLAGS.include?(@name)
36
- end
36
+ private def parser
37
+ OptionParser.new do |opts|
38
+ opts.banner = %q{Usage: lapidarius sinatra --version=1.4.7 --remote}
37
39
 
38
- private def help
39
- [].tap do |h|
40
- h << %q{Usage: lapidarius <name> <version>}
41
- h << " %-#{COL_WIDTH}s Print this help" % "-h --help"
42
- h << " %-#{COL_WIDTH}s Gem's name to cut" % "<name>"
43
- h << " %-#{COL_WIDTH}s Gem's version to cut" % "<version>"
40
+ opts.on("-vVERSION", "--version=VERSION", "Specify the gem version to cut") do |version|
41
+ @version = version
42
+ end
43
+
44
+ opts.on("-r", "--remote", "Fetch gem remotely") do |remote|
45
+ @remote = true
46
+ end
47
+
48
+ opts.on(*HELP_FLAGS, "Prints this help") do
49
+ @io.puts opts
50
+ exit
51
+ end
44
52
  end
45
53
  end
54
+
55
+ private def help?
56
+ HELP_FLAGS.any? { |h| @args.first == h }
57
+ end
46
58
  end
47
59
  end
@@ -11,11 +11,19 @@ module Lapidarius
11
11
  @dep.ui = ui_klass.new
12
12
  end
13
13
 
14
- def call(gem, version = nil)
14
+ def call(*args)
15
15
  @dep.ui.clear!
16
- version ? @dep.invoke(gem, '-v', version) : @dep.invoke(gem)
16
+ @dep.invoke(*options(args))
17
17
  @dep.ui.out
18
18
  end
19
+
20
+ private def options(args)
21
+ name, version, remote = args
22
+ [name].tap do |args|
23
+ args.concat(["-v", version]) if version
24
+ args.concat(["-b", "-B", "10000"]) if remote
25
+ end
26
+ end
19
27
  end
20
28
  end
21
29
 
@@ -6,12 +6,13 @@ module Lapidarius
6
6
  class Cutter
7
7
  DEVELOPMENT = "development"
8
8
 
9
- attr_reader :version
9
+ attr_reader :version, :remote
10
10
 
11
- def initialize(name:, cmd_klass: Command, version: nil)
11
+ def initialize(name:, cmd_klass: Command, version: nil, remote: nil)
12
12
  @name = name
13
13
  @cmd = cmd_klass.new
14
14
  @version = version
15
+ @remote = remote
15
16
  @dev_deps = []
16
17
  end
17
18
 
@@ -21,14 +22,14 @@ module Lapidarius
21
22
  end
22
23
  end
23
24
 
24
- private def recurse(name = @name, gem = nil, version = @version)
25
- tokens = tokenize(name, version)
25
+ private def recurse(name: @name, gem: nil, version: @version, remote: @remote)
26
+ tokens = tokenize(name, version, remote)
26
27
  token = tokens.shift
27
28
  gem ||= Gem.factory(token)
28
29
  tokens.each do |t|
29
30
  next unless dep = Gem.factory(t)
30
31
  gem << dep
31
- recurse(dep.name, dep, nil)
32
+ recurse(name: dep.name, gem: dep, version: nil, remote: remote)
32
33
  end
33
34
  gem
34
35
  end
@@ -37,8 +38,8 @@ module Lapidarius
37
38
  @dev_deps.map { |e| e.split(" ").first }.uniq.count
38
39
  end
39
40
 
40
- private def tokenize(name, version)
41
- src = @cmd.call(name, version)
41
+ private def tokenize(name, version, remote)
42
+ src = @cmd.call(name, version, remote)
42
43
  data = normalize(src)
43
44
  dev, tokens = data.partition { |token| token.match(/#{DEVELOPMENT}/) }
44
45
  @dev_deps.concat(dev)
@@ -1,3 +1,3 @@
1
1
  module Lapidarius
2
- VERSION = "3.4.0"
2
+ VERSION = "4.0.1"
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: 3.4.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler