matching_bundle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +26 -0
- data/Rakefile +18 -0
- data/Readme.md +29 -0
- data/VERSION +1 -0
- data/bin/matching_bundle +13 -0
- data/lib/matching_bundle.rb +52 -0
- data/matching_bundle.gemspec +42 -0
- data/spec/matching_bundle_spec.rb +48 -0
- data/spec/spec_helper.rb +2 -0
- metadata +76 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
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
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
+
end
|
14
|
+
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
18
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,29 @@
|
|
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
|
+
sudo matching_bundle --version # matching version is installed
|
19
|
+
matching_bundle install # matching version is used
|
20
|
+
|
21
|
+
TODO
|
22
|
+
====
|
23
|
+
- parse --gemfile option
|
24
|
+
|
25
|
+
Author
|
26
|
+
======
|
27
|
+
[Michael Grosser](http://grosser.it)<br/>
|
28
|
+
michael@grosser.it<br/>
|
29
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/matching_bundle
ADDED
@@ -0,0 +1,13 @@
|
|
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
|
12
|
+
|
13
|
+
exec "bundle #{ARGV * " "}"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
class MatchingBundle
|
4
|
+
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
5
|
+
|
6
|
+
def self.find_or_install_matching_version(gemfile_content)
|
7
|
+
return unless requirement = bundler_requirement(gemfile_content)
|
8
|
+
|
9
|
+
if version = find_matching_local_bundler_version(requirement)
|
10
|
+
return version
|
11
|
+
end
|
12
|
+
|
13
|
+
if version = find_matching_remote_bundler_version(requirement)
|
14
|
+
$stderr.puts "installing bundler #{version}"
|
15
|
+
`gem install bundler -v #{version}`
|
16
|
+
return version
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
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
|
25
|
+
|
26
|
+
def self.find_matching_local_bundler_version(requirement)
|
27
|
+
find_satisfied(requirement, installed_bundler_versions)
|
28
|
+
end
|
29
|
+
|
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)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
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
|
43
|
+
end
|
44
|
+
bundler_specs.map{|spec| spec.version.to_s }
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.bundler_requirement(gemfile_content)
|
48
|
+
if found = gemfile_content.match(/^\s*bundler \((.*)\)/)
|
49
|
+
found[1]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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.0"
|
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-05-09}
|
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.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.6.2}
|
31
|
+
s.summary = %q{Find a matching bundler version for a Gemfile and use it}
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
s.specification_version = 3
|
35
|
+
|
36
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
37
|
+
else
|
38
|
+
end
|
39
|
+
else
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,48 @@
|
|
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
|
+
it "finds nothing when there is nothing" do
|
10
|
+
MatchingBundle.bundler_requirement("").should == nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "finds a direct requirement" do
|
14
|
+
MatchingBundle.bundler_requirement("asd\n bundler (1.0.1)").should == "1.0.1"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "finds a indirect requirement" do
|
18
|
+
MatchingBundle.bundler_requirement("asd\n bundler (~>1.0.1)").should == "~>1.0.1"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :installed_bundler_versions do
|
23
|
+
it "finds something" do
|
24
|
+
expected = `gem list bundler | grep bundler`.strip.match(/\((.*)\)/)[1].split(', ')
|
25
|
+
MatchingBundle.installed_bundler_versions.should =~ expected
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe :find_matching_local_bundler_version do
|
30
|
+
it "find something for >=0" do
|
31
|
+
MatchingBundle.find_matching_local_bundler_version('>=0').should =~ /^\d+\.\d+\.\d+$/
|
32
|
+
end
|
33
|
+
|
34
|
+
it "finds nothing for >999" do
|
35
|
+
MatchingBundle.find_matching_local_bundler_version('>=999').should == nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe :find_matching_remote_bundler_version do
|
40
|
+
it "finds one for ~>0.4.0" do
|
41
|
+
MatchingBundle.find_matching_remote_bundler_version("~>0.4.0").should == "0.4.1"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "does not find one for ~>999" do
|
45
|
+
MatchingBundle.find_matching_remote_bundler_version("~>999.0.0").should == nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: matching_bundle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Grosser
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-09 00:00:00 +02:00
|
19
|
+
default_executable: matching_bundle
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: michael@grosser.it
|
24
|
+
executables:
|
25
|
+
- matching_bundle
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Gemfile
|
32
|
+
- Gemfile.lock
|
33
|
+
- Rakefile
|
34
|
+
- Readme.md
|
35
|
+
- VERSION
|
36
|
+
- bin/matching_bundle
|
37
|
+
- 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: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
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:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.6.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Find a matching bundler version for a Gemfile and use it
|
75
|
+
test_files: []
|
76
|
+
|