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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30269020c86fa6f75cb9f79d2dc1bc1aedffc0825f1e847e31910226d173b0ba
4
- data.tar.gz: 2ccdaa16e32999bd55be285cb831f6430848970e1c6ceef7a1049101fa8364f4
3
+ metadata.gz: 705bb25abef68815226829e668898018d40da2b472e84e6afb462e07c0634350
4
+ data.tar.gz: 848dad272c218c10632b87459ecfb7f96ede0888e602d4b119e9df8c5140da87
5
5
  SHA512:
6
- metadata.gz: 40a048bb2e8e6b7d8b05346a03d7d6eed6f7c2ad636e845e2b919f99286793661e7fd83626b9048eeeab7cadb2810c78cf40e26c9a47816abdd86357a8f494ad
7
- data.tar.gz: 7f9afbb816f26e7a10be12bd953453b15f93c36999e95e7b536a4c5d43937593c0811a90d70f35e82e08e81e46a915bfcdcea1261f8ad5dbb2da89293aa5853e
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
- exec "bundle", "_#{version}_", *ARGV
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
@@ -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
- return unless requirement = bundler_requirement(gemfile_content)
8
+ requirements = bundler_requirements(gemfile_content)
9
+ return if requirements.empty? # just use whatever
9
10
 
10
- if version = find_matching_local_bundler_version(requirement)
11
- warn "Found bundler #{version}"
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
- return unless version = find_matching_remote_bundler_version(requirement)
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(requirement)
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(requirement, versions)
31
+ find_satisfied(requirements, versions)
28
32
  end
29
33
 
30
- def find_matching_local_bundler_version(requirement)
31
- find_satisfied(requirement, installed_bundler_versions)
34
+ def find_matching_local_bundler_version(requirements)
35
+ find_satisfied(requirements, installed_bundler_versions)
32
36
  end
33
37
 
34
- def find_satisfied(requirement, versions)
35
- requirement = Gem::Requirement.new(requirement)
36
- versions.find do |version|
37
- requirement.satisfied_by? Gem::Version.new(version)
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 bundler_requirement(gemfile_content)
48
- found = gemfile_content.scan(/^\s*bundler \((.*)\)/)
49
- versions = found.map(&:last)
50
- versions.grep(/^=\s*\d/).first || versions.first
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module MatchingBundle
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.5"
4
4
  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.0
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: 2019-06-01 00:00:00.000000000 Z
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
- rubyforge_project:
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