diff options
Diffstat (limited to 'lib/bundler')
32 files changed, 148 insertions, 183 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 55bf274596..5f06fea6e7 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -4,7 +4,7 @@ require "bundler/vendored_thor" module Bundler class CLI < Thor include Thor::Actions - AUTO_INSTALL_CMDS = %w[show binstubs outdated exec open console licenses clean] + AUTO_INSTALL_CMDS = %w(show binstubs outdated exec open console licenses clean) def self.start(*) super diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index 53b30d2045..b90544ba3a 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -51,6 +51,5 @@ module Bundler message += "\nDid you mean #{suggestions}?" if suggestions message end - end end diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 7d71ac8c44..5a7e92d535 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -61,10 +61,10 @@ module Bundler "bin/setup.tt" => "bin/setup" } - executables = %w[ + executables = %w( bin/console bin/setup - ] + ) if test_framework = ask_and_set_test_framework config[:test] = test_framework diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 256ae0a7d2..df3472d70a 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -69,9 +69,7 @@ module Bundler "before deploying." end - if Bundler.app_cache.exist? - options[:local] = true - end + options[:local] = true if Bundler.app_cache.exist? Bundler.settings[:frozen] = "1" end diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 4c777df6e6..5381314552 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -62,7 +62,7 @@ module Bundler spec_version = "#{active_spec.version}#{active_spec.git_version}" current_version = "#{current_spec.version}#{current_spec.git_version}" - dependency_version = %|, requested #{dependency.requirement}| if dependency && dependency.specific? + dependency_version = %(, requested #{dependency.requirement}) if dependency && dependency.specific? if dependency groups = dependency.groups.join(", ") diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 1de65df695..7acd78ea0b 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -19,9 +19,7 @@ module Bundler unlock ||= {} gemfile = Pathname.new(gemfile).expand_path - unless gemfile.file? - raise GemfileNotFound, "#{gemfile} not found" - end + raise GemfileNotFound, "#{gemfile} not found" unless gemfile.file? Dsl.evaluate(gemfile, lockfile, unlock) end @@ -355,9 +353,7 @@ module Bundler new_deps = @dependencies - @locked_deps deleted_deps = @locked_deps - @dependencies - if new_deps.any? - added.concat new_deps.map {|d| "* #{pretty_dep(d)}" } - end + added.concat new_deps.map {|d| "* #{pretty_dep(d)}" } if new_deps.any? if deleted_deps.any? deleted.concat deleted_deps.map {|d| "* #{pretty_dep(d)}" } @@ -368,11 +364,10 @@ module Bundler @locked_deps.each {|d| both_sources[d.name][1] = d.source } both_sources.each do |name, (dep, lock_source)| - if (dep.nil? && !lock_source.nil?) || (!dep.nil? && !lock_source.nil? && !lock_source.can_lock?(dep)) - gemfile_source_name = (dep && dep.source) || "no specified source" - lockfile_source_name = lock_source || "no specified source" - changed << "* #{name} from `#{gemfile_source_name}` to `#{lockfile_source_name}`" - end + next unless (dep.nil? && !lock_source.nil?) || (!dep.nil? && !lock_source.nil? && !lock_source.can_lock?(dep)) + gemfile_source_name = (dep && dep.source) || "no specified source" + lockfile_source_name = lock_source || "no specified source" + changed << "* #{name} from `#{gemfile_source_name}` to `#{lockfile_source_name}`" end msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any? @@ -390,18 +385,18 @@ module Bundler problem, expected, actual = diff msg = case problem - when :engine - "Your Ruby engine is #{actual}, but your Gemfile specified #{expected}" - when :version - "Your Ruby version is #{actual}, but your Gemfile specified #{expected}" - when :engine_version - "Your #{Bundler.ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}" - when :patchlevel - if !expected.is_a?(String) - "The Ruby patchlevel in your Gemfile must be a string" - else - "Your Ruby patchlevel is #{actual}, but your Gemfile specified #{expected}" - end + when :engine + "Your Ruby engine is #{actual}, but your Gemfile specified #{expected}" + when :version + "Your Ruby version is #{actual}, but your Gemfile specified #{expected}" + when :engine_version + "Your #{Bundler.ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}" + when :patchlevel + if !expected.is_a?(String) + "The Ruby patchlevel in your Gemfile must be a string" + else + "Your Ruby patchlevel is #{actual}, but your Gemfile specified #{expected}" + end end raise RubyVersionMismatch, msg @@ -513,9 +508,7 @@ module Bundler def converge_dependencies (@dependencies + @locked_deps).each do |dep| - if dep.source - dep.source = sources.get(dep.source) - end + dep.source = sources.get(dep.source) if dep.source end Set.new(@dependencies) != Set.new(@locked_deps) end @@ -661,7 +654,7 @@ module Bundler end def requested_groups - self.groups - Bundler.settings.without - @optional_groups + Bundler.settings.with + groups - Bundler.settings.without - @optional_groups + Bundler.settings.with end def lockfiles_equal?(current, proposed, preserve_bundled_with) diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index f3e640b676..a62808d23c 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -74,9 +74,7 @@ module Bundler @env = options["env"] @should_include = options.fetch("should_include", true) - if options.key?("require") - @autorequire = Array(options["require"] || []) - end + @autorequire = Array(options["require"] || []) if options.key?("require") end def gem_platforms(valid_platforms) @@ -108,9 +106,9 @@ module Bundler def current_platform? return true if @platforms.empty? - @platforms.any? { |p| + @platforms.any? do |p| Bundler.current_ruby.send("#{p}?") - } + end end def to_lock diff --git a/lib/bundler/deprecate.rb b/lib/bundler/deprecate.rb index d9f6b494e7..02eb4b0918 100644 --- a/lib/bundler/deprecate.rb +++ b/lib/bundler/deprecate.rb @@ -1,5 +1,4 @@ module Bundler - if defined? ::Deprecate Deprecate = ::Deprecate elsif defined? Gem::Deprecate @@ -13,5 +12,4 @@ module Bundler yield end end - end diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 041a55ebd1..4755fe0609 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -205,7 +205,8 @@ module Bundler alias_method :platform, :platforms def env(name) - @env, old = name, @env + old = @env + @env = name yield ensure @env = old @@ -256,10 +257,10 @@ module Bundler def normalize_options(name, version, opts) if name.is_a?(Symbol) - raise GemfileError, %{You need to specify gem names as Strings. Use 'gem "#{name}"' instead} + raise GemfileError, %(You need to specify gem names as Strings. Use 'gem "#{name}"' instead) end if name =~ /\s/ - raise GemfileError, %{'#{name}' is not a valid gem name because it contains whitespace} + raise GemfileError, %('#{name}' is not a valid gem name because it contains whitespace) end normalize_hash(opts) @@ -298,16 +299,15 @@ module Bundler opts["git"] = @git_sources[git_name].call(opts[git_name]) end - %w[git path].each do |type| - if param = opts[type] - if version.first && version.first =~ /^\s*=?\s*(\d[^\s]*)\s*$/ - options = opts.merge("name" => name, "version" => $1) - else - options = opts.dup - end - source = send(type, param, options) {} - opts["source"] = source + %w(git path).each do |type| + next unless param = opts[type] + if version.first && version.first =~ /^\s*=?\s*(\d[^\s]*)\s*$/ + options = opts.merge("name" => name, "version" => $1) + else + options = opts.dup end + source = send(type, param, options) {} + opts["source"] = source end opts["source"] ||= @source @@ -474,5 +474,4 @@ module Bundler end end end - end diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 4ebbe7acf8..4b79a7d883 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -4,7 +4,6 @@ require "securerandom" require "zlib" module Bundler - # Handles all the fetching with the rubygems server class Fetcher autoload :Downloader, "bundler/fetcher/downloader" @@ -106,9 +105,7 @@ module Bundler specs = {} fetchers.dup.each do |f| - unless f.api_fetcher? && !gem_names - break if specs = f.specs(gem_names) - end + break unless f.api_fetcher? && !gem_names || !specs = f.specs(gem_names) fetchers.delete(f) end @use_api = false if fetchers.none?(&:api_fetcher?) @@ -157,7 +154,11 @@ module Bundler if ruby.engine != "ruby" # engine_version raises on unknown engines - engine_version = ruby.engine_version rescue "???" + engine_version = begin + ruby.engine_version + rescue + "???" + end agent << " #{ruby.engine}/#{engine_version}" end @@ -183,8 +184,6 @@ module Bundler def http_proxy if uri = connection.proxy_uri uri.to_s - else - nil end end diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index f6f8fd5623..eb15f48071 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -92,5 +92,4 @@ module Bundler "https://github.com/bundler/bundler/search?q=" \ "#{CGI.escape(exception.message.lines.first.chomp)}&type=Issues" end - end diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 70dded01ba..d468194538 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -72,12 +72,12 @@ module Bundler def build_gem file_name = nil - sh("gem build -V '#{spec_path}'") { + sh("gem build -V '#{spec_path}'") do file_name = File.basename(built_gem_path) SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) } FileUtils.mv(built_gem_path, "pkg") Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}." - } + end File.join(base, "pkg", file_name) end @@ -129,7 +129,7 @@ module Bundler end def guard_clean - clean? && committed? or raise("There are files that need to be committed first.") + clean? && committed? || raise("There are files that need to be committed first.") end def clean? @@ -175,17 +175,15 @@ module Bundler cmd << " 2>&1" outbuf = "" Bundler.ui.debug(cmd) - SharedHelpers.chdir(base) { + SharedHelpers.chdir(base) do outbuf = `#{cmd}` - if $? == 0 - block.call(outbuf) if block - end - } + block.call(outbuf) if $? == 0 && block + end [outbuf, $?] end def gem_push? - ! %w{n no nil false off 0}.include?(ENV["gem_push"].to_s.downcase) + ! %w(n no nil false off 0).include?(ENV["gem_push"].to_s.downcase) end end end diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb index fc1a341574..ac83e6fb92 100644 --- a/lib/bundler/gem_helpers.rb +++ b/lib/bundler/gem_helpers.rb @@ -1,6 +1,5 @@ module Bundler module GemHelpers - GENERIC_CACHE = {} GENERICS = [ [Gem::Platform.new("java"), Gem::Platform.new("java")], diff --git a/lib/bundler/graph.rb b/lib/bundler/graph.rb index cf5913ec70..414ec712fa 100644 --- a/lib/bundler/graph.rb +++ b/lib/bundler/graph.rb @@ -96,15 +96,15 @@ module Bundler # redefinition of matching_specs will also redefine to_spec and to_specs Gem::Dependency.class_eval do def matching_specs(platform_only = false) - matches = Bundler.load.specs.select { |spec| - self.name == spec.name and - requirement.satisfied_by? spec.version - } + matches = Bundler.load.specs.select do |spec| + name == spec.name && + requirement.satisfied_by?(spec.version) + end if platform_only - matches.select! { |spec| + matches.select! do |spec| Gem::Platform.match spec.platform - } + end end matches = matches.sort_by(&:sort_obj) # HACK: shouldn't be needed diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 04096c3f11..ef98fad888 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -47,7 +47,7 @@ module Bundler def new_gem_lines @new_deps.map do |d| - %|gem '#{d.name}', '#{d.requirement}'| + %(gem '#{d.name}', '#{d.requirement}') end.join("\n") end diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index 6776dd6200..35ad98891e 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -15,7 +15,7 @@ module Bundler file.puts "ruby_version = RbConfig::CONFIG[\"ruby_version\"]" file.puts "path = File.expand_path('..', __FILE__)" paths.each do |path| - file.puts %{$:.unshift "\#{path}/#{path}"} + file.puts %($:.unshift "\#{path}/#{path}") end end end diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index f0efbc448f..8d4a114ede 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -19,7 +19,7 @@ module Bundler end def full_name - if platform == Gem::Platform::RUBY or platform.nil? + if platform == Gem::Platform::RUBY || platform.nil? "#{@name}-#{@version}" else "#{@name}-#{@version}-#{platform}" @@ -35,7 +35,7 @@ module Bundler end def to_lock - if platform == Gem::Platform::RUBY or platform.nil? + if platform == Gem::Platform::RUBY || platform.nil? out = " #{name} (#{version})\n" else out = " #{name} (#{version}-#{platform})\n" diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 5fa1f5aae0..497fbcb133 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -184,9 +184,7 @@ module Bundler end def parse_platform(line) - if line =~ /^ (.*)$/ - @platforms << Gem::Platform.new($1) - end + @platforms << Gem::Platform.new($1) if line =~ /^ (.*)$/ end def parse_bundled_with(line) diff --git a/lib/bundler/match_platform.rb b/lib/bundler/match_platform.rb index 1dda3cadc1..f4b9492c25 100644 --- a/lib/bundler/match_platform.rb +++ b/lib/bundler/match_platform.rb @@ -5,9 +5,9 @@ module Bundler include GemHelpers def match_platform(p) - Gem::Platform::RUBY == platform or - platform.nil? or p == platform or - generic(Gem::Platform.new(platform)) === p + Gem::Platform::RUBY == platform || + platform.nil? || p == platform || + generic(Gem::Platform.new(platform)) === p end end end diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb index 3050c37371..c8247c4c95 100644 --- a/lib/bundler/remote_specification.rb +++ b/lib/bundler/remote_specification.rb @@ -27,7 +27,7 @@ module Bundler end def full_name - if platform == Gem::Platform::RUBY or platform.nil? + if platform == Gem::Platform::RUBY || platform.nil? "#{@name}-#{@version}" else "#{@name}-#{@version}-#{platform}" diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 527962d134..edced0077f 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -94,14 +94,13 @@ module Bundler specs = {} @activated.each do |p| - if s = @specs[p] - platform = generic(Gem::Platform.new(s.platform)) - next if specs[platform] + next unless s = @specs[p] + platform = generic(Gem::Platform.new(s.platform)) + next if specs[platform] - lazy_spec = LazySpecification.new(name, version, platform, source) - lazy_spec.dependencies.replace s.dependencies - specs[platform] = lazy_spec - end + lazy_spec = LazySpecification.new(name, version, platform, source) + lazy_spec.dependencies.replace s.dependencies + specs[platform] = lazy_spec end specs.values end @@ -156,12 +155,11 @@ module Bundler @dependencies ||= begin dependencies = {} ALL.each do |p| - if spec = @specs[p] - dependencies[p] = [] - spec.dependencies.each do |dep| - next if dep.type == :development - dependencies[p] << DepProxy.new(dep, p) - end + next unless spec = @specs[p] + dependencies[p] = [] + spec.dependencies.each do |dep| + next if dep.type == :development + dependencies[p] << DepProxy.new(dep, p) end end dependencies @@ -282,11 +280,15 @@ module Bundler end def name_for_explicit_dependency_source - Bundler.default_gemfile.basename.to_s rescue "Gemfile" + Bundler.default_gemfile.basename.to_s + rescue + "Gemfile" end def name_for_locking_dependency_source - Bundler.default_lockfile.basename.to_s rescue "Gemfile.lock" + Bundler.default_lockfile.basename.to_s + rescue + "Gemfile.lock" end def requirement_satisfied_by?(requirement, activated, spec) @@ -308,7 +310,7 @@ module Bundler def amount_constrained(dependency) @amount_constrained ||= {} @amount_constrained[dependency.name] ||= begin - if base = @base[dependency.name] and !base.empty? + if (base = @base[dependency.name]) && !base.empty? dependency.requirement.satisfied_by?(base.first.version) ? 0 : 1 else base_dep = Dependency.new dependency.name, ">= 0.a" @@ -327,30 +329,29 @@ module Bundler def verify_gemfile_dependencies_are_found!(requirements) requirements.each do |requirement| next if requirement.name == "bundler" - if search_for(requirement).empty? - if base = @base[requirement.name] and !base.empty? - version = base.first.version - message = "You have requested:\n" \ - " #{requirement.name} #{requirement.requirement}\n\n" \ - "The bundle currently has #{requirement.name} locked at #{version}.\n" \ - "Try running `bundle update #{requirement.name}`\n\n" \ - "If you are updating multiple gems in your Gemfile at once,\n" \ - "try passing them all to `bundle update`" - elsif requirement.source - name = requirement.name - versions = @source_requirements[name][name].map(&:version) - message = "Could not find gem '#{requirement}' in #{requirement.source}.\n" - if versions.any? - message << "Source contains '#{name}' at: #{versions.join(", ")}" - else - message << "Source does not contain any versions of '#{requirement}'" - end + next unless search_for(requirement).empty? + if (base = @base[requirement.name]) && !base.empty? + version = base.first.version + message = "You have requested:\n" \ + " #{requirement.name} #{requirement.requirement}\n\n" \ + "The bundle currently has #{requirement.name} locked at #{version}.\n" \ + "Try running `bundle update #{requirement.name}`\n\n" \ + "If you are updating multiple gems in your Gemfile at once,\n" \ + "try passing them all to `bundle update`" + elsif requirement.source + name = requirement.name + versions = @source_requirements[name][name].map(&:version) + message = "Could not find gem '#{requirement}' in #{requirement.source}.\n" + if versions.any? + message << "Source contains '#{name}' at: #{versions.join(", ")}" else - message = "Could not find gem '#{requirement}' in any of the gem sources " \ - "listed in your Gemfile or available on this machine." + message << "Source does not contain any versions of '#{requirement}'" end - raise GemNotFound, message + else + message = "Could not find gem '#{requirement}' in any of the gem sources " \ + "listed in your Gemfile or available on this machine." end + raise GemNotFound, message end end end diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index 138262e3db..34268c79f2 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -53,8 +53,6 @@ module Bundler [:engine_version, engine_version, other.engine_version] elsif patchlevel != other.patchlevel && @patchlevel [:patchlevel, patchlevel, other.patchlevel] - else - nil end end diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 9e4ce5ac17..33f6308014 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -99,9 +99,9 @@ module Gem gemfile << "group :#{group} do\n" if group dependencies.each do |dependency| gemfile << " " if group - gemfile << %|gem "#{dependency.name}"| + gemfile << %(gem "#{dependency.name}") req = dependency.requirements_list.first - gemfile << %|, "#{req}"| if req + gemfile << %(, "#{req}") if req gemfile << "\n" end gemfile << "end\n" if group diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 3f375dff8c..96b9101610 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -135,7 +135,7 @@ module Bundler end def repository_subdirectories - %w[cache doc gems specifications] + %w(cache doc gems specifications) end def clear_paths @@ -203,7 +203,7 @@ module Bundler def with_build_args(args) ext_lock.synchronize do - old_args = self.build_args + old_args = build_args begin self.build_args = args yield @@ -251,7 +251,7 @@ module Bundler end def security_policy_keys - %w{High Medium Low AlmostNo No}.map {|level| "#{level}Security" } + %w(High Medium Low AlmostNo No).map {|level| "#{level}Security" } end def security_policies @@ -282,7 +282,7 @@ module Bundler ::Kernel.send(:define_method, :gem) do |dep, *reqs| if executables.include? File.basename(caller.first.split(":").first) - return + break end reqs.pop if reqs.last.is_a?(Hash) @@ -346,15 +346,13 @@ module Bundler redefine_method(gem_class, :bin_path) do |name, *args| exec_name = args.first - if exec_name == "bundle" - return ENV["BUNDLE_BIN_PATH"] - end + return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle" spec = nil if exec_name spec = specs.find {|s| s.executables.include?(exec_name) } - spec or raise Gem::Exception, "can't find executable #{exec_name}" + raise(Gem::Exception, "can't find executable #{exec_name}") unless spec unless spec.name == name warn "Bundler is using a binstub that was created for a different gem.\n" \ "This is deprecated, in future versions you may need to `bundle binstub #{name}` " \ @@ -362,7 +360,7 @@ module Bundler end else spec = specs.find {|s| s.name == name } - exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}" + raise Gem::Exception, "no default executable for #{spec.full_name}" unless exec_name = spec.default_executable end gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name) @@ -511,9 +509,9 @@ module Bundler def stub_rubygems(specs) Gem::Specification.all = specs - Gem.post_reset { + Gem.post_reset do Gem::Specification.all = specs - } + end stub_source_index(specs) end @@ -647,9 +645,7 @@ module Bundler const_set(:CHDIR_MONITOR, EXT_LOCK) end - if const_defined?(:CHDIR_MUTEX) - remove_const(:CHDIR_MUTEX) - end + remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX) const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR)) end end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 179ce53ec4..63e345b04b 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -21,7 +21,7 @@ module Bundler raise GemNotFound, "#{spec.full_name} is missing. Run `bundle` to get it." end - if activated_spec = Bundler.rubygems.loaded_specs(spec.name) and activated_spec.version != spec.version + if (activated_spec = Bundler.rubygems.loaded_specs(spec.name)) && activated_spec.version != spec.version e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \ "but your Gemfile requires #{spec.name} #{spec.version}. Prepending " \ "`bundle exec` to your command may solve this." diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index c859a7677b..1ca41e2e71 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -29,7 +29,7 @@ module Bundler end def []=(key, value) - local_config_file or raise GemfileNotFound, "Could not locate Gemfile" + local_config_file || raise(GemfileNotFound, "Could not locate Gemfile") set_key(key, value, @local_config, local_config_file) end @@ -56,9 +56,7 @@ module Bundler def local_overrides repos = {} all.each do |k| - if k =~ /^local\./ - repos[$'] = self[k] - end + repos[$'] = self[k] if k =~ /^local\./ end repos end @@ -163,9 +161,7 @@ module Bundler private def key_for(key) - if key.is_a?(String) && /https?:/ =~ key - key = normalize_uri(key).to_s - end + key = normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key key = key.to_s.gsub(".", "__").upcase "BUNDLE_#{key}" end @@ -243,7 +239,7 @@ module Bundler end def convert_to_backward_compatible_key(key) - key = "#{key}/" if key =~ /https?:/i && key !~ %r[/\Z] + key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z} key = key.gsub(".", "__") if key.include?(".") key end @@ -252,7 +248,7 @@ module Bundler # TODO: is this the correct place to validate mirror URIs? def normalize_uri(uri) uri = uri.to_s - uri = "#{uri}/" unless uri =~ %r[/\Z] + uri = "#{uri}/" unless uri =~ %r{/\Z} uri = URI(uri) unless uri.absolute? raise ArgumentError, "Gem sources must be absolute. You provided '#{uri}'." diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 19e75186dd..2e512bfc74 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -61,7 +61,7 @@ module Bundler end def with_clean_git_env(&block) - keys = %w[GIT_DIR GIT_WORK_TREE] + keys = %w(GIT_DIR GIT_WORK_TREE) old_env = keys.inject({}) do |h, k| h.update(k => ENV[k]) end @@ -82,7 +82,7 @@ module Bundler # Set RUBYOPT rubyopt = [ENV["RUBYOPT"]].compact if rubyopt.empty? || rubyopt.first !~ %r{-rbundler/setup} - rubyopt.unshift %|-rbundler/setup| + rubyopt.unshift %(-rbundler/setup) ENV["RUBYOPT"] = rubyopt.join(" ") end @@ -126,9 +126,9 @@ module Bundler end def find_file(*names) - search_up(*names) {|filename| + search_up(*names) do |filename| return filename if File.file?(filename) - } + end end def find_directory(*names) @@ -151,7 +151,8 @@ module Bundler filename = File.join(current, name) yield filename end - current, previous = File.expand_path("..", current), current + previous = current + current = File.expand_path("..", current) end end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 3a75299ff8..b11de1e4bc 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -147,9 +147,7 @@ module Bundler # TODO: actually cache git specs def specs(*) - if has_app_cache? && !local? - set_local!(app_cache_path) - end + set_local!(app_cache_path) if has_app_cache? && !local? if requires_checkout? && !@copied git_proxy.checkout diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index 40e3d205ae..b8900888a9 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -72,14 +72,14 @@ module Bundler return if has_revision_cached? Bundler.ui.info "Fetching #{uri}" in_path do - git_retry %|fetch --force --quiet --tags #{uri_escaped_with_configured_credentials} "refs/heads/*:refs/heads/*"| + git_retry %(fetch --force --quiet --tags #{uri_escaped_with_configured_credentials} "refs/heads/*:refs/heads/*") end else Bundler.ui.info "Fetching #{uri}" SharedHelpers.filesystem_access(path.dirname) do |p| FileUtils.mkdir_p(p) end - git_retry %|clone #{uri_escaped_with_configured_credentials} "#{path}" --bare --no-hardlinks --quiet| + git_retry %(clone #{uri_escaped_with_configured_credentials} "#{path}" --bare --no-hardlinks --quiet) end end @@ -93,7 +93,7 @@ module Bundler SharedHelpers.filesystem_access(destination) do |p| FileUtils.rm_rf(p) end - git_retry %|clone --no-checkout --quiet "#{path}" "#{destination}"| + git_retry %(clone --no-checkout --quiet "#{path}" "#{destination}") File.chmod(((File.stat(destination).mode | 0777) & ~File.umask), destination) rescue Errno::EEXIST => e file_path = e.message[%r{.*?(/.*)}, 1] @@ -104,12 +104,10 @@ module Bundler end # method 2 SharedHelpers.chdir(destination) do - git_retry %|fetch --force --quiet --tags "#{path}"| + git_retry %(fetch --force --quiet --tags "#{path}") git "reset --hard #{@revision}" - if submodules - git_retry "submodule update --init --recursive" - end + git_retry "submodule update --init --recursive" if submodules end end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 292412044c..4192015cb7 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -132,11 +132,10 @@ module Bundler if File.directory?(expanded_path) # We sort depth-first since `<<` will override the earlier-found specs Dir["#{expanded_path}/#{@glob}"].sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| - if spec = Bundler.load_gemspec(file, :validate) - spec.loaded_from = file.to_s - spec.source = self - index << spec - end + next unless spec = Bundler.load_gemspec(file, :validate) + spec.loaded_from = file.to_s + spec.source = self + index << spec end if index.empty? && @name && @version @@ -212,11 +211,10 @@ module Bundler return unless Gem.respond_to?(hooks_meth) Gem.send(hooks_meth).each do |hook| result = hook.call(installer) - if result == false - location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/ - message = "#{type} hook#{location} failed for #{installer.spec.full_name}" - raise InstallHookError, message - end + next unless result == false + location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/ + message = "#{type} hook#{location} failed for #{installer.spec.full_name}" + raise InstallHookError, message end end end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index b42cdc3eef..1f45888421 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -68,7 +68,7 @@ module Bundler end def to_s - remote_names = self.remotes.map(&:to_s).join(", ") + remote_names = remotes.map(&:to_s).join(", ") "rubygems repository #{remote_names}" end alias_method :name, :to_s @@ -264,7 +264,7 @@ module Bundler def normalize_uri(uri) uri = uri.to_s - uri = "#{uri}/" unless uri =~ %r'/$' + uri = "#{uri}/" unless uri =~ %r{/$} uri = URI(uri) raise ArgumentError, "The source must be an absolute URI. For example:\n" \ "source 'https://rubygems.org'" if !uri.absolute? || (uri.is_a?(URI::HTTP) && uri.host.nil?) diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb index 65460f2fdb..2c0076dc06 100644 --- a/lib/bundler/ui/shell.rb +++ b/lib/bundler/ui/shell.rb @@ -75,7 +75,8 @@ module Bundler end def silence - old_level, @level = @level, "silent" + old_level = @level + @level = "silent" yield ensure @level = old_level |