matching_bundle 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c325e084ef5d4a47be0353744890c55ac6a6417f97be782fc0e9ab83a225c81
4
+ data.tar.gz: 12cfb626462e676a0146c3da6d4886b100f6655264ab0e25bbefef987ca883a6
5
+ SHA512:
6
+ metadata.gz: 9e2c9488240f5d66975d478fb9aad69f37a4a2224946307ebecb8ff2962b276936d05c9f86b420da73babef388b39a51bd760317d998f748da6bd6ef41659f36
7
+ data.tar.gz: d6528958b3ce5a81a0f012346766c05206d3d144751239433f82ceb740bb042693d300f90d1c12054812f3f972241ec2af7fa6e158cc578c51c76902828f0290
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/matching_bundle CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
- if File.exist?('Gemfile.lock')
3
- content = File.read('Gemfile.lock')
4
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
- require 'rubygems'
6
- require 'matching_bundle'
7
- if version = MatchingBundle.find_or_install_matching_version(content)
8
- $stderr.puts "using bunlder #{version}"
9
- exec "bundle _#{version}_ #{ARGV * " "}" # program exits here ...
10
- end
11
- end
2
+ # frozen_string_literal: true
3
+
4
+ gemfile = ENV["BUNDLE_GEMFILE"] || "Gemfile"
5
+ lockfile = "#{gemfile}.lock"
6
+ exec "bundle", *ARGV unless File.exist?(lockfile) # nothing we can do, regular bundle it is
12
7
 
13
- exec "bundle #{ARGV * " "}"
8
+ require 'matching_bundle'
9
+
10
+ content = File.read(lockfile)
11
+ if version = MatchingBundle.find_or_install_matching_version(content)
12
+ warn "Using bundler #{version}"
13
+ exec "bundle", "_#{version}_", *ARGV
14
+ end
@@ -1,52 +1,52 @@
1
+ # frozen_string_literal: true
1
2
  require 'open-uri'
3
+ require 'json'
2
4
 
3
- class MatchingBundle
4
- VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
5
+ module MatchingBundle
6
+ class << self
7
+ def find_or_install_matching_version(gemfile_content)
8
+ return unless requirement = bundler_requirement(gemfile_content)
5
9
 
6
- def self.find_or_install_matching_version(gemfile_content)
7
- return unless requirement = bundler_requirement(gemfile_content)
10
+ if version = find_matching_local_bundler_version(requirement)
11
+ return version
12
+ end
8
13
 
9
- if version = find_matching_local_bundler_version(requirement)
10
- return version
11
- end
14
+ return unless version = find_matching_remote_bundler_version(requirement)
12
15
 
13
- if version = find_matching_remote_bundler_version(requirement)
14
- $stderr.puts "installing bundler #{version}"
15
- `gem install bundler -v #{version}`
16
- return version
16
+ warn "Installing bundler #{version}"
17
+ abort unless system "gem", "install", "bundler", "-v", version
18
+ version
17
19
  end
18
- end
19
20
 
20
- def self.find_matching_remote_bundler_version(requirement)
21
- json = open('http://rubygems.org/api/v1/versions/bundler').read
22
- versions = json.scan(/"number"\s*:\s*"(.*?)"/).map{|v|v.first}
23
- find_satisfied(requirement, versions)
24
- end
21
+ private
25
22
 
26
- def self.find_matching_local_bundler_version(requirement)
27
- find_satisfied(requirement, installed_bundler_versions)
28
- end
23
+ def find_matching_remote_bundler_version(requirement)
24
+ json = open('https://rubygems.org/api/v1/versions/bundler.json').read
25
+ versions = JSON.load(json).map { |v| v["number"] }
26
+ find_satisfied(requirement, versions)
27
+ end
29
28
 
30
- def self.find_satisfied(requirement, versions)
31
- requirement = Gem::Requirement.new(requirement)
32
- versions.find do |version|
33
- requirement.satisfied_by? Gem::Version.new(version)
29
+ def find_matching_local_bundler_version(requirement)
30
+ find_satisfied(requirement, installed_bundler_versions)
34
31
  end
35
- end
36
32
 
37
- def self.installed_bundler_versions
38
- bundler_specs = if Gem::Specification.respond_to?(:find_all)
39
- Gem::Specification.find_all{|s| s.name == 'bundler' }
40
- else
41
- dep = Gem::Dependency.new 'bundler', Gem::Requirement.default
42
- Gem.source_index.search dep
33
+ def find_satisfied(requirement, versions)
34
+ requirement = Gem::Requirement.new(requirement)
35
+ versions.find do |version|
36
+ requirement.satisfied_by? Gem::Version.new(version)
37
+ end
43
38
  end
44
- bundler_specs.map{|spec| spec.version.to_s }
45
- end
46
39
 
47
- def self.bundler_requirement(gemfile_content)
48
- found = gemfile_content.scan(/^\s*bundler \((.*)\)/)
49
- versions = found.map(&:last)
50
- versions.find{|version| version =~ /^=\s*\d/ } || versions.first
40
+ def installed_bundler_versions
41
+ Gem::Specification.
42
+ find_all { |s| s.name == 'bundler' }.
43
+ map { |spec| spec.version.to_s }
44
+ end
45
+
46
+ def bundler_requirement(gemfile_content)
47
+ found = gemfile_content.scan(/^\s*bundler \((.*)\)/)
48
+ versions = found.map(&:last)
49
+ versions.find { |version| version =~ /^=\s*\d/ } || versions.first
50
+ end
51
51
  end
52
52
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module MatchingBundle
3
+ VERSION = "0.2.0"
4
+ end
metadata CHANGED
@@ -1,76 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: matching_bundle
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Michael Grosser
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-11-19 00:00:00 -08:00
19
- default_executable: matching_bundle
11
+ date: 2019-06-01 00:00:00.000000000 Z
20
12
  dependencies: []
21
-
22
13
  description:
23
14
  email: michael@grosser.it
24
- executables:
25
- - matching_bundle
15
+ executables: []
26
16
  extensions: []
27
-
28
17
  extra_rdoc_files: []
29
-
30
- files:
31
- - Gemfile
32
- - Gemfile.lock
33
- - Rakefile
34
- - Readme.md
35
- - VERSION
18
+ files:
19
+ - MIT-LICENSE
36
20
  - bin/matching_bundle
37
21
  - lib/matching_bundle.rb
38
- - matching_bundle.gemspec
39
- - spec/matching_bundle_spec.rb
40
- - spec/spec_helper.rb
41
- has_rdoc: true
42
- homepage: http://github.com/grosser/matching_bundle
43
- licenses:
22
+ - lib/matching_bundle/version.rb
23
+ homepage: https://github.com/grosser/matching_bundle
24
+ licenses:
44
25
  - MIT
26
+ metadata: {}
45
27
  post_install_message:
46
28
  rdoc_options: []
47
-
48
- require_paths:
29
+ require_paths:
49
30
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
53
33
  - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
59
- required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
- requirements:
34
+ - !ruby/object:Gem::Version
35
+ version: 2.3.0
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
62
38
  - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
66
- - 0
67
- version: "0"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
68
41
  requirements: []
69
-
70
42
  rubyforge_project:
71
- rubygems_version: 1.6.2
43
+ rubygems_version: 2.7.6
72
44
  signing_key:
73
- specification_version: 3
45
+ specification_version: 4
74
46
  summary: Find a matching bundler version for a Gemfile and use it
75
47
  test_files: []
76
-
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source :rubygems
2
-
3
- group :dev do # not development <-> would add unneeded development dependencies in gemspec
4
- gem 'rake'
5
- gem 'rspec', '~>2'
6
- gem 'jeweler'
7
- end
data/Gemfile.lock DELETED
@@ -1,26 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.6.0)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- rake (0.8.7)
11
- rspec (2.5.0)
12
- rspec-core (~> 2.5.0)
13
- rspec-expectations (~> 2.5.0)
14
- rspec-mocks (~> 2.5.0)
15
- rspec-core (2.5.2)
16
- rspec-expectations (2.5.0)
17
- diff-lcs (~> 1.1.2)
18
- rspec-mocks (2.5.0)
19
-
20
- PLATFORMS
21
- ruby
22
-
23
- DEPENDENCIES
24
- jeweler
25
- rake
26
- rspec (~> 2)
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- task :default do
2
- sh "rspec spec/"
3
- end
4
-
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gem|
8
- gem.name = 'matching_bundle'
9
- gem.summary = "Find a matching bundler version for a Gemfile and use it"
10
- gem.email = "michael@grosser.it"
11
- gem.homepage = "http://github.com/grosser/#{gem.name}"
12
- gem.authors = ["Michael Grosser"]
13
- gem.license = "MIT"
14
- end
15
-
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
19
- end
data/Readme.md DELETED
@@ -1,33 +0,0 @@
1
- Find a matching bundler version for a Gemfile and use it.
2
- Any additional arguments are passed to bundle, so use it just like you would use bundle.
3
-
4
- Install
5
- =======
6
- gem install matching_bundle
7
-
8
- Usage
9
- =====
10
- Everything works just like bundle.
11
- If there is a specific bundler version locked in the gemfile it will be used.
12
-
13
- matching_bundle install
14
- matching_bundle exec rake
15
- ...
16
-
17
- If you need sudo to install gems do something like:
18
-
19
- sudo matching_bundle --version # matching version is installed
20
- matching_bundle install # matching version is used
21
-
22
- TODO
23
- ====
24
- - parse --gemfile option
25
- - use highest matching version
26
- - add a --no-install flag so only local versions are used
27
-
28
- Author
29
- ======
30
- [Michael Grosser](http://grosser.it)<br/>
31
- michael@grosser.it<br/>
32
- License: MIT<br/>
33
- [![Build Status](https://secure.travis-ci.org/grosser/matching_bundle.png)](http://travis-ci.org/grosser/matching_bundle)
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.2
@@ -1,43 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{matching_bundle}
8
- s.version = "0.1.2"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Grosser"]
12
- s.date = %q{2011-11-19}
13
- s.default_executable = %q{matching_bundle}
14
- s.email = %q{michael@grosser.it}
15
- s.executables = ["matching_bundle"]
16
- s.files = [
17
- "Gemfile",
18
- "Gemfile.lock",
19
- "Rakefile",
20
- "Readme.md",
21
- "VERSION",
22
- "bin/matching_bundle",
23
- "lib/matching_bundle.rb",
24
- "matching_bundle.gemspec",
25
- "spec/matching_bundle_spec.rb",
26
- "spec/spec_helper.rb"
27
- ]
28
- s.homepage = %q{http://github.com/grosser/matching_bundle}
29
- s.licenses = ["MIT"]
30
- s.require_paths = ["lib"]
31
- s.rubygems_version = %q{1.6.2}
32
- s.summary = %q{Find a matching bundler version for a Gemfile and use it}
33
-
34
- if s.respond_to? :specification_version then
35
- s.specification_version = 3
36
-
37
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
- else
39
- end
40
- else
41
- end
42
- end
43
-
@@ -1,59 +0,0 @@
1
- require File.expand_path('spec/spec_helper')
2
-
3
- describe MatchingBundle do
4
- it "has a VERSION" do
5
- MatchingBundle::VERSION.should =~ /^\d+\.\d+\.\d+$/
6
- end
7
-
8
- describe :bundler_requirement do
9
- def requirement(*args)
10
- MatchingBundle.bundler_requirement(*args)
11
- end
12
-
13
- it "finds nothing when there is nothing" do
14
- requirement("").should == nil
15
- end
16
-
17
- it "finds a direct requirement" do
18
- gemfile = "asd\n bundler (1.0.1)"
19
- requirement(gemfile).should == "1.0.1"
20
- end
21
-
22
- it "finds a indirect requirement" do
23
- gemfile = "asd\n bundler (~>1.0.1)"
24
- requirement(gemfile).should == "~>1.0.1"
25
- end
26
-
27
- it "finds dependencies before other requirements" do
28
- gemfile = "asd\n bundler (~>1.0.1)\nDEPENDENCIES\n bundler (= 1.1.rc)"
29
- requirement(gemfile).should == "= 1.1.rc"
30
- end
31
- end
32
-
33
- describe :installed_bundler_versions do
34
- it "finds something" do
35
- expected = `gem list bundler | grep bundler`.strip.match(/\((.*)\)/)[1].split(', ')
36
- MatchingBundle.installed_bundler_versions.should =~ expected
37
- end
38
- end
39
-
40
- describe :find_matching_local_bundler_version do
41
- it "find something for >=0" do
42
- MatchingBundle.find_matching_local_bundler_version('>=0').should =~ /^\d+\.\d+\.\d+$/
43
- end
44
-
45
- it "finds nothing for >999" do
46
- MatchingBundle.find_matching_local_bundler_version('>=999').should == nil
47
- end
48
- end
49
-
50
- describe :find_matching_remote_bundler_version do
51
- it "finds one for ~>0.4.0" do
52
- MatchingBundle.find_matching_remote_bundler_version("~>0.4.0").should == "0.4.1"
53
- end
54
-
55
- it "does not find one for ~>999" do
56
- MatchingBundle.find_matching_remote_bundler_version("~>999.0.0").should == nil
57
- end
58
- end
59
- end
data/spec/spec_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- $LOAD_PATH.unshift 'lib'
2
- require 'matching_bundle'