bundler-stats 2.3.0 → 2.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
2
  SHA256:
3
- metadata.gz: 38f866872f6ba724ee82db46ba1715c05bcf8f22272f0ae6a23a96b1760232ce
4
- data.tar.gz: ee9b4655d4c8faa1da7f23d3602820ab70eeaf10aad836f4bc7c544cd10bf795
3
+ metadata.gz: 8ecad684af63a04d936d307b3b165a0273b82ec21e7caab0b7473d2a3017fa35
4
+ data.tar.gz: f2564f384b1b5df0b3be76ad95b4cc67091f5f65b7d442c6f7ee0513ea14cc00
5
5
  SHA512:
6
- metadata.gz: e31cce716bfae8bdc92e525d1047678b96c4ea18f80aee2875718f84c690a8a76dbd34ee923b445724716f45eb0e9cdbeab69e13b0d6479284cb4a1185beeecf
7
- data.tar.gz: 2644320effea69f6e117a92154e3ddf0e0a3327a23d8141262dc4138fefa8a8a84eab049e68686ded2f778d2b271cbf8a00c43a6eb2b9fa06c09d01b11ce694d
6
+ metadata.gz: c58e25a9360895d6727a46b7e0f4399b28bcc34d9eb5afd06db5f814511a69dfa0bfd4fec5383f769df987ab74fe8fc45b1514327468be1664f37d5f4c54e626
7
+ data.tar.gz: e2dbf4e320175d710add987c485f4e3491da9ff4d2d8ddee96328d0335444e312f88f2ab499f8b079828316a2254422a38465730587dd6a828f8498279a1a06d
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Changelog
2
2
  =============
3
3
 
4
+ ## [2.4.0] - 2023-07-01
5
+
6
+ ### Added
7
+ - Make it possible to specify custom path for gem/Gemfile.
8
+
4
9
  ## [2.3.0] - 2022-02-12
5
10
 
6
11
  ### Added
data/README.md CHANGED
@@ -237,6 +237,14 @@ To consume information with a build job or somesuch, all commands can emit JSON.
237
237
  ]
238
238
  }
239
239
 
240
+ ### Custom Gemfile path
241
+
242
+ This gem by default attempts to locate the Gemfile and Gemfile.lock files in parent directories. If you want to specify a specific location for your Gemfile/gems.rb file, you can use the `--gemfile_path` option.
243
+
244
+ > bundle-stats show sass-rails --gemfile_path=/Users/user/project/Gemfile
245
+
246
+ Keep in mind that the location of the Gemfile.lock/gems.locked file will be inferred from the location of the Gemfile/gems.rb file.
247
+
240
248
  Contributing
241
249
  ------------
242
250
 
@@ -13,6 +13,7 @@ module Bundler
13
13
  desc 'stats', 'Displays basic stats about the gems in your Gemfile'
14
14
  method_option :format, aliases: "-f", description: "Output format, either JSON or text"
15
15
  method_option :nofollow, description: "A comma delimited list of dependencies not to follow."
16
+ method_option :gemfile_path, description: "Custom path for Gemfile/gems.rb and Gemfile.lock/gems.locked"
16
17
  def stats
17
18
  calculator = build_calculator(options)
18
19
  stats = calculator.stats
@@ -27,6 +28,7 @@ module Bundler
27
28
  desc 'show TARGET', 'Prints the dependency tree for a single gem in your Gemfile'
28
29
  method_option :format, aliases: "-f", description: "Output format, either JSON or text"
29
30
  method_option :nofollow, description: "A comma delimited list of dependencies not to follow."
31
+ method_option :gemfile_path, description: "Custom path for Gemfile/gems.rb and Gemfile.lock/gems.locked"
30
32
  def show(target)
31
33
  calculator = build_calculator(options)
32
34
  stats = calculator.summarize(target)
@@ -41,6 +43,7 @@ module Bundler
41
43
  desc 'versions TARGET', 'Shows versions requirements for target in other dependencies'
42
44
  method_option :format, aliases: "-f", description: "Output format, either JSON or text"
43
45
  method_option :nofollow, description: "A comma delimited list of dependencies not to follow."
46
+ method_option :gemfile_path, description: "Custom path for Gemfile/gems.rb and Gemfile.lock/gems.locked"
44
47
  def versions(target)
45
48
  calculator = build_calculator(options)
46
49
  stats = calculator.versions(target)
@@ -122,29 +125,15 @@ module Bundler
122
125
 
123
126
  def build_calculator(options)
124
127
  skiplist = Bundler::Stats::Skiplist.new(options[:nofollow])
125
- @calculator ||= Bundler::Stats::Calculator.new(gemfile_path, lockfile_path, skiplist)
128
+ @calculator ||= Bundler::Stats::Calculator.new(
129
+ file_path_resolver.gemfile_path,
130
+ file_path_resolver.lockfile_path,
131
+ skiplist
132
+ )
126
133
  end
127
134
 
128
- def gemfile_path
129
- cwd = Pathname.new("./")
130
- until cwd.realdirpath.root? do
131
- %w(gems.rb Gemfile).each do |gemfile|
132
- return (cwd + gemfile) if File.exist?(cwd + gemfile)
133
- end
134
- cwd = cwd.parent
135
- end
136
- raise ArgumentError, "Couldn't find gems.rb nor Gemfile in this directory or parents"
137
- end
138
-
139
- def lockfile_path
140
- cwd = Pathname.new(".")
141
- until cwd.realdirpath.root? do
142
- %w(gems.locked Gemfile.lock).each do |lockfile|
143
- return (cwd + lockfile) if File.exist?(cwd + lockfile)
144
- end
145
- cwd = cwd.parent
146
- end
147
- raise ArgumentError, "Couldn't find gems.locked nor Gemfile.lock in this directory or parents"
135
+ def file_path_resolver
136
+ @file_path_resolver ||= Bundler::Stats::FilePathResolver.new(options[:gemfile_path])
148
137
  end
149
138
  end
150
139
  end
@@ -0,0 +1,56 @@
1
+ module Bundler
2
+ module Stats
3
+ class FilePathResolver
4
+ FILES_MAP = {
5
+ "gems.rb" => "gems.locked",
6
+ "Gemfile" => "Gemfile.lock"
7
+ }
8
+
9
+ def initialize(specific_gemfile_path = nil)
10
+ @specific_gemfile_path = specific_gemfile_path
11
+ end
12
+
13
+ def gemfile_path
14
+ resolve_file_path(FILES_MAP.keys, specific_gemfile_path)
15
+ end
16
+
17
+ def lockfile_path
18
+ resolve_file_path(FILES_MAP.values, resolve_lockfile_path)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :specific_gemfile_path
24
+
25
+ def resolve_lockfile_path
26
+ return unless specific_gemfile_path
27
+
28
+ file_path = Pathname.new(specific_gemfile_path)
29
+ file_name = file_path.basename.to_s
30
+ locked_file_name = FILES_MAP[file_name]
31
+ raise ArgumentError, "Invalid file name: #{file_name}" if locked_file_name.nil?
32
+ file_path.dirname.join(locked_file_name).to_s
33
+ end
34
+
35
+ def resolve_file_path(file_names, custom_path)
36
+ if custom_path
37
+ raise ArgumentError, "Couldn't find #{custom_path} file path" unless File.exist?(custom_path)
38
+ return custom_path
39
+ end
40
+
41
+ find_file_path(file_names)
42
+ end
43
+
44
+ def find_file_path(file_names)
45
+ cwd = Pathname.new(".")
46
+ until cwd.realdirpath.root? do
47
+ file_names.each do |file|
48
+ return (cwd + file).to_s if File.exist?(cwd + file)
49
+ end
50
+ cwd = cwd.parent
51
+ end
52
+ raise ArgumentError, "Couldn't find #{file_names.join(" nor ")} in this directory or parents"
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  module Bundler
2
2
  module Stats
3
- VERSION = '2.3.0'
3
+ VERSION = '2.4.0'
4
4
  end
5
5
  end
data/lib/bundler/stats.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'stats/calculator'
2
+ require_relative 'stats/file_path_resolver'
2
3
  require_relative 'stats/printer'
3
4
  require_relative 'stats/remover'
4
5
  require_relative 'stats/skiplist'
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bundler::Stats::FilePathResolver do
4
+ let(:file_path_resolver) { described_class.new(specific_gemfile_path) }
5
+
6
+ context "with undefined specific gemfile path" do
7
+ let(:specific_gemfile_path) { nil }
8
+
9
+ before do
10
+ allow(File).to receive(:exist?).and_return(false)
11
+ end
12
+
13
+ context "without files found" do
14
+ it do
15
+ expect { file_path_resolver.gemfile_path }.to raise_error(
16
+ ArgumentError, "Couldn't find gems.rb nor Gemfile in this directory or parents"
17
+ )
18
+ end
19
+
20
+ it do
21
+ expect { file_path_resolver.lockfile_path }.to raise_error(
22
+ ArgumentError, "Couldn't find gems.locked nor Gemfile.lock in this directory or parents"
23
+ )
24
+ end
25
+ end
26
+
27
+ context "with files found" do
28
+ before do
29
+ allow(File).to receive(:exist?).with(Pathname.new("../Gemfile")).and_return(true)
30
+ allow(File).to receive(:exist?).with(Pathname.new("../../gems.locked")).and_return(true)
31
+ end
32
+
33
+ it { expect(file_path_resolver.gemfile_path).to eq("../Gemfile") }
34
+ it { expect(file_path_resolver.lockfile_path).to eq("../../gems.locked") }
35
+ end
36
+ end
37
+
38
+ context "with specific gemfile path" do
39
+ let(:specific_gemfile_path) { "some-project/Gemfile" }
40
+
41
+ context "with valid file path" do
42
+ before do
43
+ allow(File).to receive(:exist?).and_return(true)
44
+ end
45
+
46
+ it { expect(file_path_resolver.gemfile_path).to eq("some-project/Gemfile") }
47
+ it { expect(file_path_resolver.lockfile_path).to eq("some-project/Gemfile.lock") }
48
+
49
+ context "with gems.rb file" do
50
+ let(:specific_gemfile_path) { "some-project/gems.rb" }
51
+
52
+ it { expect(file_path_resolver.gemfile_path).to eq("some-project/gems.rb") }
53
+ it { expect(file_path_resolver.lockfile_path).to eq("some-project/gems.locked") }
54
+ end
55
+
56
+ context "with invalid file name" do
57
+ let(:specific_gemfile_path) { "some-project/yeimfile" }
58
+
59
+ it do
60
+ expect { file_path_resolver.lockfile_path }.to raise_error(
61
+ ArgumentError, "Invalid file name: yeimfile"
62
+ )
63
+ end
64
+ end
65
+ end
66
+
67
+ context "with invalid file path" do
68
+ before do
69
+ allow(File).to receive(:exist?).and_return(false)
70
+ end
71
+
72
+ it do
73
+ expect { file_path_resolver.gemfile_path }.to raise_error(
74
+ ArgumentError, "Couldn't find some-project/Gemfile file path"
75
+ )
76
+ end
77
+
78
+ it do
79
+ expect { file_path_resolver.lockfile_path }.to raise_error(
80
+ ArgumentError, "Couldn't find some-project/Gemfile.lock file path"
81
+ )
82
+ end
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Mastey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-13 00:00:00.000000000 Z
11
+ date: 2023-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,12 +148,14 @@ files:
148
148
  - lib/bundler/stats.rb
149
149
  - lib/bundler/stats/calculator.rb
150
150
  - lib/bundler/stats/cli.rb
151
+ - lib/bundler/stats/file_path_resolver.rb
151
152
  - lib/bundler/stats/printer.rb
152
153
  - lib/bundler/stats/remover.rb
153
154
  - lib/bundler/stats/skiplist.rb
154
155
  - lib/bundler/stats/tree.rb
155
156
  - lib/bundler/stats/version.rb
156
157
  - spec/lib/bundler/stats/calculator_spec.rb
158
+ - spec/lib/bundler/stats/file_path_resolver_spec.rb
157
159
  - spec/lib/bundler/stats/printer_spec.rb
158
160
  - spec/lib/bundler/stats/remover_spec.rb
159
161
  - spec/lib/bundler/stats/tree_spec.rb