lapidarius 3.3.0 → 3.4.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
- SHA1:
3
- metadata.gz: 268fbbb37aad0f18ae71017ff634a75f3d8a4bf4
4
- data.tar.gz: bcd7b8100f25e2bd669a89a181d19a613da03a18
2
+ SHA256:
3
+ metadata.gz: 8e47ba3f42ec60db9d0842f79b8289326e8654f10d0ec7d8893c23be55fc16bb
4
+ data.tar.gz: ef2ea270800d9f78102e03b271da4faca4014ebfb2732162789d9fc1d586dc20
5
5
  SHA512:
6
- metadata.gz: ca1312eb554fa5a9678e5cd73f4a5c955740ee787e243d427940f72f1da05303625165a65d8f4229c9f6af499c3d75946aef8cc05064acdaecbed07153290d35
7
- data.tar.gz: edc16c5b9cea8e4aff955c76ca4e76823108df62bbbbdc6330cf3bdad87df85e6a11a2d5adc96df5001537828f9d6a70ebfd99e3b5261eb31d9c8c86a5ee11d2
6
+ metadata.gz: e481ada2be52866b19189925b0a222f08cd2810e878b9d78f22fce46432a58cf7d19014e8c2de036043e13db451d058dca43120d40b7147a69415805fc87d60d
7
+ data.tar.gz: acf4e8bee952dfc6138e5830dc031e1892bd1c460b7f434f3a803ae2119abc06e1ceceec33de6b80afce2d5f5c00cb1a0d3a011ce554dbbd3066c4d646b1d698
data/README.md CHANGED
@@ -7,6 +7,7 @@
7
7
  * [Warning](#warning)
8
8
  * [Installation](#installation)
9
9
  * [Usage](#usage)
10
+ * [Version](#version)
10
11
 
11
12
  ## Scope
12
13
  This gem is aimed to recursively collect the `runtime dependencies` footprint of the specified gem.
@@ -23,7 +24,7 @@ The *bundle viz* command relies on the Gemfile and the [graphviz](http://www.gra
23
24
  While it is great to visualize inter-dependencies, i have hard times figuring out gem's runtime footprint.
24
25
 
25
26
  ## Warning
26
- Consider only the gems installed on your system are scanned by the library.
27
+ Consider only the gems local to your system are scanned by the library.
27
28
  No remote fetching is performed.
28
29
 
29
30
  ## Installation
@@ -38,7 +39,20 @@ Both runtime and development dependencies are counted (identical dependencies ar
38
39
  Just the runtime dependencies tree is printed to screen:
39
40
 
40
41
  ```shell
41
- $ lapidarius sinatra
42
+ sinatra (1.4.7)
43
+ ├── rack (~> 1.5)
44
+ ├── rack-protection (~> 1.4)
45
+ │ └── rack (>= 0)
46
+ └── tilt (< 3, >= 1.3)
47
+
48
+ 3 runtime, 4 development
49
+ ```
50
+
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:
54
+ ```shell
55
+ $ lapidarius sinatra 2.0.0
42
56
  sinatra (2.0.0)
43
57
  ├── mustermann (~> 1.0)
44
58
  ├── rack (~> 2.0)
data/bin/lapidarius CHANGED
@@ -4,5 +4,4 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  require "lapidarius"
6
6
 
7
- input = ARGV.fetch(0, "")
8
- Lapidarius::CLI.new(input).call
7
+ Lapidarius::CLI.new(ARGV.clone.first(2)).call
@@ -5,39 +5,42 @@ module Lapidarius
5
5
  HELP_FLAGS = %w[-h --help]
6
6
  COL_WIDTH = 23
7
7
 
8
+ attr_reader :name, :version
9
+
8
10
  def initialize(input,
9
- pipe = STDOUT,
11
+ out = STDOUT,
10
12
  command = Command,
11
13
  cutter = Cutter,
12
14
  tree = Tree)
13
- @input = input.to_s.strip
14
- @pipe = pipe
15
- @cutter = cutter.new(@input, command)
15
+ @name, @version = Array(input).map(&:strip)
16
+ @out = out
17
+ @cutter = cutter.new(name: @name, cmd_klass: command, version: @version)
16
18
  @tree = tree
17
19
  end
18
20
 
19
21
  def call
20
- @pipe.puts output
22
+ @out.puts output
21
23
  end
22
24
 
23
25
  private def output
24
26
  return help if help?
25
- return if @input.empty?
27
+ return unless @name
26
28
  gem = @cutter.call
27
- @tree::new(gem).out
29
+ @tree::new(gem).to_s
28
30
  rescue Gem::NotInstalledError => e
29
- e.message.sub("specified", %Q{"#{@input}"})
31
+ e.message
30
32
  end
31
33
 
32
34
  private def help?
33
- HELP_FLAGS.include?(@input)
35
+ HELP_FLAGS.include?(@name)
34
36
  end
35
37
 
36
38
  private def help
37
39
  [].tap do |h|
38
- h << %q{Usage: lapidarius sinatra}
40
+ h << %q{Usage: lapidarius <name> <version>}
39
41
  h << " %-#{COL_WIDTH}s Print this help" % "-h --help"
40
- h << " %-#{COL_WIDTH}s Gem's name to cut" % "<gem-name>"
42
+ h << " %-#{COL_WIDTH}s Gem's name to cut" % "<name>"
43
+ h << " %-#{COL_WIDTH}s Gem's version to cut" % "<version>"
41
44
  end
42
45
  end
43
46
  end
@@ -1,16 +1,19 @@
1
1
  require "rubygems/commands/dependency_command"
2
+ require "rubygems/requirement"
2
3
  require "lapidarius/ui"
3
4
 
4
5
  module Lapidarius
5
6
  class Command
7
+ attr_reader :dep
8
+
6
9
  def initialize(dep_klass: ::Gem::Commands::DependencyCommand, ui_klass: UI)
7
10
  @dep = dep_klass.new
8
11
  @dep.ui = ui_klass.new
9
12
  end
10
13
 
11
- def call(gem)
14
+ def call(gem, version = nil)
12
15
  @dep.ui.clear!
13
- @dep.invoke(gem)
16
+ version ? @dep.invoke(gem, '-v', version) : @dep.invoke(gem)
14
17
  @dep.ui.out
15
18
  end
16
19
  end
@@ -1,13 +1,17 @@
1
1
  require "lapidarius/gem"
2
2
  require "lapidarius/command"
3
+ require "rubygems/requirement"
3
4
 
4
5
  module Lapidarius
5
6
  class Cutter
6
7
  DEVELOPMENT = "development"
7
8
 
8
- def initialize(name, cmd_klass = Command)
9
+ attr_reader :version
10
+
11
+ def initialize(name:, cmd_klass: Command, version: nil)
9
12
  @name = name
10
13
  @cmd = cmd_klass.new
14
+ @version = version
11
15
  @dev_deps = []
12
16
  end
13
17
 
@@ -17,14 +21,14 @@ module Lapidarius
17
21
  end
18
22
  end
19
23
 
20
- private def recurse(name = @name, gem = nil)
21
- tokens = tokenize(name)
24
+ private def recurse(name = @name, gem = nil, version = @version)
25
+ tokens = tokenize(name, version)
22
26
  token = tokens.shift
23
27
  gem ||= Gem.factory(token)
24
28
  tokens.each do |t|
25
29
  next unless dep = Gem.factory(t)
26
30
  gem << dep
27
- recurse(dep.name, dep)
31
+ recurse(dep.name, dep, nil)
28
32
  end
29
33
  gem
30
34
  end
@@ -33,8 +37,8 @@ module Lapidarius
33
37
  @dev_deps.map { |e| e.split(" ").first }.uniq.count
34
38
  end
35
39
 
36
- private def tokenize(name)
37
- src = @cmd.call(name)
40
+ private def tokenize(name, version)
41
+ src = @cmd.call(name, version)
38
42
  data = normalize(src)
39
43
  dev, tokens = data.partition { |token| token.match(/#{DEVELOPMENT}/) }
40
44
  @dev_deps.concat(dev)
@@ -12,7 +12,7 @@ module Lapidarius
12
12
 
13
13
  def self.factory(token)
14
14
  token.match(/^No gems found matching/) do |m|
15
- fail NotInstalledError, "no version of specified gem installed"
15
+ fail NotInstalledError, token
16
16
  end
17
17
  token.match(/Gem ([a-zA-Z0-9\-_]+)-(.+)/) do |m|
18
18
  return new(name: m[1], version: m[2])
@@ -10,7 +10,7 @@ module Lapidarius
10
10
  @out = []
11
11
  end
12
12
 
13
- def out
13
+ def to_s
14
14
  return @out unless @out.empty?
15
15
  @out.tap do |out|
16
16
  out << @gem
@@ -1,3 +1,3 @@
1
1
  module Lapidarius
2
- VERSION = "3.3.0"
2
+ VERSION = "3.4.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: 3.3.0
4
+ version: 3.4.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-10-26 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  requirements: []
99
99
  rubyforge_project:
100
- rubygems_version: 2.6.11
100
+ rubygems_version: 2.7.5
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: A tiny library to visualize and count gem dependencies recursively