moneypools-bundler 0.7.1.pre → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +9 -0
- data/Rakefile +29 -8
- data/lib/bundler/{repository.rb → bundle.rb} +137 -79
- data/lib/bundler/cli.rb +27 -7
- data/lib/bundler/commands/bundle_command.rb +1 -1
- data/lib/bundler/dependency.rb +7 -9
- data/lib/bundler/dsl.rb +26 -17
- data/lib/bundler/environment.rb +35 -131
- data/lib/bundler/gem_ext.rb +3 -2
- data/lib/bundler/remote_specification.rb +4 -1
- data/lib/bundler/resolver.rb +27 -11
- data/lib/bundler/source.rb +79 -48
- data/lib/bundler/templates/app_script.erb +2 -2
- data/lib/bundler/templates/environment.erb +17 -6
- data/lib/bundler/templates/environment_picker.erb +4 -0
- data/lib/bundler.rb +17 -3
- metadata +4 -3
data/README.markdown
CHANGED
@@ -66,6 +66,15 @@ information, please refer to Bundler::ManifestBuilder.
|
|
66
66
|
# the gemspec is found in.
|
67
67
|
gem "rspec", "1.1.6", :vendored_at => "vendor/rspec"
|
68
68
|
|
69
|
+
# You can also control what will happen when you run Bundler.require_env
|
70
|
+
# by using the :require_as option, as per the next two examples.
|
71
|
+
|
72
|
+
# Don't auto-require this gem.
|
73
|
+
gem "rspec-rails", "1.2.9", :require_as => nil
|
74
|
+
|
75
|
+
# Require something other than the default.
|
76
|
+
gem "yajl-ruby", "0.6.7", :require_as => "yajl/json_gem"
|
77
|
+
|
69
78
|
# Works exactly like :vendored_at, but first downloads the repo from
|
70
79
|
# git and handles stashing the files for you. As with :vendored_at,
|
71
80
|
# Bundler will automatically use *.gemspec files in the root or anywhere
|
data/Rakefile
CHANGED
@@ -37,6 +37,33 @@ else
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
namespace :spec do
|
41
|
+
file "tmp/rg_deps" do
|
42
|
+
repo = File.dirname(__FILE__) + '/tmp/rg_deps'
|
43
|
+
FileUtils.mkdir_p(repo)
|
44
|
+
p repo
|
45
|
+
ENV['GEM_HOME'], ENV['GEM_PATH'] = repo, repo
|
46
|
+
system "gem install builder --no-rdoc --no-ri"
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Do all setup needed to run the specs"
|
50
|
+
task :setup => "tmp/rg_deps"
|
51
|
+
|
52
|
+
desc "Mount a ramdisk at ./tmp for faster specs"
|
53
|
+
task :ramdisk do
|
54
|
+
sh 'diskutil erasevolume HFS+ "tmpbundler" `hdiutil attach -nomount ram://116543`'
|
55
|
+
File.symlink "/Volumes/tmpbundler", File.expand_path('../tmp', __FILE__)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
spec_file = "#{spec.name}.gemspec"
|
60
|
+
desc "Create #{spec_file}"
|
61
|
+
file spec_file => "Rakefile" do
|
62
|
+
File.open(spec_file, "w") do |file|
|
63
|
+
file.puts spec.to_ruby
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
40
67
|
begin
|
41
68
|
require 'rake/gempackagetask'
|
42
69
|
rescue LoadError
|
@@ -45,16 +72,10 @@ else
|
|
45
72
|
Rake::GemPackageTask.new(spec) do |pkg|
|
46
73
|
pkg.gem_spec = spec
|
47
74
|
end
|
75
|
+
task :gem => spec_file
|
48
76
|
end
|
49
77
|
|
50
78
|
desc "install the gem locally"
|
51
|
-
task :install =>
|
79
|
+
task :install => :package do
|
52
80
|
sh %{gem install pkg/#{spec.name}-#{spec.version}}
|
53
81
|
end
|
54
|
-
|
55
|
-
desc "create a gemspec file"
|
56
|
-
task :make_spec do
|
57
|
-
File.open("#{spec.name}.gemspec", "w") do |file|
|
58
|
-
file.puts spec.to_ruby
|
59
|
-
end
|
60
|
-
end
|
@@ -1,30 +1,81 @@
|
|
1
1
|
module Bundler
|
2
2
|
class InvalidRepository < StandardError ; end
|
3
3
|
|
4
|
-
class
|
5
|
-
attr_reader :
|
4
|
+
class Bundle
|
5
|
+
attr_reader :gemfile, :environment
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def self.load(gemfile = nil)
|
8
|
+
gemfile = Pathname.new(gemfile || default_gemfile).expand_path
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
unless gemfile.file?
|
11
|
+
raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}"
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
+
new(gemfile)
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def self.default_gemfile
|
18
|
+
current = Pathname.new(Dir.pwd)
|
19
|
+
|
20
|
+
until current.root?
|
21
|
+
filename = current.join("Gemfile")
|
22
|
+
return filename if filename.exist?
|
23
|
+
current = current.parent
|
21
24
|
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
raise DefaultManifestNotFound
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO: passing in the filename is not good
|
30
|
+
def initialize(gemfile)
|
31
|
+
@gemfile = gemfile
|
32
|
+
@environment = Environment.new(self)
|
33
|
+
Dsl.evaluate(gemfile, self, @environment)
|
34
|
+
|
35
|
+
# path = env.gem_path
|
36
|
+
|
37
|
+
FileUtils.mkdir_p(gem_path)
|
38
|
+
|
39
|
+
@cache_path = gem_path.join('cache')
|
40
|
+
@cache = GemDirectorySource.new(self, :location => @cache_path)
|
41
|
+
|
42
|
+
@specs_path = gem_path.join('specifications')
|
43
|
+
@gems_path = gem_path.join('gems')
|
44
|
+
end
|
45
|
+
|
46
|
+
def root
|
47
|
+
gemfile.parent
|
48
|
+
end
|
49
|
+
|
50
|
+
def path
|
51
|
+
@path ||= root.join("vendor/gems")
|
52
|
+
end
|
53
|
+
|
54
|
+
def path=(path)
|
55
|
+
@path = (path.relative? ? root.join(path) : path).expand_path
|
56
|
+
end
|
57
|
+
|
58
|
+
def gem_path
|
59
|
+
path.join("#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def bindir
|
63
|
+
@bindir ||= root.join("bin")
|
64
|
+
end
|
65
|
+
|
66
|
+
def bindir=(path)
|
67
|
+
@bindir = (path.relative? ? root.join(path) : path).expand_path
|
68
|
+
end
|
69
|
+
|
70
|
+
def install(options = {})
|
71
|
+
dependencies = @environment.dependencies
|
72
|
+
sources = @environment.sources
|
73
|
+
|
74
|
+
# ========== from env
|
75
|
+
if only_envs = options[:only]
|
76
|
+
dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } }
|
27
77
|
end
|
78
|
+
# ==========
|
28
79
|
|
29
80
|
# Check to see whether the existing cache meets all the requirements
|
30
81
|
begin
|
@@ -39,7 +90,7 @@ module Bundler
|
|
39
90
|
# or the user passed --update
|
40
91
|
if options[:update] || !valid
|
41
92
|
Bundler.logger.info "Calculating dependencies..."
|
42
|
-
bundle = Resolver.resolve(dependencies, [@cache] + sources
|
93
|
+
bundle = Resolver.resolve(dependencies, [@cache] + sources)
|
43
94
|
download(bundle, options)
|
44
95
|
do_install(bundle, options)
|
45
96
|
valid = bundle
|
@@ -48,21 +99,33 @@ module Bundler
|
|
48
99
|
generate_bins(valid, options)
|
49
100
|
cleanup(valid, options)
|
50
101
|
configure(valid, options)
|
102
|
+
|
103
|
+
Bundler.logger.info "Done."
|
51
104
|
end
|
52
105
|
|
53
106
|
def cache(*gemfiles)
|
54
|
-
FileUtils.mkdir_p(@
|
107
|
+
FileUtils.mkdir_p(@cache_path)
|
55
108
|
gemfiles.each do |gemfile|
|
56
109
|
Bundler.logger.info "Caching: #{File.basename(gemfile)}"
|
57
|
-
FileUtils.cp(gemfile, @
|
110
|
+
FileUtils.cp(gemfile, @cache_path)
|
58
111
|
end
|
59
112
|
end
|
60
113
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
114
|
+
def list_outdated(options={})
|
115
|
+
outdated_gems = source_index.outdated.sort
|
116
|
+
|
117
|
+
if outdated_gems.empty?
|
118
|
+
Bundler.logger.info "All gems are up to date."
|
119
|
+
else
|
120
|
+
Bundler.logger.info "Outdated gems:"
|
121
|
+
outdated_gems.each do |name|
|
122
|
+
Bundler.logger.info " * #{name}"
|
123
|
+
end
|
65
124
|
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def prune(options = {})
|
128
|
+
dependencies, sources = @environment.dependencies, @environment.sources
|
66
129
|
|
67
130
|
sources = only_local(sources)
|
68
131
|
bundle = Resolver.resolve(dependencies, [@cache] + sources)
|
@@ -70,23 +133,26 @@ module Bundler
|
|
70
133
|
specs.each do |spec|
|
71
134
|
unless bundle.any? { |s| s.name == spec.name && s.version == spec.version }
|
72
135
|
Bundler.logger.info "Pruning #{spec.name} (#{spec.version}) from the cache"
|
73
|
-
FileUtils.rm @
|
136
|
+
FileUtils.rm @cache_path.join("#{spec.full_name}.gem")
|
74
137
|
end
|
75
138
|
end
|
76
139
|
end
|
77
140
|
end
|
78
141
|
|
79
|
-
def
|
80
|
-
|
142
|
+
def list(options = {})
|
143
|
+
Bundler.logger.info "Currently bundled gems:"
|
144
|
+
gems.each do |spec|
|
145
|
+
Bundler.logger.info " * #{spec.name} (#{spec.version})"
|
146
|
+
end
|
81
147
|
end
|
82
148
|
|
83
|
-
def
|
84
|
-
source_index.
|
149
|
+
def gems
|
150
|
+
source_index.gems.values
|
85
151
|
end
|
86
152
|
|
87
153
|
def source_index
|
88
|
-
index = Gem::SourceIndex.from_gems_in(@
|
89
|
-
index.each { |n, spec| spec.loaded_from = @
|
154
|
+
index = Gem::SourceIndex.from_gems_in(@specs_path)
|
155
|
+
index.each { |n, spec| spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec") }
|
90
156
|
index
|
91
157
|
end
|
92
158
|
|
@@ -94,25 +160,34 @@ module Bundler
|
|
94
160
|
@repos[type].download_path_for
|
95
161
|
end
|
96
162
|
|
163
|
+
def setup_environment
|
164
|
+
unless @environment.system_gems
|
165
|
+
ENV["GEM_HOME"] = gem_path
|
166
|
+
ENV["GEM_PATH"] = gem_path
|
167
|
+
end
|
168
|
+
ENV["PATH"] = "#{bindir}:#{ENV["PATH"]}"
|
169
|
+
ENV["RUBYOPT"] = "-r#{gem_path}/environment #{ENV["RUBYOPT"]}"
|
170
|
+
end
|
171
|
+
|
97
172
|
private
|
98
173
|
|
99
174
|
def only_local(sources)
|
100
|
-
sources.select { |s| s.
|
175
|
+
sources.select { |s| s.local? }
|
101
176
|
end
|
102
177
|
|
103
178
|
def download(bundle, options)
|
104
179
|
bundle.sort_by {|s| s.full_name.downcase }.each do |spec|
|
105
|
-
next if
|
180
|
+
next if spec.no_bundle?
|
106
181
|
spec.source.download(spec)
|
107
182
|
end
|
108
183
|
end
|
109
184
|
|
110
185
|
def do_install(bundle, options)
|
111
186
|
bundle.each do |spec|
|
112
|
-
next if
|
113
|
-
spec.loaded_from = @
|
187
|
+
next if spec.no_bundle?
|
188
|
+
spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec")
|
114
189
|
# Do nothing if the gem is already expanded
|
115
|
-
next if @
|
190
|
+
next if @gems_path.join(spec.full_name).directory?
|
116
191
|
|
117
192
|
case spec.source
|
118
193
|
when GemSource, GemDirectorySource, SystemGemSource
|
@@ -125,15 +200,16 @@ module Bundler
|
|
125
200
|
|
126
201
|
def generate_bins(bundle, options)
|
127
202
|
bundle.each do |spec|
|
128
|
-
next if
|
203
|
+
next if spec.no_bundle?
|
129
204
|
# HAX -- Generate the bin
|
130
|
-
bin_dir =
|
131
|
-
path =
|
205
|
+
bin_dir = bindir
|
206
|
+
path = gem_path
|
207
|
+
gems_path = @gems_path
|
132
208
|
installer = Gem::Installer.allocate
|
133
209
|
installer.instance_eval do
|
134
210
|
@spec = spec
|
135
211
|
@bin_dir = bin_dir
|
136
|
-
@gem_dir =
|
212
|
+
@gem_dir = gems_path.join(spec.full_name)
|
137
213
|
@gem_home = path
|
138
214
|
@wrappers = true
|
139
215
|
@format_executable = false
|
@@ -146,32 +222,35 @@ module Bundler
|
|
146
222
|
def expand_gemfile(spec, options)
|
147
223
|
Bundler.logger.info "Installing #{spec.name} (#{spec.version})"
|
148
224
|
|
149
|
-
gemfile = @
|
225
|
+
gemfile = @cache_path.join("#{spec.full_name}.gem").to_s
|
150
226
|
|
151
227
|
if build_args = options[:build_options] && options[:build_options][spec.name]
|
152
228
|
Gem::Command.build_args = build_args.map {|k,v| "--with-#{k}=#{v}"}
|
153
229
|
end
|
154
230
|
|
155
231
|
installer = Gem::Installer.new(gemfile, options.merge(
|
156
|
-
:install_dir =>
|
232
|
+
:install_dir => gem_path,
|
157
233
|
:ignore_dependencies => true,
|
158
234
|
:env_shebang => true,
|
159
235
|
:wrappers => true,
|
160
|
-
:bin_dir =>
|
236
|
+
:bin_dir => bindir
|
161
237
|
))
|
162
238
|
installer.install
|
239
|
+
rescue Gem::InstallError
|
240
|
+
cleanup_spec(spec)
|
241
|
+
raise
|
163
242
|
ensure
|
164
243
|
Gem::Command.build_args = []
|
165
244
|
end
|
166
245
|
|
167
246
|
def expand_vendored_gem(spec, options)
|
168
247
|
add_spec(spec)
|
169
|
-
FileUtils.mkdir_p(@
|
170
|
-
File.symlink(spec.location, @
|
248
|
+
FileUtils.mkdir_p(@gems_path)
|
249
|
+
File.symlink(spec.location, @gems_path.join(spec.full_name))
|
171
250
|
end
|
172
251
|
|
173
252
|
def add_spec(spec)
|
174
|
-
destination =
|
253
|
+
destination = @specs_path
|
175
254
|
destination.mkdir unless destination.exist?
|
176
255
|
|
177
256
|
File.open(destination.join("#{spec.full_name}.gemspec"), 'w') do |f|
|
@@ -189,17 +268,21 @@ module Bundler
|
|
189
268
|
|
190
269
|
to_delete.each do |spec|
|
191
270
|
Bundler.logger.info "Deleting gem: #{spec.name} (#{spec.version})"
|
192
|
-
|
193
|
-
FileUtils.rm_rf(@path.join("gems", spec.full_name))
|
271
|
+
cleanup_spec(spec)
|
194
272
|
# Cleanup the bin directory
|
195
273
|
spec.executables.each do |bin|
|
196
274
|
next if valid_executables.include?(bin)
|
197
275
|
Bundler.logger.info "Deleting bin file: #{bin}"
|
198
|
-
FileUtils.rm_rf(
|
276
|
+
FileUtils.rm_rf(bindir.join(bin))
|
199
277
|
end
|
200
278
|
end
|
201
279
|
end
|
202
280
|
|
281
|
+
def cleanup_spec(spec)
|
282
|
+
FileUtils.rm_rf(@specs_path.join("#{spec.full_name}.gemspec"))
|
283
|
+
FileUtils.rm_rf(@gems_path.join(spec.full_name))
|
284
|
+
end
|
285
|
+
|
203
286
|
def expand(options)
|
204
287
|
each_repo do |repo|
|
205
288
|
repo.expand(options)
|
@@ -207,42 +290,17 @@ module Bundler
|
|
207
290
|
end
|
208
291
|
|
209
292
|
def configure(specs, options)
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
def generate_environment(specs, options)
|
214
|
-
FileUtils.mkdir_p(path)
|
215
|
-
|
216
|
-
load_paths = load_paths_for_specs(specs, options)
|
217
|
-
bindir = @bindir.relative_path_from(path).to_s
|
218
|
-
filename = options[:manifest].relative_path_from(path).to_s
|
293
|
+
FileUtils.mkdir_p(gem_path)
|
219
294
|
|
220
|
-
File.open(
|
221
|
-
|
222
|
-
erb = ERB.new(template, nil, '-')
|
223
|
-
file.puts erb.result(binding)
|
295
|
+
File.open(gem_path.join("environment.rb"), "w") do |file|
|
296
|
+
file.puts @environment.environment_rb(specs, options)
|
224
297
|
end
|
225
|
-
end
|
226
|
-
|
227
|
-
def load_paths_for_specs(specs, options)
|
228
|
-
load_paths = []
|
229
|
-
specs.each do |spec|
|
230
|
-
next if options[:no_bundle].include?(spec.name)
|
231
|
-
gem_path = Pathname.new(spec.full_gem_path)
|
232
|
-
load_paths << load_path_for(gem_path, spec.bindir) if spec.bindir
|
233
|
-
spec.require_paths.each do |path|
|
234
|
-
load_paths << load_path_for(gem_path, path)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
load_paths
|
238
|
-
end
|
239
298
|
|
240
|
-
|
241
|
-
gem_path.join(path).relative_path_from(@path).to_s
|
299
|
+
generate_environment_picker
|
242
300
|
end
|
243
301
|
|
244
|
-
def
|
245
|
-
|
302
|
+
def generate_environment_picker
|
303
|
+
FileUtils.cp("#{File.dirname(__FILE__)}/templates/environment_picker.erb", path.join("environment.rb"))
|
246
304
|
end
|
247
305
|
|
248
306
|
def require_code(file, dep)
|
data/lib/bundler/cli.rb
CHANGED
@@ -31,32 +31,52 @@ module Bundler
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def initialize(options)
|
34
|
+
Bundler.mode = options[:cached] ? :local : :readwrite
|
34
35
|
@options = options
|
35
|
-
@
|
36
|
+
@bundle = Bundle.load(@options[:manifest])
|
36
37
|
end
|
37
38
|
|
38
39
|
def bundle
|
39
|
-
@
|
40
|
+
@bundle.install(@options)
|
40
41
|
end
|
41
42
|
|
42
43
|
def cache
|
43
|
-
@
|
44
|
+
gemfile = @options[:cache]
|
45
|
+
|
46
|
+
if File.extname(gemfile) == ".gem"
|
47
|
+
if !File.exist?(gemfile)
|
48
|
+
raise InvalidCacheArgument, "'#{gemfile}' does not exist."
|
49
|
+
end
|
50
|
+
@bundle.cache(gemfile)
|
51
|
+
elsif File.directory?(gemfile) || gemfile.include?('/')
|
52
|
+
if !File.directory?(gemfile)
|
53
|
+
raise InvalidCacheArgument, "'#{gemfile}' does not exist."
|
54
|
+
end
|
55
|
+
gemfiles = Dir["#{gemfile}/*.gem"]
|
56
|
+
if gemfiles.empty?
|
57
|
+
raise InvalidCacheArgument, "'#{gemfile}' contains no gemfiles"
|
58
|
+
end
|
59
|
+
@bundle.cache(*gemfiles)
|
60
|
+
else
|
61
|
+
raise InvalidCacheArgument, "w0t? '#{gemfile}' means nothing to me."
|
62
|
+
end
|
44
63
|
end
|
45
64
|
|
46
65
|
def prune
|
47
|
-
|
66
|
+
Bundler.mode = :local
|
67
|
+
@bundle.prune(@options)
|
48
68
|
end
|
49
69
|
|
50
70
|
def list
|
51
|
-
@
|
71
|
+
@bundle.list(@options)
|
52
72
|
end
|
53
73
|
|
54
74
|
def list_outdated
|
55
|
-
@
|
75
|
+
@bundle.list_outdated(@options)
|
56
76
|
end
|
57
77
|
|
58
78
|
def exec
|
59
|
-
@
|
79
|
+
@bundle.setup_environment
|
60
80
|
# w0t?
|
61
81
|
super(*$command)
|
62
82
|
end
|
@@ -19,7 +19,7 @@ class Gem::Commands::BundleCommand < Gem::Command
|
|
19
19
|
options[:cache] = gem
|
20
20
|
end
|
21
21
|
|
22
|
-
add_option('--prune-cache', "Removes all .gem files
|
22
|
+
add_option('--prune-cache', "Removes all .gem files that are not a part of the bundle from the cache") do
|
23
23
|
options[:prune] = true
|
24
24
|
end
|
25
25
|
|
data/lib/bundler/dependency.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Bundler
|
2
2
|
class InvalidEnvironmentName < StandardError; end
|
3
3
|
|
4
|
-
class Dependency
|
4
|
+
class Dependency < Gem::Dependency
|
5
5
|
attr_reader :name, :version, :require_as, :only, :except
|
6
6
|
attr_accessor :source
|
7
7
|
|
@@ -10,8 +10,8 @@ module Bundler
|
|
10
10
|
options[k.to_s] = v
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
super(name, options["version"] || ">= 0")
|
14
|
+
|
15
15
|
@require_as = options["require_as"]
|
16
16
|
@only = options["only"]
|
17
17
|
@except = options["except"]
|
@@ -31,10 +31,6 @@ module Bundler
|
|
31
31
|
true
|
32
32
|
end
|
33
33
|
|
34
|
-
def to_s
|
35
|
-
to_gem_dependency.to_s
|
36
|
-
end
|
37
|
-
|
38
34
|
def require_env(environment)
|
39
35
|
return unless in?(environment)
|
40
36
|
|
@@ -51,8 +47,8 @@ module Bundler
|
|
51
47
|
@block.call if @block
|
52
48
|
end
|
53
49
|
|
54
|
-
def
|
55
|
-
|
50
|
+
def no_bundle?
|
51
|
+
source == SystemGemSource.instance
|
56
52
|
end
|
57
53
|
|
58
54
|
def ==(o)
|
@@ -60,5 +56,7 @@ module Bundler
|
|
60
56
|
[o.name, o.version, o.require_as, o.only, o.except]
|
61
57
|
end
|
62
58
|
|
59
|
+
alias version version_requirements
|
60
|
+
|
63
61
|
end
|
64
62
|
end
|
data/lib/bundler/dsl.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
module Bundler
|
2
2
|
class ManifestFileNotFound < StandardError; end
|
3
|
+
class InvalidKey < StandardError; end
|
4
|
+
class DefaultManifestNotFound < StandardError; end
|
3
5
|
|
4
6
|
class Dsl
|
5
|
-
def self.evaluate(
|
6
|
-
builder = new(environment)
|
7
|
+
def self.evaluate(file, bundle, environment)
|
8
|
+
builder = new(bundle, environment)
|
7
9
|
builder.instance_eval(File.read(file.to_s), file.to_s, 1)
|
10
|
+
environment
|
8
11
|
end
|
9
12
|
|
10
|
-
def initialize(environment)
|
13
|
+
def initialize(bundle, environment)
|
14
|
+
@bundle = bundle
|
11
15
|
@environment = environment
|
12
16
|
@directory_sources = []
|
13
17
|
@git_sources = {}
|
@@ -15,15 +19,11 @@ module Bundler
|
|
15
19
|
end
|
16
20
|
|
17
21
|
def bundle_path(path)
|
18
|
-
path = Pathname.new(path)
|
19
|
-
@environment.gem_path = (path.relative? ?
|
20
|
-
@environment.root.join(path) : path).expand_path
|
22
|
+
@bundle.path = Pathname.new(path)
|
21
23
|
end
|
22
24
|
|
23
25
|
def bin_path(path)
|
24
|
-
|
25
|
-
@environment.bindir = (path.relative? ?
|
26
|
-
@environment.root.join(path) : path).expand_path
|
26
|
+
@bundle.bindir = Pathname.new(path)
|
27
27
|
end
|
28
28
|
|
29
29
|
def disable_rubygems
|
@@ -35,7 +35,7 @@ module Bundler
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def source(source)
|
38
|
-
source = GemSource.new(:uri => source)
|
38
|
+
source = GemSource.new(@bundle, :uri => source)
|
39
39
|
unless @environment.sources.include?(source)
|
40
40
|
@environment.add_source(source)
|
41
41
|
end
|
@@ -55,7 +55,7 @@ module Bundler
|
|
55
55
|
|
56
56
|
def directory(path, options = {})
|
57
57
|
raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
|
58
|
-
@directory = DirectorySource.new(options.merge(:location => path))
|
58
|
+
@directory = DirectorySource.new(@bundle, options.merge(:location => path))
|
59
59
|
@directory_sources << @directory
|
60
60
|
@environment.add_priority_source(@directory)
|
61
61
|
retval = yield if block_given?
|
@@ -65,7 +65,7 @@ module Bundler
|
|
65
65
|
|
66
66
|
def git(uri, options = {})
|
67
67
|
raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
|
68
|
-
@git = GitSource.new(options.merge(:uri => uri))
|
68
|
+
@git = GitSource.new(@bundle, options.merge(:uri => uri))
|
69
69
|
@git_sources[uri] = @git
|
70
70
|
@environment.add_priority_source(@git)
|
71
71
|
retval = yield if block_given?
|
@@ -81,6 +81,11 @@ module Bundler
|
|
81
81
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
82
82
|
version = args.last
|
83
83
|
|
84
|
+
keys = :vendored_at, :path, :only, :except, :git, :path, :bundle, :require_as, :tag, :branch, :ref
|
85
|
+
unless (invalid = options.keys - keys).empty?
|
86
|
+
raise InvalidKey, "Only #{keys.join(", ")} are valid options to #gem. You used #{invalid.join(", ")}"
|
87
|
+
end
|
88
|
+
|
84
89
|
if path = options.delete(:vendored_at)
|
85
90
|
options[:path] = path
|
86
91
|
warn "The :vendored_at option is deprecated. Use :path instead.\nFrom #{caller[0]}"
|
@@ -92,7 +97,7 @@ module Bundler
|
|
92
97
|
dep = Dependency.new(name, options.merge(:version => version))
|
93
98
|
|
94
99
|
if options.key?(:bundle) && !options[:bundle]
|
95
|
-
dep.source = SystemGemSource.
|
100
|
+
dep.source = SystemGemSource.new(@bundle)
|
96
101
|
elsif @git || options[:git]
|
97
102
|
dep.source = _handle_git_option(name, version, options)
|
98
103
|
elsif @directory || options[:path]
|
@@ -104,12 +109,16 @@ module Bundler
|
|
104
109
|
|
105
110
|
private
|
106
111
|
|
112
|
+
def _version?(version)
|
113
|
+
version && Gem::Version.new(version) rescue false
|
114
|
+
end
|
115
|
+
|
107
116
|
def _handle_vendored_option(name, version, options)
|
108
117
|
dir, path = _find_directory_source(options[:path])
|
109
118
|
|
110
119
|
if dir
|
111
120
|
dir.required_specs << name
|
112
|
-
dir.add_spec(path, name, version) if version
|
121
|
+
dir.add_spec(path, name, version) if _version?(version)
|
113
122
|
dir
|
114
123
|
else
|
115
124
|
directory options[:path] do
|
@@ -123,7 +132,7 @@ module Bundler
|
|
123
132
|
return @directory, Pathname.new(path || '')
|
124
133
|
end
|
125
134
|
|
126
|
-
path = @
|
135
|
+
path = @bundle.gemfile.dirname.join(path)
|
127
136
|
|
128
137
|
@directory_sources.each do |s|
|
129
138
|
if s.location.expand_path.to_s < path.expand_path.to_s
|
@@ -136,7 +145,7 @@ module Bundler
|
|
136
145
|
|
137
146
|
def _handle_git_option(name, version, options)
|
138
147
|
git = options[:git].to_s
|
139
|
-
ref = options[:
|
148
|
+
ref = options[:ref] || options[:tag]
|
140
149
|
branch = options[:branch]
|
141
150
|
|
142
151
|
if source = @git || @git_sources[git]
|
@@ -147,7 +156,7 @@ module Bundler
|
|
147
156
|
end
|
148
157
|
|
149
158
|
source.required_specs << name
|
150
|
-
source.add_spec(Pathname.new(options[:path] || '.'), name, version) if version
|
159
|
+
source.add_spec(Pathname.new(options[:path] || '.'), name, version) if _version?(version)
|
151
160
|
source
|
152
161
|
else
|
153
162
|
git(git, :ref => ref, :branch => branch) do
|