bundler 1.10.6 → 1.11.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +105 -0
  3. data/.rubocop_todo.yml +120 -0
  4. data/.travis.yml +8 -23
  5. data/CHANGELOG.md +69 -0
  6. data/CODE_OF_CONDUCT.md +6 -4
  7. data/DEVELOPMENT.md +4 -5
  8. data/README.md +2 -2
  9. data/Rakefile +70 -87
  10. data/bin/rake +14 -0
  11. data/bin/rspec +10 -0
  12. data/bin/rubocop +11 -0
  13. data/bundler.gemspec +17 -15
  14. data/exe/bundle +20 -0
  15. data/{bin → exe}/bundle_ruby +6 -4
  16. data/exe/bundler +20 -0
  17. data/lib/bundler.rb +98 -119
  18. data/lib/bundler/capistrano.rb +2 -2
  19. data/lib/bundler/cli.rb +85 -74
  20. data/lib/bundler/cli/binstubs.rb +1 -2
  21. data/lib/bundler/cli/cache.rb +0 -1
  22. data/lib/bundler/cli/check.rb +7 -5
  23. data/lib/bundler/cli/clean.rb +0 -1
  24. data/lib/bundler/cli/common.rb +6 -7
  25. data/lib/bundler/cli/config.rb +69 -56
  26. data/lib/bundler/cli/console.rb +8 -8
  27. data/lib/bundler/cli/exec.rb +4 -3
  28. data/lib/bundler/cli/gem.rb +50 -39
  29. data/lib/bundler/cli/init.rb +5 -6
  30. data/lib/bundler/cli/inject.rb +1 -2
  31. data/lib/bundler/cli/install.rb +18 -21
  32. data/lib/bundler/cli/lock.rb +8 -3
  33. data/lib/bundler/cli/open.rb +4 -5
  34. data/lib/bundler/cli/outdated.rb +7 -8
  35. data/lib/bundler/cli/package.rb +1 -1
  36. data/lib/bundler/cli/platform.rb +2 -3
  37. data/lib/bundler/cli/show.rb +9 -9
  38. data/lib/bundler/cli/update.rb +2 -3
  39. data/lib/bundler/cli/viz.rb +1 -2
  40. data/lib/bundler/constants.rb +1 -1
  41. data/lib/bundler/current_ruby.rb +38 -3
  42. data/lib/bundler/definition.rb +83 -88
  43. data/lib/bundler/dep_proxy.rb +11 -9
  44. data/lib/bundler/dependency.rb +26 -11
  45. data/lib/bundler/deployment.rb +2 -2
  46. data/lib/bundler/deprecate.rb +3 -3
  47. data/lib/bundler/dsl.rb +63 -44
  48. data/lib/bundler/env.rb +19 -12
  49. data/lib/bundler/environment.rb +1 -2
  50. data/lib/bundler/errors.rb +82 -0
  51. data/lib/bundler/fetcher.rb +45 -39
  52. data/lib/bundler/fetcher/base.rb +20 -7
  53. data/lib/bundler/fetcher/dependency.rb +5 -5
  54. data/lib/bundler/fetcher/downloader.rb +1 -2
  55. data/lib/bundler/fetcher/index.rb +4 -7
  56. data/lib/bundler/friendly_errors.rb +15 -8
  57. data/lib/bundler/gem_helper.rb +44 -35
  58. data/lib/bundler/gem_helpers.rb +7 -8
  59. data/lib/bundler/gem_remote_fetcher.rb +41 -0
  60. data/lib/bundler/gem_tasks.rb +4 -1
  61. data/lib/bundler/graph.rb +25 -24
  62. data/lib/bundler/index.rb +21 -18
  63. data/lib/bundler/injector.rb +2 -4
  64. data/lib/bundler/inline.rb +3 -3
  65. data/lib/bundler/installer.rb +57 -144
  66. data/lib/bundler/installer/gem_installer.rb +76 -0
  67. data/lib/bundler/installer/parallel_installer.rb +22 -13
  68. data/lib/bundler/installer/standalone.rb +48 -0
  69. data/lib/bundler/lazy_specification.rb +3 -4
  70. data/lib/bundler/lockfile_parser.rb +21 -19
  71. data/lib/bundler/match_platform.rb +4 -4
  72. data/lib/bundler/psyched_yaml.rb +3 -3
  73. data/lib/bundler/remote_specification.rb +1 -1
  74. data/lib/bundler/resolver.rb +93 -88
  75. data/lib/bundler/retry.rb +9 -10
  76. data/lib/bundler/ruby_dsl.rb +1 -1
  77. data/lib/bundler/ruby_version.rb +7 -10
  78. data/lib/bundler/rubygems_ext.rb +32 -27
  79. data/lib/bundler/{gem_installer.rb → rubygems_gem_installer.rb} +2 -2
  80. data/lib/bundler/rubygems_integration.rb +85 -70
  81. data/lib/bundler/runtime.rb +57 -61
  82. data/lib/bundler/settings.rb +27 -26
  83. data/lib/bundler/setup.rb +3 -3
  84. data/lib/bundler/shared_helpers.rb +45 -20
  85. data/lib/bundler/similarity_detector.rb +19 -21
  86. data/lib/bundler/source.rb +4 -5
  87. data/lib/bundler/source/git.rb +29 -31
  88. data/lib/bundler/source/git/git_proxy.rb +52 -26
  89. data/lib/bundler/source/path.rb +25 -28
  90. data/lib/bundler/source/path/installer.rb +4 -4
  91. data/lib/bundler/source/rubygems.rb +62 -48
  92. data/lib/bundler/source/rubygems/remote.rb +3 -3
  93. data/lib/bundler/source_list.rb +4 -4
  94. data/lib/bundler/spec_set.rb +17 -15
  95. data/lib/bundler/ssl_certs/certificate_manager.rb +5 -6
  96. data/lib/bundler/stub_specification.rb +2 -2
  97. data/lib/bundler/templates/Executable +5 -5
  98. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +42 -6
  99. data/lib/bundler/templates/newgem/README.md.tt +1 -1
  100. data/lib/bundler/templates/newgem/Rakefile.tt +4 -2
  101. data/lib/bundler/templates/newgem/bin/setup.tt +2 -1
  102. data/lib/bundler/templates/newgem/newgem.gemspec.tt +2 -2
  103. data/lib/bundler/ui.rb +3 -3
  104. data/lib/bundler/ui/rg_proxy.rb +2 -2
  105. data/lib/bundler/ui/shell.rb +10 -6
  106. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +82 -71
  107. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +1 -1
  108. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +9 -0
  109. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +40 -21
  110. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +8 -0
  111. data/lib/bundler/vendored_molinillo.rb +1 -1
  112. data/lib/bundler/vendored_persistent.rb +3 -3
  113. data/lib/bundler/vendored_thor.rb +2 -2
  114. data/lib/bundler/version.rb +1 -1
  115. data/lib/bundler/vlad.rb +1 -1
  116. data/lib/bundler/worker.rb +4 -5
  117. data/man/bundle-config.ronn +4 -2
  118. data/man/bundle-gem.ronn +77 -0
  119. data/man/bundle-install.ronn +13 -6
  120. data/man/bundle-lock.ronn +47 -0
  121. data/man/bundle.ronn +1 -1
  122. data/man/gemfile.5.ronn +8 -0
  123. data/man/index.txt +1 -0
  124. metadata +37 -8
  125. data/bin/bundle +0 -21
  126. data/bin/bundler +0 -21
@@ -5,7 +5,7 @@ module Bundler
5
5
  include SharedHelpers
6
6
 
7
7
  def setup(*groups)
8
- groups.map! { |g| g.to_sym }
8
+ groups.map!(&:to_sym)
9
9
 
10
10
  # Has to happen first
11
11
  clean_load_path
@@ -21,7 +21,7 @@ module Bundler
21
21
  raise GemNotFound, "#{spec.full_name} is missing. Run `bundle` to get it."
22
22
  end
23
23
 
24
- if activated_spec = Bundler.rubygems.loaded_specs(spec.name) and activated_spec.version != spec.version
24
+ if (activated_spec = Bundler.rubygems.loaded_specs(spec.name)) && activated_spec.version != spec.version
25
25
  e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \
26
26
  "but your Gemfile requires #{spec.name} #{spec.version}. Prepending " \
27
27
  "`bundle exec` to your command may solve this."
@@ -35,7 +35,7 @@ module Bundler
35
35
  end
36
36
 
37
37
  Bundler.rubygems.mark_loaded(spec)
38
- load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include?(path)}
38
+ load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include?(path) }
39
39
  $LOAD_PATH.unshift(*load_paths)
40
40
  end
41
41
 
@@ -55,13 +55,13 @@ module Bundler
55
55
  ]
56
56
 
57
57
  def require(*groups)
58
- groups.map! { |g| g.to_sym }
58
+ groups.map!(&:to_sym)
59
59
  groups = [:default] if groups.empty?
60
60
 
61
61
  @definition.dependencies.each do |dep|
62
62
  # Skip the dependency if it is not in any of the requested
63
63
  # groups
64
- next unless ((dep.groups & groups).any? && dep.current_platform?)
64
+ next unless (dep.groups & groups).any? && dep.current_platform?
65
65
 
66
66
  required_file = nil
67
67
 
@@ -73,18 +73,24 @@ module Bundler
73
73
  # Allow `require: true` as an alias for `require: <name>`
74
74
  file = dep.name if file == true
75
75
  required_file = file
76
- Kernel.require file
76
+ begin
77
+ Kernel.require file
78
+ rescue => e
79
+ raise e if e.is_a?(LoadError) # we handle this a little later
80
+ raise Bundler::GemRequireError.new e,
81
+ "There was an error while trying to load the gem '#{file}'."
82
+ end
77
83
  end
78
84
  rescue LoadError => e
79
- REQUIRE_ERRORS.find { |r| r =~ e.message }
85
+ REQUIRE_ERRORS.find {|r| r =~ e.message }
80
86
  raise if dep.autorequire || $1 != required_file
81
87
 
82
- if dep.autorequire.nil? && dep.name.include?('-')
88
+ if dep.autorequire.nil? && dep.name.include?("-")
83
89
  begin
84
- namespaced_file = dep.name.gsub('-', '/')
90
+ namespaced_file = dep.name.tr("-", "/")
85
91
  Kernel.require namespaced_file
86
92
  rescue LoadError => e
87
- REQUIRE_ERRORS.find { |r| r =~ e.message }
93
+ REQUIRE_ERRORS.find {|r| r =~ e.message }
88
94
  raise if $1 != namespaced_file
89
95
  end
90
96
  end
@@ -96,19 +102,21 @@ module Bundler
96
102
  if groups.empty?
97
103
  dependencies
98
104
  else
99
- dependencies.select { |d| (groups & d.groups).any? }
105
+ dependencies.select {|d| (groups & d.groups).any? }
100
106
  end
101
107
  end
102
108
 
103
- alias gems specs
109
+ alias_method :gems, :specs
104
110
 
105
111
  def cache(custom_path = nil)
106
112
  cache_path = Bundler.app_cache(custom_path)
107
- FileUtils.mkdir_p(cache_path) unless File.exist?(cache_path)
113
+ SharedHelpers.filesystem_access(cache_path) do |p|
114
+ FileUtils.mkdir_p(p)
115
+ end unless File.exist?(cache_path)
108
116
 
109
117
  Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}"
110
118
  specs.each do |spec|
111
- next if spec.name == 'bundler'
119
+ next if spec.name == "bundler"
112
120
  spec.source.send(:fetch_gem, spec) if Bundler.settings[:cache_all_platforms] && spec.source.respond_to?(:fetch_gem, true)
113
121
  spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
114
122
  end
@@ -122,7 +130,9 @@ module Bundler
122
130
  end
123
131
 
124
132
  def prune_cache(cache_path)
125
- FileUtils.mkdir_p(cache_path) unless File.exist?(cache_path)
133
+ SharedHelpers.filesystem_access(cache_path) do |p|
134
+ FileUtils.mkdir_p(p)
135
+ end unless File.exist?(cache_path)
126
136
  resolve = @definition.resolve
127
137
  prune_gem_cache(resolve, cache_path)
128
138
  prune_git_and_path_cache(resolve, cache_path)
@@ -159,51 +169,20 @@ module Bundler
159
169
  spec_gem_executables.flatten!
160
170
 
161
171
  stale_gem_bins = gem_bins - spec_gem_executables
162
- stale_git_dirs = git_dirs - spec_git_paths
172
+ stale_git_dirs = git_dirs - spec_git_paths - ["#{Gem.dir}/bundler/gems/extensions"]
163
173
  stale_git_cache_dirs = git_cache_dirs - spec_git_cache_dirs
164
174
  stale_gem_dirs = gem_dirs - spec_gem_paths
165
175
  stale_gem_files = gem_files - spec_cache_paths
166
176
  stale_gemspec_files = gemspec_files - spec_gemspec_paths
167
177
 
168
- output = stale_gem_dirs.collect do |gem_dir|
169
- full_name = Pathname.new(gem_dir).basename.to_s
170
-
171
- parts = full_name.split('-')
172
- name = parts[0..-2].join('-')
173
- version = parts.last
174
- output = "#{name} (#{version})"
175
-
176
- if dry_run
177
- Bundler.ui.info "Would have removed #{output}"
178
- else
179
- Bundler.ui.info "Removing #{output}"
180
- FileUtils.rm_rf(gem_dir)
181
- end
182
-
183
- output
184
- end + stale_git_dirs.collect do |gem_dir|
185
- full_name = Pathname.new(gem_dir).basename.to_s
186
-
187
- parts = full_name.split('-')
188
- name = parts[0..-2].join('-')
189
- revision = parts[-1]
190
- output = "#{name} (#{revision})"
191
-
192
- if dry_run
193
- Bundler.ui.info "Would have removed #{output}"
194
- else
195
- Bundler.ui.info "Removing #{output}"
196
- FileUtils.rm_rf(gem_dir)
197
- end
198
-
199
- output
200
- end
178
+ removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) }
179
+ removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) }
180
+ output = removed_stale_gem_dirs + removed_stale_git_dirs
201
181
 
202
182
  unless dry_run
203
- stale_gem_bins.each { |bin| FileUtils.rm(bin) if File.exist?(bin) }
204
- stale_gem_files.each { |file| FileUtils.rm(file) if File.exist?(file) }
205
- stale_gemspec_files.each { |file| FileUtils.rm(file) if File.exist?(file) }
206
- stale_git_cache_dirs.each { |dir| FileUtils.rm_rf(dir) if File.exist?(dir) }
183
+ stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files
184
+ stale_files.each {|file| FileUtils.rm(file) if File.exist?(file) }
185
+ stale_git_cache_dirs.each {|dir| FileUtils.rm_rf(dir) if File.exist?(dir) }
207
186
  end
208
187
 
209
188
  output
@@ -213,7 +192,7 @@ module Bundler
213
192
  begin
214
193
  ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.bin_path("bundler", "bundle", VERSION)
215
194
  rescue Gem::GemNotFoundException
216
- ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../bin/bundle", __FILE__)
195
+ ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../exe/bundle", __FILE__)
217
196
  end
218
197
 
219
198
  # Set BUNDLE_GEMFILE
@@ -225,7 +204,7 @@ module Bundler
225
204
  private
226
205
 
227
206
  def prune_gem_cache(resolve, cache_path)
228
- cached = Dir["#{cache_path}/*.gem"]
207
+ cached = Dir["#{cache_path}/*.gem"]
229
208
 
230
209
  cached = cached.delete_if do |path|
231
210
  spec = Bundler.rubygems.spec_from_gem path
@@ -246,7 +225,7 @@ module Bundler
246
225
  end
247
226
 
248
227
  def prune_git_and_path_cache(resolve, cache_path)
249
- cached = Dir["#{cache_path}/*/.bundlecache"]
228
+ cached = Dir["#{cache_path}/*/.bundlecache"]
250
229
 
251
230
  cached = cached.delete_if do |path|
252
231
  name = File.basename(File.dirname(path))
@@ -270,20 +249,37 @@ module Bundler
270
249
 
271
250
  def setup_manpath
272
251
  # Store original MANPATH for restoration later in with_clean_env()
273
- ENV['BUNDLE_ORIG_MANPATH'] = ENV['MANPATH']
252
+ ENV["BUNDLE_ORIG_MANPATH"] = ENV["MANPATH"]
274
253
 
275
254
  # Add man/ subdirectories from activated bundles to MANPATH for man(1)
276
255
  manuals = $LOAD_PATH.map do |path|
277
- man_subdir = path.sub(/lib$/, 'man')
278
- man_subdir unless Dir[man_subdir + '/man?/'].empty?
256
+ man_subdir = path.sub(/lib$/, "man")
257
+ man_subdir unless Dir[man_subdir + "/man?/"].empty?
279
258
  end.compact
280
259
 
281
260
  unless manuals.empty?
282
- ENV['MANPATH'] = manuals.concat(
283
- ENV['MANPATH'].to_s.split(File::PATH_SEPARATOR)
261
+ ENV["MANPATH"] = manuals.concat(
262
+ ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR)
284
263
  ).uniq.join(File::PATH_SEPARATOR)
285
264
  end
286
265
  end
287
266
 
267
+ def remove_dir(dir, dry_run)
268
+ full_name = Pathname.new(dir).basename.to_s
269
+
270
+ parts = full_name.split("-")
271
+ name = parts[0..-2].join("-")
272
+ version = parts.last
273
+ output = "#{name} (#{version})"
274
+
275
+ if dry_run
276
+ Bundler.ui.info "Would have removed #{output}"
277
+ else
278
+ Bundler.ui.info "Removing #{output}"
279
+ FileUtils.rm_rf(dir)
280
+ end
281
+
282
+ output
283
+ end
288
284
  end
289
285
  end
@@ -1,10 +1,10 @@
1
- require 'uri'
1
+ require "uri"
2
2
 
3
3
  module Bundler
4
4
  class Settings
5
- BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check ignore_messages gem.mit gem.coc).freeze
6
- NUMBER_KEYS = %w(retry timeout redirect).freeze
7
- DEFAULT_CONFIG = {:retry => 3, :timeout => 10, :redirect => 5}
5
+ BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check ignore_messages gem.mit gem.coc silence_root_warning).freeze
6
+ NUMBER_KEYS = %w(retry timeout redirect ssl_verify_mode).freeze
7
+ DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 }
8
8
 
9
9
  def initialize(root = nil)
10
10
  @root = root
@@ -17,9 +17,11 @@ module Bundler
17
17
  value = (@local_config[key] || ENV[key] || @global_config[key] || DEFAULT_CONFIG[name])
18
18
 
19
19
  case
20
- when !value.nil? && is_bool(name)
20
+ when value.nil?
21
+ nil
22
+ when is_bool(name) || value == "false"
21
23
  to_bool(value)
22
- when !value.nil? && is_num(name)
24
+ when is_num(name)
23
25
  value.to_i
24
26
  else
25
27
  value
@@ -27,11 +29,11 @@ module Bundler
27
29
  end
28
30
 
29
31
  def []=(key, value)
30
- local_config_file or raise GemfileNotFound, "Could not locate Gemfile"
32
+ local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")
31
33
  set_key(key, value, @local_config, local_config_file)
32
34
  end
33
35
 
34
- alias :set_local :[]=
36
+ alias_method :set_local, :[]=
35
37
 
36
38
  def delete(key)
37
39
  @local_config.delete(key_for(key))
@@ -42,21 +44,19 @@ module Bundler
42
44
  end
43
45
 
44
46
  def all
45
- env_keys = ENV.keys.select { |k| k =~ /BUNDLE_.*/ }
47
+ env_keys = ENV.keys.select {|k| k =~ /BUNDLE_.*/ }
46
48
 
47
49
  keys = @global_config.keys | @local_config.keys | env_keys
48
50
 
49
51
  keys.map do |key|
50
- key.sub(/^BUNDLE_/, '').gsub(/__/, ".").downcase
52
+ key.sub(/^BUNDLE_/, "").gsub(/__/, ".").downcase
51
53
  end
52
54
  end
53
55
 
54
56
  def local_overrides
55
57
  repos = {}
56
58
  all.each do |k|
57
- if k =~ /^local\./
58
- repos[$'] = self[k]
59
- end
59
+ repos[$'] = self[k] if k =~ /^local\./
60
60
  end
61
61
  repos
62
62
  end
@@ -147,7 +147,7 @@ module Bundler
147
147
  end
148
148
 
149
149
  def ignore_config?
150
- ENV['BUNDLE_IGNORE_CONFIG']
150
+ ENV["BUNDLE_IGNORE_CONFIG"]
151
151
  end
152
152
 
153
153
  def app_cache_path
@@ -159,10 +159,9 @@ module Bundler
159
159
  end
160
160
 
161
161
  private
162
+
162
163
  def key_for(key)
163
- if key.is_a?(String) && /https?:/ =~ key
164
- key = normalize_uri(key).to_s
165
- end
164
+ key = normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
166
165
  key = key.to_s.gsub(".", "__").upcase
167
166
  "BUNDLE_#{key}"
168
167
  end
@@ -184,7 +183,7 @@ module Bundler
184
183
  end
185
184
 
186
185
  def to_bool(value)
187
- !(value.nil? || value == '' || value =~ /^(false|f|no|n|0)$/i || value == false)
186
+ !(value.nil? || value == "" || value =~ /^(false|f|no|n|0)$/i || value == false)
188
187
  end
189
188
 
190
189
  def is_num(value)
@@ -192,11 +191,11 @@ module Bundler
192
191
  end
193
192
 
194
193
  def get_array(key)
195
- self[key] ? self[key].split(":").map { |w| w.to_sym } : []
194
+ self[key] ? self[key].split(":").map(&:to_sym) : []
196
195
  end
197
196
 
198
197
  def set_array(key, array)
199
- self[key] = (array.empty? ? nil : array.join(":")) if array
198
+ self[key] = (array.empty? ? nil : array.join(":")) if array
200
199
  end
201
200
 
202
201
  def set_key(key, value, hash, file)
@@ -205,9 +204,11 @@ module Bundler
205
204
  unless hash[key] == value
206
205
  hash[key] = value
207
206
  hash.delete(key) if value.nil?
208
- FileUtils.mkdir_p(file.dirname)
209
- require 'bundler/psyched_yaml'
210
- File.open(file, "w") { |f| f.puts YAML.dump(hash) }
207
+ SharedHelpers.filesystem_access(file) do |p|
208
+ FileUtils.mkdir_p(p.dirname)
209
+ require "bundler/psyched_yaml"
210
+ File.open(p, "w") {|f| f.puts YAML.dump(hash) }
211
+ end
211
212
  end
212
213
 
213
214
  value
@@ -226,6 +227,7 @@ module Bundler
226
227
  valid_file = config_file && config_file.exist? && !config_file.size.zero?
227
228
  if !ignore_config? && valid_file
228
229
  config_regex = /^(BUNDLE_.+): (['"]?)(.*(?:\n(?!BUNDLE).+)?)\2$/
230
+ raise PermissionError.new(config_file, :read) unless config_file.readable?
229
231
  config_pairs = config_file.read.scan(config_regex).map do |m|
230
232
  key, _, value = m
231
233
  [convert_to_backward_compatible_key(key), value.gsub(/\s+/, " ").tr('"', "'")]
@@ -237,7 +239,7 @@ module Bundler
237
239
  end
238
240
 
239
241
  def convert_to_backward_compatible_key(key)
240
- key = "#{key}/" if key =~ /https?:/i && key !~ %r[/\Z]
242
+ key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z}
241
243
  key = key.gsub(".", "__") if key.include?(".")
242
244
  key
243
245
  end
@@ -246,13 +248,12 @@ module Bundler
246
248
  # TODO: is this the correct place to validate mirror URIs?
247
249
  def normalize_uri(uri)
248
250
  uri = uri.to_s
249
- uri = "#{uri}/" unless uri =~ %r[/\Z]
251
+ uri = "#{uri}/" unless uri =~ %r{/\Z}
250
252
  uri = URI(uri)
251
253
  unless uri.absolute?
252
254
  raise ArgumentError, "Gem sources must be absolute. You provided '#{uri}'."
253
255
  end
254
256
  uri
255
257
  end
256
-
257
258
  end
258
259
  end
@@ -1,9 +1,9 @@
1
- require 'bundler/shared_helpers'
1
+ require "bundler/shared_helpers"
2
2
 
3
3
  if Bundler::SharedHelpers.in_bundle?
4
- require 'bundler'
4
+ require "bundler"
5
5
 
6
- if STDOUT.tty? || ENV['BUNDLER_FORCE_TTY']
6
+ if STDOUT.tty? || ENV["BUNDLER_FORCE_TTY"]
7
7
  begin
8
8
  Bundler.setup
9
9
  rescue Bundler::BundlerError => e
@@ -1,13 +1,13 @@
1
- require 'pathname'
2
- require 'rubygems'
1
+ require "pathname"
2
+ require "rubygems"
3
3
 
4
- require 'bundler/constants'
5
- require 'bundler/rubygems_integration'
6
- require 'bundler/current_ruby'
4
+ require "bundler/constants"
5
+ require "bundler/rubygems_integration"
6
+ require "bundler/current_ruby"
7
7
 
8
8
  module Gem
9
9
  class Dependency
10
- if !instance_methods.map { |m| m.to_s }.include?("requirement")
10
+ unless method_defined? :requirement
11
11
  def requirement
12
12
  version_requirements
13
13
  end
@@ -29,7 +29,7 @@ module Bundler
29
29
  gemfile = default_gemfile
30
30
 
31
31
  case gemfile.basename.to_s
32
- when 'gems.rb' then Pathname.new(gemfile.sub(/.rb$/, '.locked'))
32
+ when "gems.rb" then Pathname.new(gemfile.sub(/.rb$/, ".locked"))
33
33
  else Pathname.new("#{gemfile}.lock")
34
34
  end
35
35
  end
@@ -56,12 +56,12 @@ module Bundler
56
56
 
57
57
  def pwd
58
58
  Bundler.rubygems.ext_lock.synchronize do
59
- Dir.pwd
59
+ Pathname.pwd
60
60
  end
61
61
  end
62
62
 
63
63
  def with_clean_git_env(&block)
64
- keys = %w[GIT_DIR GIT_WORK_TREE]
64
+ keys = %w(GIT_DIR GIT_WORK_TREE)
65
65
  old_env = keys.inject({}) do |h, k|
66
66
  h.update(k => ENV[k])
67
67
  end
@@ -81,30 +81,54 @@ module Bundler
81
81
 
82
82
  # Set RUBYOPT
83
83
  rubyopt = [ENV["RUBYOPT"]].compact
84
- if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/
85
- rubyopt.unshift %|-rbundler/setup|
86
- ENV["RUBYOPT"] = rubyopt.join(' ')
84
+ if rubyopt.empty? || rubyopt.first !~ %r{-rbundler/setup}
85
+ rubyopt.unshift %(-rbundler/setup)
86
+ ENV["RUBYOPT"] = rubyopt.join(" ")
87
87
  end
88
88
 
89
89
  # Set RUBYLIB
90
90
  rubylib = (ENV["RUBYLIB"] || "").split(File::PATH_SEPARATOR)
91
- rubylib.unshift File.expand_path('../..', __FILE__)
91
+ rubylib.unshift File.expand_path("../..", __FILE__)
92
92
  ENV["RUBYLIB"] = rubylib.uniq.join(File::PATH_SEPARATOR)
93
93
  end
94
94
 
95
+ # Rescues permissions errors raised by file system operations
96
+ # (ie. Errno:EACCESS) and raises more friendly errors instead.
97
+ #
98
+ # @param path [String] the path that the action will be attempted to
99
+ # @param action [Symbol, #to_s] the type of operation that will be
100
+ # performed. For example: :write, :read, :exec
101
+ #
102
+ # @yield path
103
+ #
104
+ # @raise [Bundler::PermissionError] if Errno:EACCES is raised in the
105
+ # given block
106
+ #
107
+ # @example
108
+ # filesystem_access("vendor/cache", :write) do
109
+ # FileUtils.mkdir_p("vendor/cache")
110
+ # end
111
+ #
112
+ # @see {Bundler::PermissionError}
113
+ def filesystem_access(path, action = :write)
114
+ yield path
115
+ rescue Errno::EACCES
116
+ raise PermissionError.new(path, action)
117
+ end
118
+
95
119
  private
96
120
 
97
121
  def find_gemfile
98
- given = ENV['BUNDLE_GEMFILE']
122
+ given = ENV["BUNDLE_GEMFILE"]
99
123
  return given if given && !given.empty?
100
124
 
101
- find_file('Gemfile', 'gems.rb')
125
+ find_file("Gemfile", "gems.rb")
102
126
  end
103
127
 
104
128
  def find_file(*names)
105
- search_up(*names) {|filename|
129
+ search_up(*names) do |filename|
106
130
  return filename if File.file?(filename)
107
- }
131
+ end
108
132
  end
109
133
 
110
134
  def find_directory(*names)
@@ -118,16 +142,17 @@ module Bundler
118
142
  current = File.expand_path(SharedHelpers.pwd)
119
143
 
120
144
  until !File.directory?(current) || current == previous
121
- if ENV['BUNDLE_SPEC_RUN']
145
+ if ENV["BUNDLE_SPEC_RUN"]
122
146
  # avoid stepping above the tmp directory when testing
123
- return nil if File.file?(File.join(current, 'bundler.gemspec'))
147
+ return nil if File.file?(File.join(current, "bundler.gemspec"))
124
148
  end
125
149
 
126
150
  names.each do |name|
127
151
  filename = File.join(current, name)
128
152
  yield filename
129
153
  end
130
- current, previous = File.expand_path("..", current), current
154
+ previous = current
155
+ current = File.expand_path("..", current)
131
156
  end
132
157
  end
133
158