bundler_ext 0.3.2 → 0.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 +4 -4
- data/README.md +50 -52
- data/lib/bundler_ext.rb +36 -1
- data/lib/bundler_ext/gemfile.rb +50 -0
- data/lib/bundler_ext/output.rb +16 -0
- data/lib/bundler_ext/runtime.rb +66 -0
- data/lib/bundler_ext/setup.rb +2 -0
- data/lib/bundler_ext/system.rb +61 -0
- data/lib/bundler_ext/version.rb +1 -1
- data/spec/bundler_ext/bundler_ext_spec.rb +80 -128
- data/spec/bundler_ext/gemfile_spec.rb +191 -0
- data/spec/bundler_ext/integration_spec.rb +146 -0
- data/spec/bundler_ext/runtime_spec.rb +178 -0
- data/spec/bundler_ext/system_spec.rb +138 -0
- data/spec/spec_helper.rb +1 -1
- metadata +21 -8
- data/lib/bundler_ext/bundler_ext.rb +0 -100
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bundler_ext/runtime'
|
3
|
+
|
4
|
+
module BundlerExt
|
5
|
+
describe System do
|
6
|
+
after(:each) do
|
7
|
+
ENV.delete('BEXT_PKG_PREFIX')
|
8
|
+
ENV.delete('BEXT_ACTIVATE_VERSIONS')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#parse_env" do
|
12
|
+
it "sets pkg_prefix from BEXT_PKG_PREFIX env variable" do
|
13
|
+
ENV['BEXT_PKG_PREFIX'] = 'rubygem-'
|
14
|
+
described_class.parse_env
|
15
|
+
described_class.pkg_prefix.should == 'rubygem-'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "defaults to blank pkg_prefix" do
|
19
|
+
described_class.parse_env
|
20
|
+
described_class.pkg_prefix.should == ''
|
21
|
+
end
|
22
|
+
|
23
|
+
it "sets activate_versions from BEXT_ACTIVATE_VERSIONS env variable" do
|
24
|
+
ENV['BEXT_ACTIVATE_VERSIONS'] = 'true'
|
25
|
+
described_class.parse_env
|
26
|
+
described_class.activate_versions.should == 'true'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#activate?" do
|
31
|
+
context "activate_versions is false" do
|
32
|
+
it "returns false" do
|
33
|
+
described_class.activate?.should be_false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "not an rpm system" do
|
38
|
+
it "returns false" do
|
39
|
+
ENV['BEXT_ACTIVATE_VERSIONS'] = 'true'
|
40
|
+
described_class.should_receive(:is_rpm_system?).and_return(false)
|
41
|
+
described_class.activate?.should be_false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns true" do
|
46
|
+
ENV['BEXT_ACTIVATE_VERSIONS'] = 'true'
|
47
|
+
described_class.should_receive(:is_rpm_system?).and_return(true)
|
48
|
+
described_class.activate?.should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#system_name_for" do
|
53
|
+
it "returns package name with package prefix" do
|
54
|
+
ENV['BEXT_PKG_PREFIX'] = 'rubygem-'
|
55
|
+
described_class.system_name_for('rails').should == 'rubygem-rails'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#is_rpm_system?" do
|
60
|
+
context "/usr/bin/rpm is not an executable file" do
|
61
|
+
it "returns false" do
|
62
|
+
File.should_receive(:executable?).
|
63
|
+
with(described_class.rpm_cmd).and_return(false)
|
64
|
+
described_class.is_rpm_system?.should be_false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "/usr/bin/rpm is an executable file" do
|
69
|
+
it "returns true" do
|
70
|
+
File.should_receive(:executable?).
|
71
|
+
with(described_class.rpm_cmd).and_return(true)
|
72
|
+
described_class.is_rpm_system?.should be_true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#rpm_cmd" do
|
78
|
+
around(:each) do |spec|
|
79
|
+
orpm = described_class.rpm_cmd
|
80
|
+
spec.run
|
81
|
+
described_class.rpm_cmd orpm
|
82
|
+
end
|
83
|
+
|
84
|
+
it "gets/sets rpm command" do
|
85
|
+
described_class.rpm_cmd '/bin/rpm'
|
86
|
+
described_class.rpm_cmd.should == '/bin/rpm'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "defaults to /usr/bin/rpm" do
|
90
|
+
described_class.rpm_cmd.should == '/usr/bin/rpm'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#system_version_for" do
|
95
|
+
context "rpm system" do
|
96
|
+
it "uses rpm_cmd to retrieve version" do
|
97
|
+
described_class.should_receive(:is_rpm_system?).and_return(true)
|
98
|
+
described_class.should_receive(:`).
|
99
|
+
with("#{described_class.rpm_cmd} -qi rails").
|
100
|
+
and_return("Name: rails\nVersion : 1.0.0 \nAnything")
|
101
|
+
described_class.system_version_for('rails').should == '1.0.0'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns nil" do
|
106
|
+
described_class.should_receive(:is_rpm_system?).and_return(false)
|
107
|
+
described_class.system_version_for('rails').should be_nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#activate!" do
|
112
|
+
it "activates system version of gem" do
|
113
|
+
described_class.should_receive(:system_name_for).
|
114
|
+
with('rails').and_return('rubygem-rake')
|
115
|
+
described_class.should_receive(:system_version_for).
|
116
|
+
with('rubygem-rake').and_return('1.2.3')
|
117
|
+
described_class.should_receive(:gem).
|
118
|
+
with('rails', '=1.2.3')
|
119
|
+
described_class.activate!('rails')
|
120
|
+
end
|
121
|
+
|
122
|
+
it "gracefully handles load errors" do
|
123
|
+
described_class.should_receive(:gem).and_raise(LoadError)
|
124
|
+
lambda{
|
125
|
+
described_class.activate!('rails')
|
126
|
+
}.should_not raise_error
|
127
|
+
end
|
128
|
+
|
129
|
+
it "gracefully handles bad requirement errors" do
|
130
|
+
described_class.should_receive(:gem).
|
131
|
+
and_raise(Gem::Requirement::BadRequirementError)
|
132
|
+
lambda{
|
133
|
+
described_class.activate!('rails')
|
134
|
+
}.should_not raise_error
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'bundler_ext
|
1
|
+
require 'bundler_ext'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bundler_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Guiditta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,15 +47,23 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- lib/bundler_ext.rb
|
50
|
+
- lib/bundler_ext/setup.rb
|
50
51
|
- lib/bundler_ext/version.rb
|
51
|
-
- lib/bundler_ext/
|
52
|
+
- lib/bundler_ext/system.rb
|
53
|
+
- lib/bundler_ext/runtime.rb
|
54
|
+
- lib/bundler_ext/gemfile.rb
|
55
|
+
- lib/bundler_ext/output.rb
|
52
56
|
- README.md
|
53
57
|
- MIT-LICENSE
|
54
58
|
- Rakefile
|
55
59
|
- CHANGELOG
|
56
|
-
- spec/bundler_ext/bundler_ext_spec.rb
|
57
|
-
- spec/spec_helper.rb
|
58
60
|
- spec/fixtures/Gemfile.in
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/bundler_ext/system_spec.rb
|
63
|
+
- spec/bundler_ext/integration_spec.rb
|
64
|
+
- spec/bundler_ext/gemfile_spec.rb
|
65
|
+
- spec/bundler_ext/runtime_spec.rb
|
66
|
+
- spec/bundler_ext/bundler_ext_spec.rb
|
59
67
|
- .rspec
|
60
68
|
homepage: https://github.com/bundlerext/bundler_ext
|
61
69
|
licenses:
|
@@ -79,12 +87,17 @@ requirements:
|
|
79
87
|
- Install the linux_admin gem and set BEXT_ACTIVATE_VERSIONS to true to activate rpm/deb
|
80
88
|
installed gems
|
81
89
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.0.
|
90
|
+
rubygems_version: 2.0.11
|
83
91
|
signing_key:
|
84
92
|
specification_version: 4
|
85
93
|
summary: Load system gems via Bundler DSL
|
86
94
|
test_files:
|
87
|
-
- spec/bundler_ext/bundler_ext_spec.rb
|
88
|
-
- spec/spec_helper.rb
|
89
95
|
- spec/fixtures/Gemfile.in
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/bundler_ext/system_spec.rb
|
98
|
+
- spec/bundler_ext/integration_spec.rb
|
99
|
+
- spec/bundler_ext/gemfile_spec.rb
|
100
|
+
- spec/bundler_ext/runtime_spec.rb
|
101
|
+
- spec/bundler_ext/bundler_ext_spec.rb
|
90
102
|
- .rspec
|
103
|
+
has_rdoc:
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require "bundler"
|
2
|
-
|
3
|
-
# some rubygems does not play well with daemonized processes ($HOME is empty)
|
4
|
-
ENV['HOME'] = ENV['BEXT_HOME'] if ENV['BEXT_HOME']
|
5
|
-
ENV['HOME'] = ENV['BUNDLER_EXT_HOME'] if ENV['BUNDLER_EXT_HOME']
|
6
|
-
|
7
|
-
class BundlerExt
|
8
|
-
def self.parse_from_gemfile(gemfile,*groups)
|
9
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
10
|
-
extra_groups = ENV['BUNDLER_EXT_GROUPS']
|
11
|
-
extra_groups = ENV['BEXT_GROUPS'] || ENV['BUNDLER_EXT_GROUPS']
|
12
|
-
extra_groups.split(/\s/).each {|g| groups << g.to_sym} if extra_groups
|
13
|
-
all_groups = false
|
14
|
-
all_groups = true if groups.size == 1 and groups.include?(:all) and not extra_groups
|
15
|
-
groups.map! { |g| g.to_sym }
|
16
|
-
g = Bundler::Dsl.evaluate(gemfile,'foo',true)
|
17
|
-
deps = {}
|
18
|
-
g.dependencies.each do |dep|
|
19
|
-
if ((groups & dep.groups).any? || all_groups) && dep.current_platform?
|
20
|
-
files = []
|
21
|
-
Array(dep.autorequire || dep.name).each do |file|
|
22
|
-
files << file
|
23
|
-
end
|
24
|
-
deps[dep.name] = {:dep => dep, :files => files}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
deps
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.system_gem_name_for(name)
|
31
|
-
ENV['BEXT_PKG_PREFIX'] ||= ''
|
32
|
-
"#{ENV['BEXT_PKG_PREFIX']}#{name}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.system_gem_version_for(name)
|
36
|
-
LinuxAdmin::Package.get_info(name)['version']
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.strict_error(msg)
|
40
|
-
if ENV['BEXT_NOSTRICT'] || ENV['BUNDLER_EXT_NOSTRICT']
|
41
|
-
puts msg
|
42
|
-
else
|
43
|
-
raise msg
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.system_require(gemfile,*groups)
|
48
|
-
activate_versions = ENV['BEXT_ACTIVATE_VERSIONS']
|
49
|
-
if activate_versions
|
50
|
-
begin
|
51
|
-
require "linux_admin"
|
52
|
-
rescue LoadError
|
53
|
-
puts "linux_admin not installed, cannot retrieve versions to activate"
|
54
|
-
activate_versions = false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
BundlerExt.parse_from_gemfile(gemfile,*groups).each do |name,gdep|
|
59
|
-
# activate the dependency
|
60
|
-
if activate_versions
|
61
|
-
begin
|
62
|
-
sys_name = BundlerExt.system_gem_name_for(name)
|
63
|
-
version = BundlerExt.system_gem_version_for(sys_name)
|
64
|
-
gem name, "=#{version}"
|
65
|
-
rescue LoadError, CommandResultError
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
gdep[:files].each do |dep|
|
70
|
-
#This part ripped wholesale from lib/bundler/runtime.rb (github/master)
|
71
|
-
begin
|
72
|
-
#puts "Attempting to require #{dep}"
|
73
|
-
require dep
|
74
|
-
rescue LoadError => e
|
75
|
-
#puts "Caught error: #{e.message}"
|
76
|
-
if dep.include?('-')
|
77
|
-
begin
|
78
|
-
if dep.respond_to? :name
|
79
|
-
namespaced_file = dep.name.gsub('-', '/')
|
80
|
-
else
|
81
|
-
# try to load unresolved deps
|
82
|
-
namespaced_file = dep.gsub('-', '/')
|
83
|
-
end
|
84
|
-
#puts "Munged the name, now trying to require as #{namespaced_file}"
|
85
|
-
require namespaced_file
|
86
|
-
rescue LoadError => e2
|
87
|
-
strict_error "Gem loading error: #{e2.message}"
|
88
|
-
end
|
89
|
-
else
|
90
|
-
strict_error "Gem loading error: #{e.message}"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.output
|
98
|
-
ENV['BUNDLER_STDERR'] || $stderr
|
99
|
-
end
|
100
|
-
end
|