bundler_ext 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -2
- data/lib/aeolus/ext/bundler_ext.rb +35 -13
- data/lib/aeolus/ext/version.rb +1 -1
- data/spec/aeolus/ext/bundler_ext_spec.rb +42 -20
- data/spec/fixtures/Gemfile.in +9 -2
- metadata +5 -19
data/README.md
CHANGED
@@ -18,9 +18,21 @@ However, this is the use case for many linux systems, and this library
|
|
18
18
|
is an initial attempt to get the two approaches to not step on each
|
19
19
|
other.
|
20
20
|
|
21
|
-
### Example usage
|
21
|
+
### Example usage ###
|
22
22
|
|
23
|
-
|
23
|
+
If you want to load ALL Gemfile groups, use the following statement:
|
24
|
+
|
25
|
+
Aeolus::Ext::BundlerExt.system_require(File.expand_path('../../Gemfile.in', __FILE__), :all)
|
26
|
+
|
27
|
+
When you want to load only the default one, use:
|
28
|
+
|
29
|
+
Aeolus::Ext::BundlerExt.system_require(File.expand_path('../../Gemfile.in', __FILE__), :default)
|
30
|
+
|
31
|
+
You can provide multiple parameters to the system_require function
|
32
|
+
of course. Finally, you will be likely requiring default group and
|
33
|
+
group named as the current Rails environment; use this:
|
34
|
+
|
35
|
+
Aeolus::Ext::BundlerExt.system_require(File.expand_path('../../Gemfile.in', __FILE__), :default, Rails.env)
|
24
36
|
|
25
37
|
You may also want to wrap your call in some kind of check, to allow
|
26
38
|
non-platform users (ie, mac, or any developer not installing as a
|
@@ -41,3 +53,27 @@ all, so for now at least, it is safer to just look for a different
|
|
41
53
|
file (and this is easily scripted as well) In the linux deployment
|
42
54
|
case, this is not the desired behavior, we explicitly want to say
|
43
55
|
'just use what the package manager has installed'.
|
56
|
+
|
57
|
+
### Additional configuration ###
|
58
|
+
|
59
|
+
There are special environment variables you can use. You may need to
|
60
|
+
insert additional groups to be required, e.g. when developing and you
|
61
|
+
want to restart the system in development mode once. Use
|
62
|
+
BUNDLER_EXT_GROUPS variable (separate with whitespace):
|
63
|
+
|
64
|
+
BUNDLER_EXT_GROUPS="group1 group2 group3" rails server ...
|
65
|
+
|
66
|
+
Also, by default bundler_ext raises an error when dependency cannot
|
67
|
+
be loaded. You can turn off this behavior (e.g. for installers when
|
68
|
+
you want to do rake db:migrate) with setting BUNDLER_EXT_NOSTRICT:
|
69
|
+
|
70
|
+
BUNDLER_EXT_NOSTRICT=1 rake db:migrate ...
|
71
|
+
|
72
|
+
In this mode bundler_ext prints out error messages on the stdout,
|
73
|
+
but does not terminate the process.
|
74
|
+
|
75
|
+
Some rubygems require HOME environment variable to be set, threfore
|
76
|
+
not running daemonized. For this purposes there is BUNDLER_EXT_HOME
|
77
|
+
variable which can be used to set HOME environment variable before
|
78
|
+
any rubygem gets loaded. The variable is not exported for
|
79
|
+
subprocesses.
|
@@ -15,41 +15,63 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "bundler"
|
18
|
+
|
19
|
+
# some rubygems does not play well with daemonized processes ($HOME is empty)
|
20
|
+
ENV['HOME'] = ENV['BUNDLER_EXT_HOME'] if ENV['BUNDLER_EXT_HOME']
|
21
|
+
|
18
22
|
module Aeolus
|
19
23
|
module Ext
|
20
24
|
class BundlerExt
|
21
25
|
def self.parse_from_gemfile(gemfile,*groups)
|
22
26
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
27
|
+
extra_groups = ENV['BUNDLER_EXT_GROUPS']
|
28
|
+
extra_groups.split(/\s/).each {|g| groups << g.to_sym} if extra_groups
|
29
|
+
all_groups = false
|
30
|
+
all_groups = true if groups.size == 1 and groups.include?(:all) and not extra_groups
|
23
31
|
groups.map! { |g| g.to_sym }
|
24
|
-
groups = [:default] if groups.empty?
|
25
32
|
g = Bundler::Dsl.evaluate(gemfile,'foo',true)
|
26
33
|
list = []
|
27
|
-
g.dependencies.each
|
28
|
-
|
29
|
-
|
30
|
-
|
34
|
+
g.dependencies.each do |dep|
|
35
|
+
if ((groups & dep.groups).any? || all_groups) && dep.current_platform?
|
36
|
+
Array(dep.autorequire || dep.name).each do |file|
|
37
|
+
list << file
|
38
|
+
end
|
31
39
|
end
|
32
|
-
|
40
|
+
end
|
33
41
|
list
|
34
42
|
end
|
43
|
+
|
44
|
+
def self.strict_error(msg)
|
45
|
+
if ENV['BUNDLER_EXT_NOSTRICT']
|
46
|
+
puts msg
|
47
|
+
else
|
48
|
+
raise msg
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
35
52
|
def self.system_require(gemfile,*groups)
|
36
53
|
BundlerExt.parse_from_gemfile(gemfile,*groups).each do |dep|
|
37
|
-
|
38
|
-
|
54
|
+
#This part ripped wholesale from lib/bundler/runtime.rb (github/master)
|
55
|
+
begin
|
39
56
|
#puts "Attempting to require #{dep}"
|
40
|
-
|
57
|
+
require dep
|
41
58
|
rescue LoadError => e
|
42
59
|
#puts "Caught error: #{e.message}"
|
43
60
|
if dep.include?('-')
|
44
61
|
begin
|
45
|
-
|
62
|
+
if dep.respond_to? :name
|
63
|
+
namespaced_file = dep.name.gsub('-', '/')
|
64
|
+
else
|
65
|
+
# try to load unresolved deps
|
66
|
+
namespaced_file = dep.gsub('-', '/')
|
67
|
+
end
|
46
68
|
#puts "Munged the name, now trying to require as #{namespaced_file}"
|
47
69
|
require namespaced_file
|
48
|
-
rescue LoadError
|
49
|
-
|
70
|
+
rescue LoadError => e2
|
71
|
+
strict_error "Gem loading error: #{e2.message}"
|
50
72
|
end
|
51
73
|
else
|
52
|
-
|
74
|
+
strict_error "Gem loading error: #{e.message}"
|
53
75
|
end
|
54
76
|
end
|
55
77
|
end
|
data/lib/aeolus/ext/version.rb
CHANGED
@@ -19,55 +19,77 @@ module Aeolus
|
|
19
19
|
module Ext
|
20
20
|
describe BundlerExt do
|
21
21
|
before(:each) do
|
22
|
-
|
22
|
+
@gemfile = 'spec/fixtures/Gemfile.in'
|
23
|
+
end
|
24
|
+
after(:each) do
|
25
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = nil
|
26
|
+
ENV['BUNDLER_EXT_GROUPS'] = nil
|
23
27
|
end
|
24
28
|
|
25
29
|
describe "#parse_from_gemfile" do
|
26
30
|
describe "with no group passed in" do
|
27
|
-
it "should return
|
31
|
+
it "should return nothing to require" do
|
28
32
|
libs = BundlerExt.parse_from_gemfile(@gemfile)
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
libs.should be_an(Array)
|
34
|
+
libs.should_not include('deltacloud')
|
35
|
+
libs.should_not include('vcr')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe "with :all passed in" do
|
39
|
+
it "should return the list of system libraries in all groups to require" do
|
40
|
+
libs = BundlerExt.parse_from_gemfile(@gemfile, :all)
|
41
|
+
libs.should be_an(Array)
|
42
|
+
libs.should include('deltacloud')
|
43
|
+
libs.should include('vcr')
|
32
44
|
end
|
33
45
|
end
|
34
46
|
describe "with group passed in" do
|
35
47
|
it "should not return any deps that are not in the 'development' group" do
|
36
48
|
libs = BundlerExt.parse_from_gemfile(@gemfile,'development')
|
37
49
|
libs.should be_an(Array)
|
38
|
-
|
50
|
+
libs.should_not include('deltacloud')
|
39
51
|
end
|
40
52
|
it "should return only deps that are in the :test group" do
|
41
53
|
libs = BundlerExt.parse_from_gemfile(@gemfile, :test)
|
42
54
|
libs.should be_an(Array)
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
libs.should_not include('deltacloud')
|
56
|
+
libs.should include('vcr')
|
57
|
+
end
|
46
58
|
it "should return deps from both the :default and :test groups" do
|
47
59
|
libs = BundlerExt.parse_from_gemfile(@gemfile, :default, :test)
|
48
60
|
libs.should be_an(Array)
|
49
|
-
|
50
|
-
|
51
|
-
|
61
|
+
libs.should include('deltacloud')
|
62
|
+
libs.should include('vcr')
|
63
|
+
end
|
52
64
|
end
|
53
65
|
it "should only return deps for the current platform" do
|
54
66
|
libs = BundlerExt.parse_from_gemfile(@gemfile)
|
55
67
|
libs.should be_an(Array)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
if RUBY_VERSION < "1.9"
|
69
|
+
libs.should_not include('cinch')
|
70
|
+
else
|
71
|
+
libs.should_not include('fastercsv')
|
60
72
|
end
|
61
73
|
end
|
62
74
|
end
|
63
75
|
describe "#system_require" do
|
64
|
-
it "should
|
76
|
+
it "strict mode should fail loading non existing gem" do
|
77
|
+
expect { BundlerExt.system_require(@gemfile, :fail) }.to raise_error
|
78
|
+
end
|
79
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
80
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
65
81
|
BundlerExt.system_require(@gemfile)
|
66
|
-
|
82
|
+
defined?(Gem).should be_true
|
67
83
|
end
|
68
|
-
it "should load the libraries in the gemfile" do
|
84
|
+
it "non-strict mode should load the libraries in the gemfile" do
|
85
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
69
86
|
BundlerExt.system_require(@gemfile, :fail)
|
70
|
-
|
87
|
+
defined?(Gem).should be_true
|
88
|
+
end
|
89
|
+
it "non-strict mode should load the libraries using env var list" do
|
90
|
+
ENV['BUNDLER_EXT_GROUPS'] = 'test development blah'
|
91
|
+
ENV['BUNDLER_EXT_NOSTRICT'] = 'true'
|
92
|
+
defined?(Gem::Command).should be_true
|
71
93
|
end
|
72
94
|
end
|
73
95
|
end
|
data/spec/fixtures/Gemfile.in
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
+
# only this really need to be present on the system
|
4
|
+
gem 'rubygems'
|
5
|
+
|
6
|
+
# non exising gem must be ordered as second gem
|
7
|
+
gem 'not_existing_gem', :group => :fail
|
8
|
+
|
9
|
+
# all the others are not required to have passing tests
|
3
10
|
gem 'deltacloud-client', :require => 'deltacloud'
|
4
11
|
gem 'will_paginate', '>= 3.0.pre1'
|
5
12
|
gem 'fastercsv' , :platforms => :mri_18
|
6
13
|
gem 'cinch' , :platforms => :mri_19
|
7
|
-
|
14
|
+
|
8
15
|
group :development, :test do
|
9
|
-
gem '
|
16
|
+
gem 'rubygems-command'
|
10
17
|
gem 'vcr'
|
11
18
|
gem 'webmock'
|
12
19
|
gem 'launchy'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bundler_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Guiditta
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-11-28 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|
@@ -47,20 +47,6 @@ dependencies:
|
|
47
47
|
version: 1.3.0
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: deltacloud-client
|
52
|
-
prerelease: false
|
53
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
|
-
requirements:
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
version: "0"
|
62
|
-
type: :development
|
63
|
-
version_requirements: *id003
|
64
50
|
description: Simple library leveraging the Bundler Gemfile DSL to load gems already on the system and managed by the systems package manager (like yum/apt)
|
65
51
|
email:
|
66
52
|
- aeolus-devel@lists.fedorahosted.org, jguiditt@redhat.com
|
@@ -110,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
96
|
requirements: []
|
111
97
|
|
112
98
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.8.
|
99
|
+
rubygems_version: 1.8.11
|
114
100
|
signing_key:
|
115
101
|
specification_version: 3
|
116
102
|
summary: Load system gems via Bundler DSL
|