matching_bundle 0.3.0 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/matching_bundle +8 -1
- data/lib/matching_bundle.rb +30 -16
- data/lib/matching_bundle/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 705bb25abef68815226829e668898018d40da2b472e84e6afb462e07c0634350
|
4
|
+
data.tar.gz: 848dad272c218c10632b87459ecfb7f96ede0888e602d4b119e9df8c5140da87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c70324b3b09871d77c1d392201bccae47408ddfb382a005c6f2814a4ee578e26478a5518c89fff3d4f60204cafa3494edc40cd2eacf146562c945783beb94166
|
7
|
+
data.tar.gz: ac6d9184aa5630526c4a966fb401393a096c2ad77a5e91681cd95671983a82af9eab38ae1d5bb1a5ff49eaa8e975dc86848fc9c0f7dd6edcb7ff0482a5bfbb00
|
data/bin/matching_bundle
CHANGED
@@ -18,6 +18,13 @@ else
|
|
18
18
|
end
|
19
19
|
|
20
20
|
require 'matching_bundle'
|
21
|
+
# require_relative '../lib/matching_bundle' # use this for local debugging
|
21
22
|
if version = MatchingBundle.find_or_install_matching_version(content)
|
22
|
-
|
23
|
+
# some gem/ruby combinations do not support `bundle _1.2.3_` and exists with 0
|
24
|
+
if `bundle _#{version}_ --version 2>&1`.include?("Could not find command")
|
25
|
+
warn "Unable to use _#{version}_, falling back to default version"
|
26
|
+
else
|
27
|
+
exec "bundle", "_#{version}_", *ARGV
|
28
|
+
end
|
23
29
|
end
|
30
|
+
exec "bundle", *ARGV
|
data/lib/matching_bundle.rb
CHANGED
@@ -5,14 +5,18 @@ require 'json'
|
|
5
5
|
module MatchingBundle
|
6
6
|
class << self
|
7
7
|
def find_or_install_matching_version(gemfile_content)
|
8
|
-
|
8
|
+
requirements = bundler_requirements(gemfile_content)
|
9
|
+
return if requirements.empty? # just use whatever
|
9
10
|
|
10
|
-
if version = find_matching_local_bundler_version(
|
11
|
-
warn "
|
11
|
+
if version = find_matching_local_bundler_version(requirements)
|
12
|
+
warn "Using installed bundler #{version}"
|
12
13
|
return version
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
unless version = find_matching_remote_bundler_version(requirements)
|
17
|
+
warn "No remote version of bundler satisfies #{requirements.join(", ")}"
|
18
|
+
return
|
19
|
+
end
|
16
20
|
|
17
21
|
warn "Installing bundler #{version}"
|
18
22
|
abort unless system "gem", "install", "bundler", "-v", version
|
@@ -21,21 +25,22 @@ module MatchingBundle
|
|
21
25
|
|
22
26
|
private
|
23
27
|
|
24
|
-
def find_matching_remote_bundler_version(
|
28
|
+
def find_matching_remote_bundler_version(requirements)
|
25
29
|
json = open('https://rubygems.org/api/v1/versions/bundler.json').read
|
26
30
|
versions = JSON.load(json).map { |v| v["number"] }
|
27
|
-
find_satisfied(
|
31
|
+
find_satisfied(requirements, versions)
|
28
32
|
end
|
29
33
|
|
30
|
-
def find_matching_local_bundler_version(
|
31
|
-
find_satisfied(
|
34
|
+
def find_matching_local_bundler_version(requirements)
|
35
|
+
find_satisfied(requirements, installed_bundler_versions)
|
32
36
|
end
|
33
37
|
|
34
|
-
def find_satisfied(
|
35
|
-
requirement = Gem::Requirement.new(
|
36
|
-
versions.find do |version|
|
37
|
-
requirement.satisfied_by?
|
38
|
+
def find_satisfied(requirements, versions)
|
39
|
+
requirement = Gem::Requirement.new(*requirements)
|
40
|
+
version = versions.map { |v| Gem::Version.new(v) }.sort!.reverse!.find do |version|
|
41
|
+
requirement.satisfied_by? version
|
38
42
|
end
|
43
|
+
version.to_s if version
|
39
44
|
end
|
40
45
|
|
41
46
|
def installed_bundler_versions
|
@@ -44,10 +49,19 @@ module MatchingBundle
|
|
44
49
|
map { |spec| spec.version.to_s }
|
45
50
|
end
|
46
51
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
def bundler_requirements(gemfile_content)
|
53
|
+
requirements =
|
54
|
+
gemfile_content.
|
55
|
+
split("Current Bundler version").first.to_s.
|
56
|
+
scan(/^\s*bundler \((.*)\)/).flatten.
|
57
|
+
flat_map { |r| r.split(", ") }
|
58
|
+
|
59
|
+
# saw 2.2.16 fail on 2.2.3 ... so we need exact match
|
60
|
+
if gemfile_content =~ /BUNDLED WITH\n\s+(.*)/
|
61
|
+
requirements << "= #{$1}"
|
62
|
+
end
|
63
|
+
|
64
|
+
requirements
|
51
65
|
end
|
52
66
|
end
|
53
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matching_bundle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -40,8 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
|
44
|
-
rubygems_version: 2.7.6
|
43
|
+
rubygems_version: 3.2.16
|
45
44
|
signing_key:
|
46
45
|
specification_version: 4
|
47
46
|
summary: Find a matching bundler version for a Gemfile and use it
|