diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-02-02 16:57:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 16:57:34 +0900 |
commit | 6794f8cf928ab8c009b301ec49a5a81e97e6eb2f (patch) | |
tree | 63f83daf2d1d2f57d6aaee9efa01e1c91ee8b021 /lib/rubygems | |
parent | 69463805f0722d90a2049f43e852539b4532bf2e (diff) |
Merge pull request #5482 from hsbt/rubygems-3-3-bundler-2-3
Merge RubyGems 3.3.x and Bundler 2.3.x
Diffstat (limited to 'lib/rubygems')
39 files changed, 434 insertions, 387 deletions
diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 665b87fc0e..b3b63b51aa 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -289,14 +289,14 @@ class Gem::BasicSpecification def lib_dirs_glob dirs = if self.raw_require_paths - if self.raw_require_paths.size > 1 - "{#{self.raw_require_paths.join(',')}}" - else - self.raw_require_paths.first - end - else - "lib" # default value for require_paths for bundler/inline - end + if self.raw_require_paths.size > 1 + "{#{self.raw_require_paths.join(',')}}" + else + self.raw_require_paths.first + end + else + "lib" # default value for require_paths for bundler/inline + end "#{self.full_gem_path}/#{dirs}".dup.tap(&Gem::UNTAINT) end diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index 14179aebf3..f6fad0bd83 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -65,9 +65,9 @@ module Gem::BundlerVersionFinder return unless gemfile lockfile = case gemfile - when "gems.rb" then "gems.locked" - else "#{gemfile}.lock" - end.dup.tap(&Gem::UNTAINT) + when "gems.rb" then "gems.locked" + else "#{gemfile}.lock" + end.dup.tap(&Gem::UNTAINT) return unless File.file?(lockfile) diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index abdaa8e7c6..f74cb419f9 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -398,10 +398,10 @@ class Gem::Command version_to_expire = deprecation["rg_version_to_expire"] deprecate_option_msg = if version_to_expire - "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}." - else - "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems." - end + "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}." + else + "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems." + end extra_msg = deprecation["extra_msg"] diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb index c965085880..dc181e4de0 100644 --- a/lib/rubygems/commands/cleanup_command.rb +++ b/lib/rubygems/commands/cleanup_command.rb @@ -117,12 +117,12 @@ If no gems are named all gems in GEM_HOME are cleaned. def get_candidate_gems @candidate_gems = unless options[:args].empty? - options[:args].map do |gem_name| - Gem::Specification.find_all_by_name gem_name - end.flatten - else - Gem::Specification.to_a - end + options[:args].map do |gem_name| + Gem::Specification.find_all_by_name gem_name + end.flatten + else + Gem::Specification.to_a + end end def get_gems_to_cleanup diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb index 7d217076a5..d2fed022fe 100644 --- a/lib/rubygems/commands/dependency_command.rb +++ b/lib/rubygems/commands/dependency_command.rb @@ -53,41 +53,41 @@ use with other commands. "#{program_name} REGEXP" end - def fetch_remote_specs(dependency) # :nodoc: + def fetch_remote_specs(name, requirement, prerelease) # :nodoc: fetcher = Gem::SpecFetcher.fetcher - ss, = fetcher.spec_for_dependency dependency + specs_type = prerelease ? :complete : :released - ss.map {|spec, _| spec } + ss = if name.nil? + fetcher.detect(specs_type) { true } + else + fetcher.detect(specs_type) do |name_tuple| + name === name_tuple.name && requirement.satisfied_by?(name_tuple.version) + end + end + + ss.map {|tuple, source| source.fetch_spec(tuple) } end - def fetch_specs(name_pattern, dependency) # :nodoc: + def fetch_specs(name_pattern, requirement, prerelease) # :nodoc: specs = [] if local? specs.concat Gem::Specification.stubs.find_all {|spec| - name_pattern =~ spec.name and - dependency.requirement.satisfied_by? spec.version + name_matches = name_pattern ? name_pattern =~ spec.name : true + version_matches = requirement.satisfied_by?(spec.version) + + name_matches and version_matches }.map(&:to_spec) end - specs.concat fetch_remote_specs dependency if remote? + specs.concat fetch_remote_specs name_pattern, requirement, prerelease if remote? ensure_specs specs specs.uniq.sort end - def gem_dependency(pattern, version, prerelease) # :nodoc: - dependency = Gem::Deprecate.skip_during do - Gem::Dependency.new pattern, version - end - - dependency.prerelease = prerelease - - dependency - end - def display_pipe(specs) # :nodoc: specs.each do |spec| unless spec.dependencies.empty? @@ -119,11 +119,9 @@ use with other commands. ensure_local_only_reverse_dependencies pattern = name_pattern options[:args] + requirement = Gem::Requirement.new options[:version] - dependency = - gem_dependency pattern, options[:version], options[:prerelease] - - specs = fetch_specs pattern, dependency + specs = fetch_specs pattern, requirement, options[:prerelease] reverse = reverse_dependencies specs @@ -162,14 +160,6 @@ use with other commands. response end - def remote_specs(dependency) # :nodoc: - fetcher = Gem::SpecFetcher.fetcher - - ss, _ = fetcher.spec_for_dependency dependency - - ss.map {|s,o| s } - end - def reverse_dependencies(specs) # :nodoc: reverse = Hash.new {|h, k| h[k] = [] } @@ -205,7 +195,7 @@ use with other commands. private def name_pattern(args) - args << '' if args.empty? + return if args.empty? if args.length == 1 and args.first =~ /\A(.*)(i)?\z/m flags = $2 ? Regexp::IGNORECASE : nil diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb index 373851643d..c8ecb0d48c 100644 --- a/lib/rubygems/commands/fetch_command.rb +++ b/lib/rubygems/commands/fetch_command.rb @@ -8,7 +8,12 @@ class Gem::Commands::FetchCommand < Gem::Command include Gem::VersionOption def initialize - super 'fetch', 'Download a gem and place it in the current directory' + defaults = { + :suggest_alternate => true, + :version => Gem::Requirement.default, + } + + super 'fetch', 'Download a gem and place it in the current directory', defaults add_bulk_threshold_option add_proxy_option @@ -18,6 +23,10 @@ class Gem::Commands::FetchCommand < Gem::Command add_version_option add_platform_option add_prerelease_option + + add_option '--[no-]suggestions', 'Suggest alternates when gems are not found' do |value, options| + options[:suggest_alternate] = value + end end def arguments # :nodoc: @@ -42,15 +51,27 @@ then repackaging it. "#{program_name} GEMNAME [GEMNAME ...]" end + def check_version # :nodoc: + if options[:version] != Gem::Requirement.default and + get_all_gem_names.size > 1 + alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirements using `gem fetch 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + terminate_interaction 1 + end + end + def execute - version = options[:version] || Gem::Requirement.default + check_version + version = options[:version] platform = Gem.platforms.last - gem_names = get_all_gem_names + gem_names = get_all_gem_names_and_versions - gem_names.each do |gem_name| - dep = Gem::Dependency.new gem_name, version + gem_names.each do |gem_name, gem_version| + gem_version ||= version + dep = Gem::Dependency.new gem_name, gem_version dep.prerelease = options[:prerelease] + suppress_suggestions = !options[:suggest_alternate] specs_and_sources, errors = Gem::SpecFetcher.fetcher.spec_for_dependency dep @@ -63,12 +84,10 @@ then repackaging it. spec, source = specs_and_sources.max_by {|s,| s } if spec.nil? - show_lookup_failure gem_name, version, errors, options[:domain] + show_lookup_failure gem_name, gem_version, errors, suppress_suggestions, options[:domain] next end - source.download spec - say "Downloaded #{spec.full_name}" end end diff --git a/lib/rubygems/commands/list_command.rb b/lib/rubygems/commands/list_command.rb index dea11111c9..010d968f9c 100644 --- a/lib/rubygems/commands/list_command.rb +++ b/lib/rubygems/commands/list_command.rb @@ -10,7 +10,7 @@ class Gem::Commands::ListCommand < Gem::Command def initialize super 'list', 'Display local gems whose name matches REGEXP', - :name => //, :domain => :local, :details => false, :versions => true, + :domain => :local, :details => false, :versions => true, :installed => nil, :version => Gem::Requirement.default add_query_options diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index 13979b0a59..3cf496ba5b 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -98,20 +98,20 @@ extensions will be restored. def execute specs = if options[:all] - Gem::Specification.map + Gem::Specification.map - # `--extensions` must be explicitly given to pristine only gems - # with extensions. - elsif options[:extensions_set] and + # `--extensions` must be explicitly given to pristine only gems + # with extensions. + elsif options[:extensions_set] and options[:extensions] and options[:args].empty? - Gem::Specification.select do |spec| - spec.extensions and not spec.extensions.empty? - end - else - get_all_gem_names.sort.map do |gem_name| - Gem::Specification.find_all_by_name(gem_name, options[:version]).reverse - end.flatten - end + Gem::Specification.select do |spec| + spec.extensions and not spec.extensions.empty? + end + else + get_all_gem_names.sort.map do |gem_name| + Gem::Specification.find_all_by_name(gem_name, options[:version]).reverse + end.flatten + end specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform || spec.platform == Gem::Platform::RUBY } diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 1864b4b095..4d0d5a9f4b 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -52,14 +52,14 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo default_gem_server, push_host = get_hosts_for(gem_name) @host = if @user_defined_host - options[:host] - elsif default_gem_server - default_gem_server - elsif push_host - push_host - else - options[:host] - end + options[:host] + elsif default_gem_server + default_gem_server + elsif push_host + push_host + else + options[:host] + end sign_in @host, scope: get_push_scope diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index 5896bec44e..442c4b19bb 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -20,7 +20,7 @@ class Gem::Commands::QueryCommand < Gem::Command def initialize(name = 'query', summary = 'Query gem information in local or remote repositories') super name, summary, - :name => //, :domain => :local, :details => false, :versions => true, + :domain => :local, :details => false, :versions => true, :installed => nil, :version => Gem::Requirement.default add_option('-n', '--name-matches REGEXP', diff --git a/lib/rubygems/commands/rdoc_command.rb b/lib/rubygems/commands/rdoc_command.rb index 305c80ccfe..7c5d6212f5 100644 --- a/lib/rubygems/commands/rdoc_command.rb +++ b/lib/rubygems/commands/rdoc_command.rb @@ -61,12 +61,12 @@ Use --overwrite to force rebuilding of documentation. def execute specs = if options[:all] - Gem::Specification.to_a - else - get_all_gem_names.map do |name| - Gem::Specification.find_by_name name, options[:version] - end.flatten.uniq - end + Gem::Specification.to_a + else + get_all_gem_names.map do |name| + Gem::Specification.find_by_name name, options[:version] + end.flatten.uniq + end if specs.empty? alert_error 'No matching gems found' diff --git a/lib/rubygems/commands/search_command.rb b/lib/rubygems/commands/search_command.rb index 488d777939..75d99986f9 100644 --- a/lib/rubygems/commands/search_command.rb +++ b/lib/rubygems/commands/search_command.rb @@ -7,7 +7,7 @@ class Gem::Commands::SearchCommand < Gem::Command def initialize super 'search', 'Display remote gems whose name matches REGEXP', - :name => //, :domain => :remote, :details => false, :versions => true, + :domain => :remote, :details => false, :versions => true, :installed => nil, :version => Gem::Requirement.default add_query_options diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 0601dccb07..01714f0342 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -54,10 +54,10 @@ class Gem::Commands::SetupCommand < Gem::Command 'List the documentation types you wish to', 'generate. For example: rdoc,ri' do |value, options| options[:document] = case value - when nil then %w[rdoc ri] - when false then [] - else value - end + when nil then %w[rdoc ri] + when false then [] + else value + end end add_option '--[no-]rdoc', @@ -666,10 +666,10 @@ abort "#{deprecation_message}" def target_bin_path(bin_dir, bin_file) bin_file_formatted = if options[:format_executable] - Gem.default_exec_format % bin_file - else - bin_file - end + Gem.default_exec_format % bin_file + else + bin_file + end File.join bin_dir, bin_file_formatted end diff --git a/lib/rubygems/commands/specification_command.rb b/lib/rubygems/commands/specification_command.rb index 473b6e7b19..6f24787962 100644 --- a/lib/rubygems/commands/specification_command.rb +++ b/lib/rubygems/commands/specification_command.rb @@ -140,10 +140,10 @@ Specific fields in the specification can be extracted in YAML format: s = s.send field if field say case options[:format] - when :ruby then s.to_ruby - when :marshal then Marshal.dump s - else s.to_yaml - end + when :ruby then s.to_ruby + when :marshal then Marshal.dump s + else s.to_yaml + end say "\n" end diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 513351d303..42d6f6046b 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -233,10 +233,10 @@ command to remove old versions. up_ver = gems_to_update.first.version target = if update_latest - up_ver - else - version - end + up_ver + else + version + end return target, requirement end @@ -286,10 +286,11 @@ command to remove old versions. check_oldest_rubygems version - update_gem 'rubygems-update', version - installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement - version = installed_gems.first.version + installed_gems = update_gem('rubygems-update', version) if installed_gems.empty? || installed_gems.first.version != version + return if installed_gems.empty? + + version = installed_gems.first.version install_rubygems version end @@ -335,7 +336,9 @@ command to remove old versions. # def oldest_supported_version @oldest_supported_version ||= - if Gem.ruby_version > Gem::Version.new("3.0.a") + if Gem.ruby_version > Gem::Version.new("3.1.a") + Gem::Version.new("3.3.3") + elsif Gem.ruby_version > Gem::Version.new("3.0.a") Gem::Version.new("3.2.3") elsif Gem.ruby_version > Gem::Version.new("2.7.a") Gem::Version.new("3.1.2") diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 60c1d50ba9..5dd2bfe88d 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -281,10 +281,10 @@ if you believe they were disclosed to a third party. check_credentials_permissions @api_keys = if File.exist? credentials_path - load_file(credentials_path) - else - @hash - end + load_file(credentials_path) + else + @hash + end if @api_keys.key? :rubygems_api_key @rubygems_api_key = @api_keys[:rubygems_api_key] diff --git a/lib/rubygems/doctor.rb b/lib/rubygems/doctor.rb index 41bcda9804..d14c64a166 100644 --- a/lib/rubygems/doctor.rb +++ b/lib/rubygems/doctor.rb @@ -117,11 +117,11 @@ class Gem::Doctor type = File.directory?(child) ? 'directory' : 'file' action = if @dry_run - 'Extra' - else - FileUtils.rm_r(child) - 'Removed' - end + 'Extra' + else + FileUtils.rm_r(child) + 'Removed' + end say "#{action} #{type} #{sub_directory}/#{File.basename(child)}" end diff --git a/lib/rubygems/gem_runner.rb b/lib/rubygems/gem_runner.rb index 55b5a7d067..89b23b26aa 100644 --- a/lib/rubygems/gem_runner.rb +++ b/lib/rubygems/gem_runner.rb @@ -42,11 +42,11 @@ class Gem::GemRunner cmd.command_names.each do |command_name| config_args = Gem.configuration[command_name] config_args = case config_args - when String - config_args.split ' ' - else - Array(config_args) - end + when String + config_args.split ' ' + else + Array(config_args) + end Gem::Command.add_specific_extra_args command_name, config_args end diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb index 2203b17f8e..454104435d 100644 --- a/lib/rubygems/install_update_options.rb +++ b/lib/rubygems/install_update_options.rb @@ -35,10 +35,10 @@ module Gem::InstallUpdateOptions 'List the documentation types you wish to', 'generate. For example: rdoc,ri') do |value, options| options[:document] = case value - when nil then %w[ri] - when false then [] - else value - end + when nil then %w[ri] + when false then [] + else value + end end add_option(:"Install/Update", '--build-root DIR', diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index ab09c18280..4cda09f200 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -201,8 +201,8 @@ class Gem::Installer # # If +@force+ is set +filename+ is overwritten. # - # If +filename+ exists and is a RubyGems wrapper for different gem the user - # is consulted. + # If +filename+ exists and it is a RubyGems wrapper for a different gem, then + # the user is consulted. # # If +filename+ exists and +@bin_dir+ is Gem.default_bindir (/usr/local) the # user is consulted. @@ -220,7 +220,17 @@ class Gem::Installer existing = nil File.open generated_bin, 'rb' do |io| - next unless io.gets =~ /^#!/ # shebang + line = io.gets + shebang = /^#!.*ruby/ + + if load_relative_enabled? + until line.nil? || line =~ shebang do + line = io.gets + end + end + + next unless line =~ shebang + io.gets # blankline # TODO detect a specially formatted comment instead of trying @@ -585,7 +595,6 @@ class Gem::Installer # def shebang(bin_file_name) - ruby_name = RbConfig::CONFIG['ruby_install_name'] if @env_shebang path = File.join gem_dir, spec.bindir, bin_file_name first_line = File.open(path, "rb") {|file| file.gets } || "" @@ -598,7 +607,7 @@ class Gem::Installer if which = Gem.configuration[:custom_shebang] # replace bin_file_name with "ruby" to avoid endless loops - which = which.gsub(/ #{bin_file_name}$/," #{RbConfig::CONFIG['ruby_install_name']}") + which = which.gsub(/ #{bin_file_name}$/," #{ruby_install_name}") which = which.gsub(/\$(\w+)/) do case $1 @@ -614,14 +623,12 @@ class Gem::Installer end "#!#{which}" - elsif not ruby_name - "#!#{Gem.ruby}#{opts}" - elsif opts - "#!/bin/sh\n'exec' #{ruby_name.dump} '-x' \"$0\" \"$@\"\n#{shebang}" - else + elsif @env_shebang # Create a plain shebang line. @env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path } - "#!#{@env_path} #{ruby_name}" + "#!#{@env_path} #{ruby_install_name}" + else + "#{bash_prolog_script}#!#{Gem.ruby}#{opts}" end end @@ -805,7 +812,6 @@ TEXT # return the stub script text used to launch the true Ruby script def windows_stub_script(bindir, bin_file_name) - rb_config = RbConfig::CONFIG rb_topdir = RbConfig::TOPDIR || File.dirname(rb_config["bindir"]) # get ruby executable file name from RbConfig @@ -973,4 +979,37 @@ TEXT Gem::Command.build_args end end + + def rb_config + RbConfig::CONFIG + end + + def ruby_install_name + rb_config["ruby_install_name"] + end + + def load_relative_enabled? + rb_config["LIBRUBY_RELATIVE"] == 'yes' + end + + def bash_prolog_script + if load_relative_enabled? + script = +<<~EOS + bindir="${0%/*}" + EOS + + script << %Q(exec "$bindir/#{ruby_install_name}" "-x" "$0" "$@"\n) + + <<~EOS + #!/bin/sh + # -*- ruby -*- + _=_\\ + =begin + #{script.chomp} + =end + EOS + else + "" + end + end end diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 94705914af..a81c5f307c 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -146,12 +146,12 @@ class Gem::Package def self.new(gem, security_policy = nil) gem = if gem.is_a?(Gem::Package::Source) - gem - elsif gem.respond_to? :read - Gem::Package::IOSource.new gem - else - Gem::Package::FileSource.new gem - end + gem + elsif gem.respond_to? :read + Gem::Package::IOSource.new gem + else + Gem::Package::FileSource.new gem + end return super unless Gem::Package == self return super unless gem.present? @@ -230,7 +230,7 @@ class Gem::Package tar.add_file_signed 'checksums.yaml.gz', 0444, @signer do |io| gzip_to io do |gz_io| - YAML.dump checksums_by_algorithm, gz_io + Psych.dump checksums_by_algorithm, gz_io end end end @@ -353,10 +353,10 @@ EOM def digest(entry) # :nodoc: algorithms = if @checksums - @checksums.keys - else - [Gem::Security::DIGEST_NAME].compact - end + @checksums.keys + else + [Gem::Security::DIGEST_NAME].compact + end algorithms.each do |algorithm| digester = Gem::Security.create_digest(algorithm) diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb index 25317ef23f..301d403411 100644 --- a/lib/rubygems/package/old.rb +++ b/lib/rubygems/package/old.rb @@ -145,7 +145,7 @@ class Gem::Package::Old < Gem::Package begin @spec = Gem::Specification.from_yaml yaml - rescue YAML::SyntaxError + rescue Psych::SyntaxError raise Gem::Exception, "Failed to parse gem specification out of gem file" end rescue ArgumentError diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index a5e65f9243..f48f4bdc76 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -78,9 +78,9 @@ class Gem::Platform cpu = arch.shift @cpu = case cpu - when /i\d86/ then 'x86' - else cpu - end + when /i\d86/ then 'x86' + else cpu + end if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ # for command-line @os, @version = arch @@ -91,32 +91,32 @@ class Gem::Platform @cpu, os = nil, cpu if os.nil? # legacy jruby @os, @version = case os - when /aix(\d+)?/ then [ 'aix', $1 ] - when /cygwin/ then [ 'cygwin', nil ] - when /darwin(\d+)?/ then [ 'darwin', $1 ] - when /^macruby$/ then [ 'macruby', nil ] - when /freebsd(\d+)?/ then [ 'freebsd', $1 ] - when /hpux(\d+)?/ then [ 'hpux', $1 ] - when /^java$/, /^jruby$/ then [ 'java', nil ] - when /^java([\d.]*)/ then [ 'java', $1 ] - when /^dalvik(\d+)?$/ then [ 'dalvik', $1 ] - when /^dotnet$/ then [ 'dotnet', nil ] - when /^dotnet([\d.]*)/ then [ 'dotnet', $1 ] - when /linux-?((?!gnu)\w+)?/ then [ 'linux', $1 ] - when /mingw32/ then [ 'mingw32', nil ] - when /mingw-?(\w+)?/ then [ 'mingw', $1 ] - when /(mswin\d+)(\_(\d+))?/ then - os, version = $1, $3 - @cpu = 'x86' if @cpu.nil? and os =~ /32$/ - [os, version] - when /netbsdelf/ then [ 'netbsdelf', nil ] - when /openbsd(\d+\.\d+)?/ then [ 'openbsd', $1 ] - when /bitrig(\d+\.\d+)?/ then [ 'bitrig', $1 ] - when /solaris(\d+\.\d+)?/ then [ 'solaris', $1 ] - # test - when /^(\w+_platform)(\d+)?/ then [ $1, $2 ] - else [ 'unknown', nil ] - end + when /aix(\d+)?/ then [ 'aix', $1 ] + when /cygwin/ then [ 'cygwin', nil ] + when /darwin(\d+)?/ then [ 'darwin', $1 ] + when /^macruby$/ then [ 'macruby', nil ] + when /freebsd(\d+)?/ then [ 'freebsd', $1 ] + when /hpux(\d+)?/ then [ 'hpux', $1 ] + when /^java$/, /^jruby$/ then [ 'java', nil ] + when /^java([\d.]*)/ then [ 'java', $1 ] + when /^dalvik(\d+)?$/ then [ 'dalvik', $1 ] + when /^dotnet$/ then [ 'dotnet', nil ] + when /^dotnet([\d.]*)/ then [ 'dotnet', $1 ] + when /linux-?((?!gnu)\w+)?/ then [ 'linux', $1 ] + when /mingw32/ then [ 'mingw32', nil ] + when /mingw-?(\w+)?/ then [ 'mingw', $1 ] + when /(mswin\d+)(\_(\d+))?/ then + os, version = $1, $3 + @cpu = 'x86' if @cpu.nil? and os =~ /32$/ + [os, version] + when /netbsdelf/ then [ 'netbsdelf', nil ] + when /openbsd(\d+\.\d+)?/ then [ 'openbsd', $1 ] + when /bitrig(\d+\.\d+)?/ then [ 'bitrig', $1 ] + when /solaris(\d+\.\d+)?/ then [ 'solaris', $1 ] + # test + when /^(\w+_platform)(\d+)?/ then [ $1, $2 ] + else [ 'unknown', nil ] + end when Gem::Platform then @cpu = arch.cpu @os = arch.os @@ -180,19 +180,19 @@ class Gem::Platform when String then # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007 other = case other - when /^i686-darwin(\d)/ then ['x86', 'darwin', $1 ] - when /^i\d86-linux/ then ['x86', 'linux', nil ] - when 'java', 'jruby' then [nil, 'java', nil ] - when /^dalvik(\d+)?$/ then [nil, 'dalvik', $1 ] - when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet', $2 ] - when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ] - when /mswin64(\_(\d+))?/ then ['x64', 'mswin64', $2 ] - when 'powerpc-darwin' then ['powerpc', 'darwin', nil ] - when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ] - when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8' ] - when /universal-darwin(\d)/ then ['universal', 'darwin', $1 ] - else other - end + when /^i686-darwin(\d)/ then ['x86', 'darwin', $1 ] + when /^i\d86-linux/ then ['x86', 'linux', nil ] + when 'java', 'jruby' then [nil, 'java', nil ] + when /^dalvik(\d+)?$/ then [nil, 'dalvik', $1 ] + when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet', $2 ] + when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ] + when /mswin64(\_(\d+))?/ then ['x64', 'mswin64', $2 ] + when 'powerpc-darwin' then ['powerpc', 'darwin', nil ] + when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ] + when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8' ] + when /universal-darwin(\d)/ then ['universal', 'darwin', $1 ] + else other + end other = Gem::Platform.new other else diff --git a/lib/rubygems/psych_additions.rb b/lib/rubygems/psych_additions.rb index 1ddd74421c..a13c1ec676 100644 --- a/lib/rubygems/psych_additions.rb +++ b/lib/rubygems/psych_additions.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true # This exists just to satisfy bugs in marshal'd gemspecs that -# contain a reference to YAML::PrivateType. We prune these out +# contain a reference to Psych::PrivateType. We prune these out # in Specification._load, but if we don't have the constant, Marshal # blows up. diff --git a/lib/rubygems/query_utils.rb b/lib/rubygems/query_utils.rb index 0acd5bf9c8..f4cfea3087 100644 --- a/lib/rubygems/query_utils.rb +++ b/lib/rubygems/query_utils.rb @@ -54,14 +54,14 @@ module Gem::QueryUtils end def defaults_str # :nodoc: - "--local --name-matches // --no-details --versions --no-installed" + "--local --no-details --versions --no-installed" end def execute - gem_names = Array(options[:name]) - - if !args.empty? - gem_names = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i } + gem_names = if args.empty? + [options[:name]] + else + options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i } end terminate_interaction(check_installed_gems(gem_names)) if check_installed_gems? @@ -96,7 +96,7 @@ module Gem::QueryUtils end def gem_name? - !options[:name].source.empty? + !options[:name].nil? end def prerelease @@ -129,12 +129,10 @@ module Gem::QueryUtils display_header("LOCAL") specs = Gem::Specification.find_all do |s| - s.name =~ name and req =~ s.version - end + name_matches = name ? s.name =~ name : true + version_matches = show_prereleases? || !s.version.prerelease? - dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req } - specs.select! do |s| - dep.match?(s.name, s.version, show_prereleases?) + name_matches and version_matches end spec_tuples = specs.map do |spec| @@ -149,13 +147,13 @@ module Gem::QueryUtils fetcher = Gem::SpecFetcher.fetcher - spec_tuples = if name.respond_to?(:source) && name.source.empty? - fetcher.detect(specs_type) { true } - else - fetcher.detect(specs_type) do |name_tuple| - name === name_tuple.name - end - end + spec_tuples = if name.nil? + fetcher.detect(specs_type) { true } + else + fetcher.detect(specs_type) do |name_tuple| + name === name_tuple.name + end + end output_query_results(spec_tuples) end diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index bd8165e3c7..b8f9f90cee 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -172,10 +172,10 @@ class Gem::RemoteFetcher when nil then # TODO test for local overriding cache source_path = if Gem.win_platform? && source_uri.scheme && !source_uri.path.include?(':') - "#{source_uri.scheme}:#{source_uri.path}" - else - source_uri.path - end + "#{source_uri.scheme}:#{source_uri.path}" + else + source_uri.path + end source_path = Gem::UriFormatter.new(source_path).unescape diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb index bec29ef1b9..684d3fc7fe 100644 --- a/lib/rubygems/request_set/lockfile.rb +++ b/lib/rubygems/request_set/lockfile.rb @@ -56,10 +56,10 @@ class Gem::RequestSet::Lockfile deps[name] = if [Gem::Resolver::VendorSpecification, Gem::Resolver::GitSpecification].include? spec.class - Gem::Requirement.source_set - else - requirement - end + Gem::Requirement.source_set + else + requirement + end end deps diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb index 237bc3f782..45252ed241 100644 --- a/lib/rubygems/resolver/installer_set.rb +++ b/lib/rubygems/resolver/installer_set.rb @@ -76,21 +76,21 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set newest = found.last + unless newest + exc = Gem::UnsatisfiableDependencyError.new request + exc.errors = errors + + raise exc + end + unless @force found_matching_metadata = found.reverse.find do |spec| metadata_satisfied?(spec) end if found_matching_metadata.nil? - if newest - ensure_required_ruby_version_met(newest.spec) - ensure_required_rubygems_version_met(newest.spec) - else - exc = Gem::UnsatisfiableDependencyError.new request - exc.errors = errors - - raise exc - end + ensure_required_ruby_version_met(newest.spec) + ensure_required_rubygems_version_met(newest.spec) else newest = found_matching_metadata end diff --git a/lib/rubygems/safe_yaml.rb b/lib/rubygems/safe_yaml.rb index e905052e1c..81f99ee26e 100644 --- a/lib/rubygems/safe_yaml.rb +++ b/lib/rubygems/safe_yaml.rb @@ -24,33 +24,33 @@ module Gem runtime ].freeze - if ::YAML.respond_to? :safe_load + if ::Psych.respond_to? :safe_load def self.safe_load(input) if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') - ::YAML.safe_load(input, permitted_classes: PERMITTED_CLASSES, permitted_symbols: PERMITTED_SYMBOLS, aliases: true) + ::Psych.safe_load(input, permitted_classes: PERMITTED_CLASSES, permitted_symbols: PERMITTED_SYMBOLS, aliases: true) else - ::YAML.safe_load(input, PERMITTED_CLASSES, PERMITTED_SYMBOLS, true) + ::Psych.safe_load(input, PERMITTED_CLASSES, PERMITTED_SYMBOLS, true) end end def self.load(input) if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') - ::YAML.safe_load(input, permitted_classes: [::Symbol]) + ::Psych.safe_load(input, permitted_classes: [::Symbol]) else - ::YAML.safe_load(input, [::Symbol]) + ::Psych.safe_load(input, [::Symbol]) end end else unless Gem::Deprecate.skip - warn "YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0)." + warn "Psych safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0)." end def self.safe_load(input, *args) - ::YAML.load input + ::Psych.load input end def self.load(input) - ::YAML.load input + ::Psych.load input end end end diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb index f21c175642..fc23c1c481 100644 --- a/lib/rubygems/security.rb +++ b/lib/rubygems/security.rb @@ -261,7 +261,7 @@ require_relative 'openssl' # 2. Grab the public key from the gemspec # # gem spec some_signed_gem-1.0.gem cert_chain | \ -# ruby -ryaml -e 'puts YAML.load($stdin)' > public_key.crt +# ruby -rpsych -e 'puts Psych.load($stdin)' > public_key.crt # # 3. Generate a SHA1 hash of the data.tar.gz # diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb index f03e09872c..85c300a8f8 100644 --- a/lib/rubygems/source.rb +++ b/lib/rubygems/source.rb @@ -81,12 +81,12 @@ class Gem::Source return Gem::Resolver::IndexSet.new self if 'file' == uri.scheme fetch_uri = if uri.host == "rubygems.org" - index_uri = uri.dup - index_uri.host = "index.rubygems.org" - index_uri - else - uri - end + index_uri = uri.dup + index_uri.host = "index.rubygems.org" + index_uri + else + uri + end bundler_api_uri = enforce_trailing_slash(fetch_uri) diff --git a/lib/rubygems/source_list.rb b/lib/rubygems/source_list.rb index 13b25b63dc..16e90e1ef7 100644 --- a/lib/rubygems/source_list.rb +++ b/lib/rubygems/source_list.rb @@ -51,13 +51,13 @@ class Gem::SourceList require "uri" src = case obj - when URI - Gem::Source.new(obj) - when Gem::Source - obj - else - Gem::Source.new(URI.parse(obj)) - end + when URI + Gem::Source.new(obj) + when Gem::Source + obj + else + Gem::Source.new(URI.parse(obj)) + end @sources << src unless @sources.include?(src) src diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index b97bd49692..15bfbb6f8d 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -191,10 +191,10 @@ class Gem::SpecFetcher end matches = if matches.empty? && type != :prerelease - suggest_gems_from_name gem_name, :prerelease - else - matches.uniq.sort_by {|name, dist| dist } - end + suggest_gems_from_name gem_name, :prerelease + else + matches.uniq.sort_by {|name, dist| dist } + end matches.map {|name, dist| name }.uniq.first(num_results) end @@ -216,27 +216,27 @@ class Gem::SpecFetcher @sources.each_source do |source| begin names = case type - when :latest - tuples_for source, :latest - when :released - tuples_for source, :released - when :complete - names = - tuples_for(source, :prerelease, true) + - tuples_for(source, :released) - - names.sort - when :abs_latest - names = - tuples_for(source, :prerelease, true) + - tuples_for(source, :latest) - - names.sort - when :prerelease - tuples_for(source, :prerelease) - else - raise Gem::Exception, "Unknown type - :#{type}" - end + when :latest + tuples_for source, :latest + when :released + tuples_for source, :released + when :complete + names = + tuples_for(source, :prerelease, true) + + tuples_for(source, :released) + + names.sort + when :abs_latest + names = + tuples_for(source, :prerelease, true) + + tuples_for(source, :latest) + + names.sort + when :prerelease + tuples_for(source, :prerelease) + else + raise Gem::Exception, "Unknown type - :#{type}" + end rescue Gem::RemoteFetcher::FetchError => e errors << Gem::SourceFetchProblem.new(source, e) else diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 031a37f775..43ab917d19 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -11,7 +11,6 @@ require_relative 'basic_specification' require_relative 'stub_specification' require_relative 'platform' require_relative 'requirement' -require_relative 'specification_policy' require_relative 'util/list' ## @@ -163,15 +162,15 @@ class Gem::Specification < Gem::BasicSpecification @@default_value.each do |k,v| INITIALIZE_CODE_FOR_DEFAULTS[k] = case v - when [], {}, true, false, nil, Numeric, Symbol - v.inspect - when String - v.dump - when Numeric - "default_value(:#{k})" - else - "default_value(:#{k}).dup" - end + when [], {}, true, false, nil, Numeric, Symbol + v.inspect + when String + v.dump + when Numeric + "default_value(:#{k})" + else + "default_value(:#{k}).dup" + end end @@attributes = @@default_value.keys.sort_by {|s| s.to_s } @@ -226,7 +225,7 @@ class Gem::Specification < Gem::BasicSpecification attr_reader :version ## - # A short summary of this gem's description. Displayed in `gem list -d`. + # A short summary of this gem's description. Displayed in <tt>gem list -d</tt>. # # The #description should be more detailed than the summary. # @@ -272,7 +271,7 @@ class Gem::Specification < Gem::BasicSpecification # A list of authors for this gem. # # Alternatively, a single author can be specified by assigning a string to - # `spec.author` + # +spec.author+ # # Usage: # @@ -1116,7 +1115,7 @@ class Gem::Specification < Gem::BasicSpecification file = file.dup.tap(&Gem::UNTAINT) return unless File.file?(file) - code = Gem.open_with_flock(file, 'r:UTF-8:-', &:read) + code = Gem.open_file(file, 'r:UTF-8:-', &:read) code.tap(&Gem::UNTAINT) @@ -1269,21 +1268,21 @@ class Gem::Specification < Gem::BasicSpecification current_version = CURRENT_SPECIFICATION_VERSION field_count = if spec.specification_version > current_version - spec.instance_variable_set :@specification_version, - current_version - MARSHAL_FIELDS[current_version] - else - MARSHAL_FIELDS[spec.specification_version] - end + spec.instance_variable_set :@specification_version, + current_version + MARSHAL_FIELDS[current_version] + else + MARSHAL_FIELDS[spec.specification_version] + end if array.size < field_count raise TypeError, "invalid Gem::Specification format #{array.inspect}" end - # Cleanup any YAML::PrivateType. They only show up for an old bug + # Cleanup any Psych::PrivateType. They only show up for an old bug # where nil => null, so just convert them to nil based on the type. - array.map! {|e| e.kind_of?(YAML::PrivateType) ? nil : e } + array.map! {|e| e.kind_of?(Psych::PrivateType) ? nil : e } spec.instance_variable_set :@rubygems_version, array[0] # spec version @@ -1474,10 +1473,10 @@ class Gem::Specification < Gem::BasicSpecification def add_dependency_with_type(dependency, type, requirements) requirements = if requirements.empty? - Gem::Requirement.default - else - requirements.flatten - end + Gem::Requirement.default + else + requirements.flatten + end unless dependency.respond_to?(:name) && dependency.respond_to?(:requirement) @@ -1685,18 +1684,18 @@ class Gem::Specification < Gem::BasicSpecification # This is the cleanest, most-readable, faster-than-using-Date # way to do it. @date = case date - when String then - if DateTimeFormat =~ date - Time.utc($1.to_i, $2.to_i, $3.to_i) - else - raise(Gem::InvalidSpecificationException, - "invalid date format in specification: #{date.inspect}") - end - when Time, DateLike then - Time.utc(date.year, date.month, date.day) - else - TODAY - end + when String then + if DateTimeFormat =~ date + Time.utc($1.to_i, $2.to_i, $3.to_i) + else + raise(Gem::InvalidSpecificationException, + "invalid date format in specification: #{date.inspect}") + end + when Time, DateLike then + Time.utc(date.year, date.month, date.day) + else + TODAY + end end ## @@ -1802,13 +1801,13 @@ class Gem::Specification < Gem::BasicSpecification coder.add 'name', @name coder.add 'version', @version platform = case @original_platform - when nil, '' then - 'ruby' - when String then - @original_platform - else - @original_platform.to_s - end + when nil, '' then + 'ruby' + when String then + @original_platform + else + @original_platform.to_s + end coder.add 'platform', platform attributes = @@attributes.map(&:to_s) - %w[name version platform] @@ -2025,10 +2024,10 @@ class Gem::Specification < Gem::BasicSpecification def base_dir return Gem.dir unless loaded_from @base_dir ||= if default_gem? - File.dirname File.dirname File.dirname loaded_from - else - File.dirname File.dirname loaded_from - end + File.dirname File.dirname File.dirname loaded_from + else + File.dirname File.dirname loaded_from + end end ## @@ -2655,9 +2654,9 @@ class Gem::Specification < Gem::BasicSpecification default = self.default_value attribute value = case default - when Time, Numeric, Symbol, true, false, nil then default - else default.dup - end + when Time, Numeric, Symbol, true, false, nil then default + else default.dup + end instance_variable_set "@#{attribute}", value end diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index 73bd31970c..002b3c20c4 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -199,17 +199,17 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: base = segments.first 2 recommendation = if (op == '>' || op == '>=') && segments == [0] - " use a bounded requirement, such as '~> x.y'" - else - bugfix = if op == '>' - ", '> #{dep_version}'" - elsif op == '>=' and base != segments - ", '>= #{dep_version}'" - end - - " if #{dep.name} is semantically versioned, use:\n" \ - " add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}" - end + " use a bounded requirement, such as '~> x.y'" + else + bugfix = if op == '>' + ", '> #{dep_version}'" + elsif op == '>=' and base != segments + ", '>= #{dep_version}'" + end + + " if #{dep.name} is semantically versioned, use:\n" \ + " add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}" + end warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n" end @@ -332,11 +332,11 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: def validate_array_attribute(field) val = @specification.send(field) klass = case field - when :dependencies then - Gem::Dependency - else - String - end + when :dependencies then + Gem::Dependency + else + String + end unless Array === val and val.all? {|x| x.kind_of?(klass) } error "#{field} must be an Array of #{klass}" diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index 47fe7da695..b1dd7397ae 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -36,18 +36,18 @@ class Gem::StubSpecification < Gem::BasicSpecification parts = data[PREFIX.length..-1].split(" ".freeze, 4) @name = parts[0].freeze @version = if Gem::Version.correct?(parts[1]) - Gem::Version.new(parts[1]) - else - Gem::Version.new(0) - end + Gem::Version.new(parts[1]) + else + Gem::Version.new(0) + end @platform = Gem::Platform.new parts[2] @extensions = extensions @full_name = if platform == Gem::Platform::RUBY - "#{name}-#{version}" - else - "#{name}-#{version}-#{platform}" - end + "#{name}-#{version}" + else + "#{name}-#{version}-#{platform}" + end path_list = parts.last @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0".freeze).map! do |x| @@ -110,16 +110,16 @@ class Gem::StubSpecification < Gem::BasicSpecification begin saved_lineno = $. - Gem.open_with_flock loaded_from, OPEN_MODE do |file| + Gem.open_file loaded_from, OPEN_MODE do |file| begin file.readline # discard encoding line stubline = file.readline.chomp if stubline.start_with?(PREFIX) extensions = if /\A#{PREFIX}/ =~ file.readline.chomp - $'.split "\0" - else - StubLine::NO_EXTENSIONS - end + $'.split "\0" + else + StubLine::NO_EXTENSIONS + end @data = StubLine.new stubline, extensions end @@ -185,14 +185,11 @@ class Gem::StubSpecification < Gem::BasicSpecification def to_spec @spec ||= if @data - loaded = Gem.loaded_specs[name] - loaded if loaded && loaded.version == version - end + loaded = Gem.loaded_specs[name] + loaded if loaded && loaded.version == version + end @spec ||= Gem::Specification.load(loaded_from) - @spec.ignored = @ignored if @spec - - @spec end ## diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 11fb611329..a36c5cbe2b 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -200,13 +200,13 @@ class Gem::Uninstaller executables = executables.map {|exec| formatted_program_filename exec } remove = if @force_executables.nil? - ask_yes_no("Remove executables:\n" + - "\t#{executables.join ', '}\n\n" + - "in addition to the gem?", - true) - else - @force_executables - end + ask_yes_no("Remove executables:\n" + + "\t#{executables.join ', '}\n\n" + + "in addition to the gem?", + true) + else + @force_executables + end if remove bin_dir = @bin_dir || Gem.bindir(spec.base_dir) diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 0ab44fbf6c..e632f418a9 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -258,23 +258,23 @@ class Gem::StreamUI end default_answer = case default - when nil - 'yn' - when true - 'Yn' - else - 'yN' - end + when nil + 'yn' + when true + 'Yn' + else + 'yN' + end result = nil while result.nil? do result = case ask "#{question} [#{default_answer}]" - when /^y/i then true - when /^n/i then false - when /^$/ then default - else nil - end + when /^y/i then true + when /^n/i then false + when /^$/ then default + else nil + end end return result diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index 42e0f23505..d8aeb6f278 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -310,12 +310,12 @@ class Gem::Version def release @@release[self] ||= if prerelease? - segments = self.segments - segments.pop while segments.any? {|s| String === s } - self.class.new segments.join('.') - else - self - end + segments = self.segments + segments.pop while segments.any? {|s| String === s } + self.class.new segments.join('.') + else + self + end end def segments # :nodoc: @@ -341,9 +341,11 @@ class Gem::Version # Compares this version with +other+ returning -1, 0, or 1 if the # other version is larger, the same, or smaller than this # one. Attempts to compare to something that's not a - # <tt>Gem::Version</tt> return +nil+. + # <tt>Gem::Version</tt> or a valid version String return +nil+. def <=>(other) + return self <=> self.class.new(other) if (String === other) && self.class.correct?(other) + return unless Gem::Version === other return 0 if @version == other._version || canonical_segments == other.canonical_segments |