lapidarius 4.4.4 → 4.5.5

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: 371cfce240008bc7e4489d05628a6bfbaefd1cf7a12d3552eba1c9f49e3f9a99
4
- data.tar.gz: 8f96713c52a33ef09bb1d5760574ec509ecea4d53c3addcf204c992b23edbae1
3
+ metadata.gz: 743d5d7b47e23ae05b54f761366dc7f7c6c8c03e082585f26be4e7a4fe965360
4
+ data.tar.gz: fb1e6fbf6e9e11e4ac6c3b96f6db20e73a95c477bb8662d736bea9d2ecf6b274
5
5
  SHA512:
6
- metadata.gz: 10bdff2a62137f652bb9f39e52e9e68421fb745ba4dd84f096662b9ce727a646b05f44fe8cb91fa706caba2da17c686e144d407e60ee5db26f708a9434fdd81a
7
- data.tar.gz: aa933fc490f31242e199743fd23c7b18d67e0c428d78e67d874d20a148755299b3ac99aeaad97d7dfd234f8c38a86a1910b177c32e372d26f63b519fdb889c8d
6
+ metadata.gz: '0909cbef4a840dbb432d603c00563a2da51968df8d27f3e865f1d86e6471dbbedbdc1306dbc1c35f735426a75652980506b378fa8447a38aa839262ca5c0426a'
7
+ data.tar.gz: 3e5898e9aa146c21063eb0dd30314c3c820f2875e3ef36e2a7610ed7248ce3474deeca415e2f275f759b757383ceb4b711186c59b9f233668f668e33373ffdbb
data/README.md CHANGED
@@ -31,7 +31,7 @@ gem install lapidarius
31
31
  ```
32
32
 
33
33
  ## Usage
34
- This library invokes the `Gem::Commands::DependencyCommand` class recursively to collect all the levels of dependency.
34
+ This library invokes the [Gem::Commands::DependencyCommand](https://github.com/rubygems/rubygems/blob/master/lib/rubygems/commands/dependency_command.rb) class recursively to collect all the levels of dependency.
35
35
  Both runtime and development dependencies are counted (identical dependencies are counted once), but just the former are printed on screen:
36
36
 
37
37
  ```shell
@@ -43,11 +43,11 @@ sinatra (2.0.0)
43
43
  │ └── rack (>= 0)
44
44
  └── tilt (~> 2.0)
45
45
 
46
- 4 runtime, 4 development
46
+ 4 runtime, 5 development
47
47
  ```
48
48
 
49
49
  ### Version
50
- By default this library scans for the first version `>= 0` found at [rubygems.org](https://rubygems.org/).
50
+ By default this library scans for the latest available version `>= 0` found at [rubygems.org](https://rubygems.org/).
51
51
  In case you are interested on a specific version just specify the `-v` option:
52
52
  ```shell
53
53
  lapidarius sinatra -v 1.4.7
@@ -63,35 +63,36 @@ sinatra (1.4.7)
63
63
  ### Remote
64
64
  By default this library scan for local gems, warning if the gem is not found:
65
65
  ```shell
66
- lapidarius rails -v 2.3.6
67
- No gems found matching rails (= 2.3.6)
66
+ lapidarius rails -v 1.2.6
67
+ No gems found matching rails (= 1.2.6)
68
68
  ```
69
69
 
70
70
  If you want to scan for remote gems specify the `-r` option (be aware of slowness):
71
71
  ```shell
72
- lapidarius rails -v 2.3.6 -r
73
- rails (2.3.6)
74
- ├── actionmailer (= 2.3.6)
75
- │ └── actionpack (= 2.3.6)
76
- ├── activesupport (= 2.3.6)
77
- │ └── rack (~> 1.1.0)
78
- ├── actionpack (= 2.3.6)
79
- ├── activesupport (= 2.3.6)
80
- └── rack (~> 1.1.0)
81
- ├── activerecord (= 2.3.6)
82
- │ └── activesupport (= 2.3.6)
83
- ├── activeresource (= 2.3.6)
84
- │ └── activesupport (= 2.3.6)
85
- ├── activesupport (= 2.3.6)
86
- └── rake (>= 0.8.3)
72
+ lapidarius rails -v 1.2.6 -r
73
+ rails (1.2.6)
74
+ ├── actionmailer (= 1.3.6)
75
+ │ └── actionpack (= 1.13.6)
76
+ └── activesupport (= 1.4.4)
77
+ ├── actionpack (= 1.13.6)
78
+ │ └── activesupport (= 1.4.4)
79
+ ├── actionwebservice (= 1.2.6)
80
+ ├── actionpack (= 1.13.6)
81
+ │ │ └── activesupport (= 1.4.4)
82
+ │ └── activerecord (= 1.15.6)
83
+ │ └── activesupport (= 1.4.4)
84
+ ├── activerecord (= 1.15.6)
85
+ │ └── activesupport (= 1.4.4)
86
+ ├── activesupport (= 1.4.4)
87
+ └── rake (>= 0.7.2)
87
88
 
88
- 7 runtime, 6 development
89
+ 6 runtime, 5 development
89
90
  ```
90
91
 
91
92
  ### Quiet
92
93
  Some gems have several interdependencies that results in a multitude of tree branches.
93
94
  In case you just dare to count dependencies without the visual noise, you can pass the `-q` option:
94
95
  ```shell
95
- lapidarius rails -v 5.1.4 -r -q
96
- 42 runtime, 48 development
96
+ lapidarius rails -v 5.1.5 -r -q
97
+ 37 runtime, 48 development
97
98
  ```
@@ -7,34 +7,29 @@ module Lapidarius
7
7
 
8
8
  attr_reader :name, :version, :remote
9
9
 
10
- def initialize(args: [], io: STDOUT, command: Command, cutter: Cutter,
11
- tree: Tree, spinner: Spinner.new)
10
+ def initialize(args: [], io: STDOUT, command: Command, cutter: Cutter, tree: Tree)
12
11
  @args = args
13
12
  @io = io
14
13
  @command = command
15
14
  @cutter = cutter
16
15
  @tree = tree
17
- @spinner = spinner
18
16
  @name = @args.shift unless help?
19
17
  parser.parse!(@args)
20
18
  end
21
19
 
22
20
  def call
23
- @spinner.call do
24
- @output = cut
25
- end
26
- @io.puts @output
21
+ @io.puts out
27
22
  end
28
23
 
29
24
  private def cutter
30
25
  @cutter.new(name: @name, cmd_klass: @command, version: @version, remote: @remote)
31
26
  end
32
27
 
33
- private def cut
28
+ private def out
34
29
  return unless @name
35
30
  gem = cutter.call
36
31
  @tree::new(gem, @quiet).out
37
- rescue Gem::NotInstalledError => e
32
+ rescue Gem::NotInstalledError, Gem::KindError => e
38
33
  e.message
39
34
  end
40
35
 
@@ -65,31 +60,4 @@ module Lapidarius
65
60
  HELP_FLAGS.any? { |h| @args.first == h }
66
61
  end
67
62
  end
68
-
69
- class Spinner
70
- CHARS = %w[| / - \\]
71
-
72
- def initialize(io = STDOUT, fps = 15, delay = 1.0)
73
- @io = io
74
- @fps = fps.to_i
75
- @delay = delay.to_f / @fps
76
- @iter = 0
77
- end
78
-
79
- def call
80
- spinner = Thread.new do
81
- while @iter do
82
- @io.print CHARS[(@iter+=1) % CHARS.length]
83
- sleep @delay
84
- @io.print "\b"
85
- @io.flush
86
- end
87
- end
88
- ensure
89
- yield.tap do
90
- @iter = false
91
- spinner.join
92
- end
93
- end
94
- end
95
63
  end
@@ -24,32 +24,36 @@ module Lapidarius
24
24
 
25
25
  private def recurse(name: @name, gem: nil, version: @version)
26
26
  tokens = tokenize(name, version, @remote)
27
- token = tokens.shift
28
- gem ||= Gem.factory(token)
29
- tokens.each do |t|
30
- next unless dep = Gem.factory(t)
31
- gem << @cache.fetch(t) do
32
- recurse(name: dep.name, gem: dep, version: dep.version)
33
- @cache[t] = dep
34
- end
27
+ parent = tokens.shift
28
+ gem ||= Gem.factory(parent)
29
+ tokens.reduce(gem) do |acc, token|
30
+ acc << dependency(token); acc
35
31
  end
36
- gem
37
32
  end
38
33
 
39
34
  def dev_count
40
35
  @dev_deps.map { |e| e.split(" ").first }.uniq.count
41
36
  end
42
37
 
38
+ private def dependency(token)
39
+ @cache.fetch(token) do
40
+ Gem.factory(token).tap do |dep|
41
+ recurse(name: dep.name, gem: dep, version: dep.version)
42
+ @cache[token] = dep
43
+ end
44
+ end
45
+ end
46
+
43
47
  private def tokenize(name, version, remote)
44
48
  src = @cmd.call(name, version, remote)
45
- data = normalize(src)
49
+ data = latest_match(src)
46
50
  dev, tokens = data.partition { |token| token.match(/#{DEVELOPMENT}/) }
47
51
  @dev_deps.concat(dev)
48
52
  tokens
49
53
  end
50
54
 
51
- private def normalize(src)
52
- src.split(/\n\n/).map!(&:strip).first.split("\n").map(&:strip)
55
+ private def latest_match(src)
56
+ src.split(/\n\n/).map!(&:strip).last.split("\n").map(&:strip)
53
57
  end
54
58
  end
55
59
  end
@@ -3,7 +3,8 @@ require "lapidarius/tree"
3
3
 
4
4
  module Lapidarius
5
5
  class Gem
6
- VER_STRIP_CHARS = %w[> < = ~ !]
6
+ INVALID_VER_CHARS = %w[> < = ~ !]
7
+ DEFAULT_VER = ">= 0"
7
8
 
8
9
  extend Forwardable
9
10
 
@@ -22,9 +23,10 @@ module Lapidarius
22
23
  token.match(/([a-zA-Z0-9\-_]+) \((.+)\)/) do |m|
23
24
  return new(name: m[1], version: m[2])
24
25
  end
26
+ fail KindError, "no gem can be created from #{token}"
25
27
  end
26
28
 
27
- attr_reader :name, :deps
29
+ attr_reader :name, :deps, :version
28
30
  attr_accessor :dev_count
29
31
 
30
32
  def initialize(name:, version:, deps: [])
@@ -51,17 +53,8 @@ module Lapidarius
51
53
  flatten_deps.size
52
54
  end
53
55
 
54
- def version
55
- @version.gsub(/#{VER_STRIP_CHARS.join("|")}/, "").split(",").map(&:strip).min
56
- end
57
-
58
56
  protected def flatten_deps
59
- deps.reduce(deps) do |acc, dep|
60
- acc.concat dep.flatten_deps
61
- end.tap do |deps|
62
- deps.flatten!
63
- deps.uniq!(&:name)
64
- end
57
+ deps.reduce(deps) { |acc, dep| acc.concat dep.flatten_deps }.flatten.uniq(&:name)
65
58
  end
66
59
 
67
60
  private def gem?(gem)
@@ -1,3 +1,3 @@
1
1
  module Lapidarius
2
- VERSION = "4.4.4"
2
+ VERSION = "4.5.5"
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: 4.4.4
4
+ version: 4.5.5
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-14 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler