From 5335ce0e060c7a2a0b01c57f8f8a64254f2658e1 Mon Sep 17 00:00:00 2001 From: hsbt Date: Wed, 21 Nov 2018 10:20:47 +0000 Subject: Merge master branch from rubygems/rubygems upstream. * Enable Style/MethodDefParentheses in Rubocop https://github.com/rubygems/rubygems/pull/2478 * Enable Style/MultilineIfThen in Rubocop https://github.com/rubygems/rubygems/pull/2479 * Fix required_ruby_version with prereleases and improve error message https://github.com/rubygems/rubygems/pull/2344 * Fix bundler rubygems binstub not properly looking for bundler https://github.com/rubygems/rubygems/pull/2426 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/available_set.rb | 2 +- lib/rubygems/basic_specification.rb | 20 +-- lib/rubygems/bundler_version_finder.rb | 13 +- lib/rubygems/command.rb | 18 +-- lib/rubygems/command_manager.rb | 7 +- lib/rubygems/commands/build_command.rb | 5 +- lib/rubygems/commands/cert_command.rb | 17 +- lib/rubygems/commands/check_command.rb | 2 +- lib/rubygems/commands/cleanup_command.rb | 11 +- lib/rubygems/commands/contents_command.rb | 29 ++-- lib/rubygems/commands/dependency_command.rb | 34 ++-- lib/rubygems/commands/environment_command.rb | 2 +- lib/rubygems/commands/fetch_command.rb | 5 +- lib/rubygems/commands/generate_index_command.rb | 5 +- lib/rubygems/commands/help_command.rb | 17 +- lib/rubygems/commands/install_command.rb | 21 ++- lib/rubygems/commands/list_command.rb | 1 - lib/rubygems/commands/lock_command.rb | 7 +- lib/rubygems/commands/open_command.rb | 20 +-- lib/rubygems/commands/owner_command.rb | 8 +- lib/rubygems/commands/pristine_command.rb | 14 +- lib/rubygems/commands/push_command.rb | 5 +- lib/rubygems/commands/query_command.rb | 48 +++--- lib/rubygems/commands/rdoc_command.rb | 7 +- lib/rubygems/commands/search_command.rb | 1 - lib/rubygems/commands/server_command.rb | 3 +- lib/rubygems/commands/setup_command.rb | 46 +++--- lib/rubygems/commands/signin_command.rb | 1 - lib/rubygems/commands/signout_command.rb | 4 +- lib/rubygems/commands/sources_command.rb | 23 ++- lib/rubygems/commands/specification_command.rb | 14 +- lib/rubygems/commands/uninstall_command.rb | 6 +- lib/rubygems/commands/unpack_command.rb | 11 +- lib/rubygems/commands/update_command.rb | 30 ++-- lib/rubygems/commands/which_command.rb | 9 +- lib/rubygems/commands/yank_command.rb | 3 +- lib/rubygems/config_file.rb | 14 +- lib/rubygems/core_ext/kernel_require.rb | 12 +- lib/rubygems/defaults.rb | 14 +- lib/rubygems/dependency.rb | 26 +-- lib/rubygems/dependency_installer.rb | 40 ++--- lib/rubygems/dependency_list.rb | 17 +- lib/rubygems/deprecate.rb | 5 +- lib/rubygems/doctor.rb | 9 +- lib/rubygems/errors.rb | 6 +- lib/rubygems/exceptions.rb | 8 +- lib/rubygems/ext.rb | 1 - lib/rubygems/ext/build_error.rb | 1 - lib/rubygems/ext/builder.rb | 20 +-- lib/rubygems/ext/cmake_builder.rb | 2 +- lib/rubygems/ext/configure_builder.rb | 2 +- lib/rubygems/ext/ext_conf_builder.rb | 4 +- lib/rubygems/ext/rake_builder.rb | 2 +- lib/rubygems/gem_runner.rb | 4 +- lib/rubygems/gemcutter_utilities.rb | 15 +- lib/rubygems/indexer.rb | 29 ++-- lib/rubygems/install_default_message.rb | 1 - lib/rubygems/install_message.rb | 1 - lib/rubygems/install_update_options.rb | 6 +- lib/rubygems/installer.rb | 60 +++---- lib/rubygems/installer_test_case.rb | 1 - lib/rubygems/local_remote_options.rb | 3 +- lib/rubygems/mock_gem_ui.rb | 7 +- lib/rubygems/name_tuple.rb | 8 +- lib/rubygems/package.rb | 62 ++++---- lib/rubygems/package/digest_io.rb | 7 +- lib/rubygems/package/file_source.rb | 7 +- lib/rubygems/package/io_source.rb | 3 +- lib/rubygems/package/old.rb | 10 +- lib/rubygems/package/source.rb | 1 - lib/rubygems/package/tar_header.rb | 2 +- lib/rubygems/package/tar_reader.rb | 4 +- lib/rubygems/package/tar_reader/entry.rb | 2 +- lib/rubygems/package/tar_test_case.rb | 2 +- lib/rubygems/package/tar_writer.rb | 18 +-- lib/rubygems/package_task.rb | 1 - lib/rubygems/path_support.rb | 6 +- lib/rubygems/platform.rb | 5 +- lib/rubygems/psych_tree.rb | 2 +- lib/rubygems/remote_fetcher.rb | 20 +-- lib/rubygems/request.rb | 24 +-- lib/rubygems/request/connection_pools.rb | 17 +- lib/rubygems/request/http_pool.rb | 7 +- lib/rubygems/request/https_pool.rb | 4 +- lib/rubygems/request_set.rb | 48 +++--- lib/rubygems/request_set/gem_dependency_api.rb | 64 ++++---- lib/rubygems/request_set/lockfile.rb | 24 +-- lib/rubygems/request_set/lockfile/parser.rb | 26 +-- lib/rubygems/request_set/lockfile/tokenizer.rb | 18 +-- lib/rubygems/requirement.rb | 24 +-- lib/rubygems/resolver.rb | 18 +-- lib/rubygems/resolver/activation_request.rb | 12 +- lib/rubygems/resolver/api_set.rb | 11 +- lib/rubygems/resolver/api_specification.rb | 5 +- lib/rubygems/resolver/best_set.rb | 11 +- lib/rubygems/resolver/composed_set.rb | 11 +- lib/rubygems/resolver/conflict.rb | 10 +- lib/rubygems/resolver/current_set.rb | 3 +- lib/rubygems/resolver/dependency_request.rb | 8 +- lib/rubygems/resolver/git_set.rb | 11 +- lib/rubygems/resolver/git_specification.rb | 9 +- lib/rubygems/resolver/index_set.rb | 11 +- lib/rubygems/resolver/index_specification.rb | 7 +- lib/rubygems/resolver/installed_specification.rb | 7 +- lib/rubygems/resolver/installer_set.rb | 24 +-- lib/rubygems/resolver/local_specification.rb | 3 +- lib/rubygems/resolver/lock_set.rb | 11 +- lib/rubygems/resolver/lock_specification.rb | 15 +- lib/rubygems/resolver/requirement_list.rb | 2 +- lib/rubygems/resolver/set.rb | 4 +- lib/rubygems/resolver/source_set.rb | 7 +- lib/rubygems/resolver/spec_specification.rb | 3 +- lib/rubygems/resolver/specification.rb | 5 +- lib/rubygems/resolver/vendor_set.rb | 9 +- lib/rubygems/resolver/vendor_specification.rb | 5 +- lib/rubygems/safe_yaml.rb | 8 +- lib/rubygems/security.rb | 41 +++-- lib/rubygems/security/policies.rb | 1 - lib/rubygems/security/policy.rb | 44 +++--- lib/rubygems/security/signer.rb | 17 +- lib/rubygems/security/trust_dir.rb | 15 +- lib/rubygems/server.rb | 32 ++-- lib/rubygems/source.rb | 12 +- lib/rubygems/source/git.rb | 19 ++- lib/rubygems/source/installed.rb | 7 +- lib/rubygems/source/local.rb | 14 +- lib/rubygems/source/lock.rb | 8 +- lib/rubygems/source/specific_file.rb | 10 +- lib/rubygems/source/vendor.rb | 5 +- lib/rubygems/source_list.rb | 4 +- lib/rubygems/source_local.rb | 1 - lib/rubygems/spec_fetcher.rb | 3 +- lib/rubygems/specification.rb | 192 +++++++++++------------ lib/rubygems/specification_policy.rb | 62 ++++---- lib/rubygems/stub_specification.rb | 12 +- lib/rubygems/test_case.rb | 136 +++++++++------- lib/rubygems/test_utilities.rb | 39 +++-- lib/rubygems/text.rb | 10 +- lib/rubygems/uninstaller.rb | 26 +-- lib/rubygems/uri_formatter.rb | 3 +- lib/rubygems/user_interaction.rb | 27 ++-- lib/rubygems/util.rb | 6 +- lib/rubygems/util/list.rb | 2 +- lib/rubygems/validator.rb | 9 +- lib/rubygems/version.rb | 26 +-- lib/rubygems/version_option.rb | 5 +- 146 files changed, 1068 insertions(+), 1145 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/available_set.rb b/lib/rubygems/available_set.rb index 49b5d5fd06..8334a73ecb 100644 --- a/lib/rubygems/available_set.rb +++ b/lib/rubygems/available_set.rb @@ -103,7 +103,7 @@ class Gem::AvailableSet # Other options are :shallow for only direct development dependencies of the # gems in this set or :all for all development dependencies. - def to_request_set development = :none + def to_request_set(development = :none) request_set = Gem::RequestSet.new request_set.development = :all == development diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 54242983ff..d1878021ba 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -65,10 +65,10 @@ class Gem::BasicSpecification ## # Return true if this spec can require +file+. - def contains_requirable_file? file - if @ignored then + def contains_requirable_file?(file) + if @ignored return false - elsif missing_extensions? then + elsif missing_extensions? @ignored = true warn "Ignoring #{full_name} because its extensions are not built. " + @@ -124,7 +124,7 @@ class Gem::BasicSpecification # default Ruby platform. def full_name - if platform == Gem::Platform::RUBY or platform.nil? then + if platform == Gem::Platform::RUBY or platform.nil? "#{name}-#{version}".dup.untaint else "#{name}-#{version}-#{platform}".dup.untaint @@ -160,8 +160,8 @@ class Gem::BasicSpecification # Full path of the target library file. # If the file is not in this gem, return nil. - def to_fullpath path - if activated? then + def to_fullpath(path) + if activated? @paths_map ||= {} @paths_map[path] ||= begin @@ -249,7 +249,7 @@ class Gem::BasicSpecification def source_paths paths = raw_require_paths.dup - if have_extensions? then + if have_extensions? ext_dirs = extensions.map do |extension| extension.split(File::SEPARATOR, 2).first end.uniq @@ -263,7 +263,7 @@ class Gem::BasicSpecification ## # Return all files in this gem that match for +glob+. - def matches_for_glob glob # TODO: rename? + def matches_for_glob(glob) # TODO: rename? # TODO: do we need these?? Kill it glob = File.join(self.lib_dirs_glob, glob) @@ -276,7 +276,7 @@ class Gem::BasicSpecification def lib_dirs_glob dirs = if self.raw_require_paths - if self.raw_require_paths.size > 1 then + if self.raw_require_paths.size > 1 "{#{self.raw_require_paths.join(',')}}" else self.raw_require_paths.first @@ -316,7 +316,7 @@ class Gem::BasicSpecification def have_extensions?; !extensions.empty?; end - def have_file? file, suffixes + def have_file?(file, suffixes) return true if raw_require_paths.any? do |path| base = File.join(gems_dir, full_name, path.untaint, file).untaint suffixes.any? { |suf| File.file? base + suf } diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index 7babeaa848..11fb81450a 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -3,15 +3,6 @@ require "rubygems/util" module Gem::BundlerVersionFinder - @without_filtering = false - - def self.without_filtering - without_filtering, @without_filtering = true, @without_filtering - yield - ensure - @without_filtering = without_filtering - end - def self.bundler_version version, _ = bundler_version_with_reason @@ -21,8 +12,6 @@ module Gem::BundlerVersionFinder end def self.bundler_version_with_reason - return if @without_filtering - if v = ENV["BUNDLER_VERSION"] return [v, "`$BUNDLER_VERSION`"] end @@ -40,7 +29,7 @@ module Gem::BundlerVersionFinder return unless vr = bundler_version_with_reason <<-EOS Could not find 'bundler' (#{vr.first}) required by #{vr.last}. -To update to the lastest version installed on your system, run `bundle update --bundler`. +To update to the latest version installed on your system, run `bundle update --bundler`. To install the missing version, run `gem install bundler:#{vr.first}` EOS end diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 3fc8a70a3e..9f22cb9e82 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -160,7 +160,7 @@ class Gem::Command msg << ", here is why:\n" errors.each { |x| msg << " #{x.wordy}\n" } else - if required_by and gem != required_by then + if required_by and gem != required_by msg << " (required by #{required_by}) in any repository" else msg << " in any repository" @@ -169,7 +169,7 @@ class Gem::Command alert_error msg - unless domain == :local then # HACK + unless domain == :local # HACK suggestions = Gem::SpecFetcher.fetcher.suggest_gems_from_name gem_name unless suggestions.empty? @@ -184,7 +184,7 @@ class Gem::Command def get_all_gem_names args = options[:args] - if args.nil? or args.empty? then + if args.nil? or args.empty? raise Gem::CommandLineError, "Please specify at least one gem name (e.g. gem build GEMNAME)" end @@ -214,12 +214,12 @@ class Gem::Command def get_one_gem_name args = options[:args] - if args.nil? or args.empty? then + if args.nil? or args.empty? raise Gem::CommandLineError, "Please specify a gem name on the command line (e.g. gem build GEMNAME)" end - if args.size > 1 then + if args.size > 1 raise Gem::CommandLineError, "Too many gem names (#{args.join(', ')}); please specify only one" end @@ -313,9 +313,9 @@ class Gem::Command self.ui = ui = Gem::SilentUI.new end - if options[:help] then + if options[:help] show_help - elsif @when_invoked then + elsif @when_invoked @when_invoked.call options else execute @@ -451,7 +451,7 @@ class Gem::Command # Adds a section with +title+ and +content+ to the parser help view. Used # for adding command arguments and default arguments. - def add_parser_run_info title, content + def add_parser_run_info(title, content) return if content.empty? @parser.separator nil @@ -531,7 +531,7 @@ class Gem::Command add_common_option('-V', '--[no-]verbose', 'Set the verbose level of output') do |value, options| # Set us to "really verbose" so the progress meter works - if Gem.configuration.verbose and value then + if Gem.configuration.verbose and value Gem.configuration.verbose = 1 else Gem.configuration.verbose = value diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb index 40ae6191c5..8e4e26fdea 100644 --- a/lib/rubygems/command_manager.rb +++ b/lib/rubygems/command_manager.rb @@ -155,7 +155,7 @@ class Gem::CommandManager end def process_args(args, build_args=nil) - if args.empty? then + if args.empty? say Gem::Command::HELP terminate_interaction 1 end @@ -182,10 +182,10 @@ class Gem::CommandManager possibilities = find_command_possibilities cmd_name - if possibilities.size > 1 then + if possibilities.size > 1 raise Gem::CommandLineError, "Ambiguous command #{cmd_name} matches [#{possibilities.join(', ')}]" - elsif possibilities.empty? then + elsif possibilities.empty? raise Gem::CommandLineError, "Unknown command #{cmd_name}" end @@ -230,4 +230,3 @@ class Gem::CommandManager end end - diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index 3c778cf705..78737154b6 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -50,11 +50,11 @@ with gem spec: gemspec += '.gemspec' if File.exist? gemspec + '.gemspec' end - if File.exist? gemspec then + if File.exist? gemspec Dir.chdir(File.dirname(gemspec)) do spec = Gem::Specification.load File.basename(gemspec) - if spec then + if spec Gem::Package.build( spec, options[:force], @@ -72,4 +72,3 @@ with gem spec: end end - diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb index e93c39747c..5695460d94 100644 --- a/lib/rubygems/commands/cert_command.rb +++ b/lib/rubygems/commands/cert_command.rb @@ -98,7 +98,7 @@ class Gem::Commands::CertCommand < Gem::Command end end - def add_certificate certificate # :nodoc: + def add_certificate(certificate) # :nodoc: Gem::Security.trust_dir.trust_cert certificate say "Added '#{certificate.subject}'" @@ -132,7 +132,7 @@ class Gem::Commands::CertCommand < Gem::Command sign_certificates unless options[:sign].empty? end - def build email + def build(email) if !valid_email?(email) raise Gem::CommandLineError, "Invalid email address #{email}" end @@ -148,7 +148,7 @@ class Gem::Commands::CertCommand < Gem::Command end end - def build_cert email, key # :nodoc: + def build_cert(email, key) # :nodoc: expiration_length_days = options[:expiration_length_days] || Gem.configuration.cert_expiration_length_days @@ -179,7 +179,7 @@ class Gem::Commands::CertCommand < Gem::Command return key, key_path end - def certificates_matching filter + def certificates_matching(filter) return enum_for __method__, filter unless block_given? Gem::Security.trusted_certificates.select do |certificate, _| @@ -231,7 +231,7 @@ For further reading on signing gems see `ri Gem::Security`. EOF end - def list_certificates_matching filter # :nodoc: + def list_certificates_matching(filter) # :nodoc: certificates_matching filter do |certificate, _| # this could probably be formatted more gracefully say certificate.subject.to_s @@ -276,14 +276,14 @@ For further reading on signing gems see `ri Gem::Security`. load_default_key unless options[:key] end - def remove_certificates_matching filter # :nodoc: + def remove_certificates_matching(filter) # :nodoc: certificates_matching filter do |certificate, path| FileUtils.rm path say "Removed '#{certificate.subject}'" end end - def sign cert_file + def sign(cert_file) cert = File.read cert_file cert = OpenSSL::X509::Certificate.new cert @@ -314,11 +314,10 @@ For further reading on signing gems see `ri Gem::Security`. private - def valid_email? email + def valid_email?(email) # It's simple, but is all we need email =~ /\A.+@.+\z/ end end if defined?(OpenSSL::SSL) - diff --git a/lib/rubygems/commands/check_command.rb b/lib/rubygems/commands/check_command.rb index 818cb05f55..7905b8ab69 100644 --- a/lib/rubygems/commands/check_command.rb +++ b/lib/rubygems/commands/check_command.rb @@ -44,7 +44,7 @@ class Gem::Commands::CheckCommand < Gem::Command gems = get_all_gem_names rescue [] Gem::Validator.new.alien(gems).sort.each do |key, val| - unless val.empty? then + unless val.empty? say "#{key} has #{val.size} problems" val.each do |error_entry| say " #{error_entry.path}:" diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb index fe85deddda..aeb4d82fae 100644 --- a/lib/rubygems/commands/cleanup_command.rb +++ b/lib/rubygems/commands/cleanup_command.rb @@ -62,7 +62,7 @@ If no gems are named all gems in GEM_HOME are cleaned. def execute say "Cleaning up installed gems..." - if options[:args].empty? then + if options[:args].empty? done = false last_set = nil @@ -111,7 +111,7 @@ If no gems are named all gems in GEM_HOME are cleaned. end def get_candidate_gems - @candidate_gems = unless options[:args].empty? then + @candidate_gems = unless options[:args].empty? options[:args].map do |gem_name| Gem::Specification.find_all_by_name gem_name end.flatten @@ -121,7 +121,6 @@ If no gems are named all gems in GEM_HOME are cleaned. end def get_gems_to_cleanup - gems_to_cleanup = @candidate_gems.select { |spec| @primary_gems[spec.name].version != spec.version } @@ -146,16 +145,16 @@ If no gems are named all gems in GEM_HOME are cleaned. Gem::Specification.each do |spec| if @primary_gems[spec.name].nil? or - @primary_gems[spec.name].version < spec.version then + @primary_gems[spec.name].version < spec.version @primary_gems[spec.name] = spec end end end - def uninstall_dep spec + def uninstall_dep(spec) return unless @full.ok_to_remove?(spec.full_name, options[:check_dev]) - if options[:dryrun] then + if options[:dryrun] say "Dry Run Mode: Would uninstall #{spec.full_name}" return end diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb index e0f2eedb5d..6da89a136e 100644 --- a/lib/rubygems/commands/contents_command.rb +++ b/lib/rubygems/commands/contents_command.rb @@ -73,7 +73,7 @@ prefix or only the files that are requireable. names.each do |name| found = - if options[:show_install_dir] then + if options[:show_install_dir] gem_install_dir name else gem_contents name @@ -83,15 +83,15 @@ prefix or only the files that are requireable. end end - def files_in spec - if spec.default_gem? then + def files_in(spec) + if spec.default_gem? files_in_default_gem spec else files_in_gem spec end end - def files_in_gem spec + def files_in_gem(spec) gem_path = spec.full_gem_path extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only] glob = "#{gem_path}#{extra}/**/*" @@ -102,7 +102,7 @@ prefix or only the files that are requireable. end end - def files_in_default_gem spec + def files_in_default_gem(spec) spec.files.map do |file| case file when /\A#{spec.bindir}\// @@ -115,7 +115,7 @@ prefix or only the files that are requireable. end end - def gem_contents name + def gem_contents(name) spec = spec_for name return false unless spec @@ -127,7 +127,7 @@ prefix or only the files that are requireable. true end - def gem_install_dir name + def gem_install_dir(name) spec = spec_for name return false unless spec @@ -138,27 +138,27 @@ prefix or only the files that are requireable. end def gem_names # :nodoc: - if options[:all] then + if options[:all] Gem::Specification.map(&:name) else get_all_gem_names end end - def path_description spec_dirs # :nodoc: - if spec_dirs.empty? then + def path_description(spec_dirs) # :nodoc: + if spec_dirs.empty? "default gem paths" else "specified path" end end - def show_files files + def show_files(files) files.sort.each do |prefix, basename| absolute_path = File.join(prefix, basename) next if File.directory? absolute_path - if options[:prefix] then + if options[:prefix] say absolute_path else say basename @@ -166,14 +166,14 @@ prefix or only the files that are requireable. end end - def spec_for name + def spec_for(name) spec = Gem::Specification.find_all_by_name(name, @version).last return spec if spec say "Unable to find gem '#{name}' in #{@path_kind}" - if Gem.configuration.verbose then + if Gem.configuration.verbose say "\nDirectories searched:" @spec_dirs.sort.each { |dir| say dir } end @@ -188,4 +188,3 @@ prefix or only the files that are requireable. end end - diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb index 97fd812ffa..9e88b04ea5 100644 --- a/lib/rubygems/commands/dependency_command.rb +++ b/lib/rubygems/commands/dependency_command.rb @@ -54,7 +54,7 @@ use with other commands. "#{program_name} REGEXP" end - def fetch_remote_specs dependency # :nodoc: + def fetch_remote_specs(dependency) # :nodoc: fetcher = Gem::SpecFetcher.fetcher ss, = fetcher.spec_for_dependency dependency @@ -62,7 +62,7 @@ use with other commands. ss.map { |spec, _| spec } end - def fetch_specs name_pattern, dependency # :nodoc: + def fetch_specs(name_pattern, dependency) # :nodoc: specs = [] if local? @@ -79,7 +79,7 @@ use with other commands. specs.uniq.sort end - def gem_dependency pattern, version, prerelease # :nodoc: + def gem_dependency(pattern, version, prerelease) # :nodoc: dependency = Gem::Deprecate.skip_during { Gem::Dependency.new pattern, version } @@ -89,9 +89,9 @@ use with other commands. dependency end - def display_pipe specs # :nodoc: + def display_pipe(specs) # :nodoc: specs.each do |spec| - unless spec.dependencies.empty? then + unless spec.dependencies.empty? spec.dependencies.sort_by { |dep| dep.name }.each do |dep| say "#{dep.name} --version '#{dep.requirement}'" end @@ -99,12 +99,12 @@ use with other commands. end end - def display_readable specs, reverse # :nodoc: + def display_readable(specs, reverse) # :nodoc: response = String.new specs.each do |spec| response << print_dependencies(spec) - unless reverse[spec.full_name].empty? then + unless reverse[spec.full_name].empty? response << " Used by\n" reverse[spec.full_name].each do |sp, dep| response << " #{sp} (#{dep})\n" @@ -128,7 +128,7 @@ use with other commands. reverse = reverse_dependencies specs - if options[:pipe_format] then + if options[:pipe_format] display_pipe specs else display_readable specs, reverse @@ -136,13 +136,13 @@ use with other commands. end def ensure_local_only_reverse_dependencies # :nodoc: - if options[:reverse_dependencies] and remote? and not local? then + if options[:reverse_dependencies] and remote? and not local? alert_error 'Only reverse dependencies for local gems are supported.' terminate_interaction 1 end end - def ensure_specs specs # :nodoc: + def ensure_specs(specs) # :nodoc: return unless specs.empty? patterns = options[:args].join ',' @@ -155,7 +155,7 @@ use with other commands. def print_dependencies(spec, level = 0) # :nodoc: response = String.new response << ' ' * level + "Gem #{spec.full_name}\n" - unless spec.dependencies.empty? then + unless spec.dependencies.empty? spec.dependencies.sort_by { |dep| dep.name }.each do |dep| response << ' ' * level + " #{dep}\n" end @@ -163,7 +163,7 @@ use with other commands. response end - def remote_specs dependency # :nodoc: + def remote_specs(dependency) # :nodoc: fetcher = Gem::SpecFetcher.fetcher ss, _ = fetcher.spec_for_dependency dependency @@ -171,7 +171,7 @@ use with other commands. ss.map { |s,o| s } end - def reverse_dependencies specs # :nodoc: + def reverse_dependencies(specs) # :nodoc: reverse = Hash.new { |h, k| h[k] = [] } return reverse unless options[:reverse_dependencies] @@ -186,7 +186,7 @@ use with other commands. ## # Returns an Array of [specification, dep] that are satisfied by +spec+. - def find_reverse_dependencies spec # :nodoc: + def find_reverse_dependencies(spec) # :nodoc: result = [] Gem::Specification.each do |sp| @@ -194,7 +194,7 @@ use with other commands. dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep if spec.name == dep.name and - dep.requirement.satisfied_by?(spec.version) then + dep.requirement.satisfied_by?(spec.version) result << [sp.full_name, dep] end end @@ -205,10 +205,10 @@ use with other commands. private - def name_pattern args + def name_pattern(args) args << '' if args.empty? - if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m then + if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m flags = $2 ? Regexp::IGNORECASE : nil Regexp.new $1, flags else diff --git a/lib/rubygems/commands/environment_command.rb b/lib/rubygems/commands/environment_command.rb index 29c9d4d38f..11fb45f68d 100644 --- a/lib/rubygems/commands/environment_command.rb +++ b/lib/rubygems/commands/environment_command.rb @@ -97,7 +97,7 @@ lib/rubygems/defaults/operating_system.rb true end - def add_path out, path + def add_path(out, path) path.each do |component| out << " - #{component}\n" end diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb index 19559a7774..66562d7fb7 100644 --- a/lib/rubygems/commands/fetch_command.rb +++ b/lib/rubygems/commands/fetch_command.rb @@ -56,14 +56,14 @@ then repackaging it. specs_and_sources, errors = Gem::SpecFetcher.fetcher.spec_for_dependency dep - if platform then + if platform filtered = specs_and_sources.select { |s,| s.platform == platform } specs_and_sources = filtered unless filtered.empty? end spec, source = specs_and_sources.max_by { |s,| s.version } - if spec.nil? then + if spec.nil? show_lookup_failure gem_name, version, errors, options[:domain] next end @@ -75,4 +75,3 @@ then repackaging it. end end - diff --git a/lib/rubygems/commands/generate_index_command.rb b/lib/rubygems/commands/generate_index_command.rb index 0b677b73a9..941637ea9c 100644 --- a/lib/rubygems/commands/generate_index_command.rb +++ b/lib/rubygems/commands/generate_index_command.rb @@ -67,13 +67,13 @@ Marshal::MINOR_VERSION constants. It is used to ensure compatibility. options[:build_modern] = true if not File.exist?(options[:directory]) or - not File.directory?(options[:directory]) then + not File.directory?(options[:directory]) alert_error "unknown directory name #{options[:directory]}." terminate_interaction 1 else indexer = Gem::Indexer.new options.delete(:directory), options - if options[:update] then + if options[:update] indexer.update_index else indexer.generate_index @@ -82,4 +82,3 @@ Marshal::MINOR_VERSION constants. It is used to ensure compatibility. end end - diff --git a/lib/rubygems/commands/help_command.rb b/lib/rubygems/commands/help_command.rb index 0c96963fac..9f14e22f90 100644 --- a/lib/rubygems/commands/help_command.rb +++ b/lib/rubygems/commands/help_command.rb @@ -297,8 +297,8 @@ platform. begins? command, arg end - if help then - if Symbol === help then + if help + if Symbol === help send help else say help @@ -306,10 +306,10 @@ platform. return end - if options[:help] then + if options[:help] show_help - elsif arg then + elsif arg show_command_help arg else @@ -334,7 +334,7 @@ platform. command = @command_manager[cmd_name] summary = - if command then + if command command.summary else "[No command found for #{cmd_name}]" @@ -356,15 +356,15 @@ platform. say out.join("\n") end - def show_command_help command_name # :nodoc: + def show_command_help(command_name) # :nodoc: command_name = command_name.downcase possibilities = @command_manager.find_command_possibilities command_name - if possibilities.size == 1 then + if possibilities.size == 1 command = @command_manager[possibilities.first] command.invoke("--help") - elsif possibilities.size > 1 then + elsif possibilities.size > 1 alert_warning "Ambiguous command #{command_name} (#{possibilities.join(', ')})" else alert_warning "Unknown command #{command_name}. Try: gem help commands" @@ -372,4 +372,3 @@ platform. end end - diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index 9fe131c290..fca14681ee 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -132,7 +132,7 @@ You can use `i` command instead of `install`. end def check_install_dir # :nodoc: - if options[:install_dir] and options[:user_install] then + if options[:install_dir] and options[:user_install] alert_error "Use --install-dir or --user-install but not both" terminate_interaction 1 end @@ -140,7 +140,7 @@ You can use `i` command instead of `install`. def check_version # :nodoc: if options[:version] != Gem::Requirement.default and - get_all_gem_names.size > 1 then + get_all_gem_names.size > 1 alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ " version requirments using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" terminate_interaction 1 @@ -148,8 +148,7 @@ You can use `i` command instead of `install`. end def execute - - if options.include? :gemdeps then + if options.include? :gemdeps install_from_gemdeps return # not reached end @@ -189,13 +188,13 @@ You can use `i` command instead of `install`. terminate_interaction end - def install_gem name, version # :nodoc: + def install_gem(name, version) # :nodoc: return if options[:conservative] and not Gem::Dependency.new(name, version).matching_specs.empty? req = Gem::Requirement.create(version) - if options[:ignore_dependencies] then + if options[:ignore_dependencies] install_gem_without_dependencies name, req else inst = Gem::DependencyInstaller.new options @@ -217,11 +216,11 @@ You can use `i` command instead of `install`. end end - def install_gem_without_dependencies name, req # :nodoc: + def install_gem_without_dependencies(name, req) # :nodoc: gem = nil - if local? then - if name =~ /\.gem$/ and File.file? name then + if local? + if name =~ /\.gem$/ and File.file? name source = Gem::Source::SpecificFile.new name spec = source.spec else @@ -231,7 +230,7 @@ You can use `i` command instead of `install`. gem = source.download spec if spec end - if remote? and not gem then + if remote? and not gem dependency = Gem::Dependency.new name, req dependency.prerelease = options[:prerelease] @@ -293,7 +292,7 @@ You can use `i` command instead of `install`. require 'rubygems/rdoc' end - def show_install_errors errors # :nodoc: + def show_install_errors(errors) # :nodoc: return unless errors errors.each do |x| diff --git a/lib/rubygems/commands/list_command.rb b/lib/rubygems/commands/list_command.rb index 1acb49e5fb..cd21543537 100644 --- a/lib/rubygems/commands/list_command.rb +++ b/lib/rubygems/commands/list_command.rb @@ -38,4 +38,3 @@ To search for remote gems use the search command. end end - diff --git a/lib/rubygems/commands/lock_command.rb b/lib/rubygems/commands/lock_command.rb index 3eebfadc05..7f02e9feda 100644 --- a/lib/rubygems/commands/lock_command.rb +++ b/lib/rubygems/commands/lock_command.rb @@ -59,7 +59,7 @@ lock it down to the exact version. end def complain(message) - if options[:strict] then + if options[:strict] raise Gem::Exception, message else say "# #{message}" @@ -78,7 +78,7 @@ lock it down to the exact version. spec = Gem::Specification.load spec_path(full_name) - if spec.nil? then + if spec.nil? complain "Could not find gem #{full_name}, try using the full name" next end @@ -90,7 +90,7 @@ lock it down to the exact version. next if locked[dep.name] candidates = dep.matching_specs - if candidates.empty? then + if candidates.empty? complain "Unable to satisfy '#{dep}' from currently installed gems" else pending << candidates.last.full_name @@ -108,4 +108,3 @@ lock it down to the exact version. end end - diff --git a/lib/rubygems/commands/open_command.rb b/lib/rubygems/commands/open_command.rb index fdac19dc1f..2794fe05e6 100644 --- a/lib/rubygems/commands/open_command.rb +++ b/lib/rubygems/commands/open_command.rb @@ -11,9 +11,9 @@ class Gem::Commands::OpenCommand < Gem::Command def initialize super 'open', 'Open gem sources in editor' - add_option('-e', '--editor EDITOR', String, - "Opens gem sources in EDITOR") do |editor, options| - options[:editor] = editor || get_env_editor + add_option('-e', '--editor COMMAND', String, + "Prepends COMMAND to gem path. Could be used to specify editor.") do |command, options| + options[:editor] = command || get_env_editor end add_option('-v', '--version VERSION', String, "Opens specific gem version") do |version| @@ -32,14 +32,14 @@ class Gem::Commands::OpenCommand < Gem::Command def description # :nodoc: <<-EOF The open command opens gem in editor and changes current path - to gem's source directory. Editor can be specified with -e option, - otherwise rubygems will look for editor in $EDITOR, $VISUAL and - $GEM_EDITOR variables. + to gem's source directory. + Editor command can be specified with -e option, otherwise rubygems + will look for editor in $EDITOR, $VISUAL and $GEM_EDITOR variables. EOF end def usage # :nodoc: - "#{program_name} GEMNAME [-e EDITOR]" + "#{program_name} GEMNAME [-e COMMAND]" end def get_env_editor @@ -58,7 +58,7 @@ class Gem::Commands::OpenCommand < Gem::Command terminate_interaction 1 unless found end - def open_gem name + def open_gem(name) spec = spec_for name return false unless spec @@ -71,13 +71,13 @@ class Gem::Commands::OpenCommand < Gem::Command open_editor(spec.full_gem_path) end - def open_editor path + def open_editor(path) Dir.chdir(path) do system(*@editor.split(/\s+/) + [path]) end end - def spec_for name + def spec_for(name) spec = Gem::Specification.find_all_by_name(name, @version).first return spec if spec diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb index 637b5bdc4d..9cfaa241b5 100644 --- a/lib/rubygems/commands/owner_command.rb +++ b/lib/rubygems/commands/owner_command.rb @@ -58,7 +58,7 @@ permission to. show_owners name end - def show_owners name + def show_owners(name) response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request| request.add_field "Authorization", api_key end @@ -73,15 +73,15 @@ permission to. end end - def add_owners name, owners + def add_owners(name, owners) manage_owners :post, name, owners end - def remove_owners name, owners + def remove_owners(name, owners) manage_owners :delete, name, owners end - def manage_owners method, name, owners + def manage_owners(method, name, owners) owners.each do |owner| begin response = rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request| diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index 575c344130..b686d8341d 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -88,13 +88,13 @@ extensions will be restored. end def execute - specs = if options[:all] then + specs = if options[:all] Gem::Specification.map # `--extensions` must be explicitly given to pristine only gems # with extensions. elsif options[:extensions_set] and - options[:extensions] and options[:args].empty? then + options[:extensions] and options[:args].empty? Gem::Specification.select do |spec| spec.extensions and not spec.extensions.empty? end @@ -104,7 +104,7 @@ extensions will be restored. end.flatten end - if specs.to_a.empty? then + if specs.to_a.empty? raise Gem::Exception, "Failed to find gems #{options[:args]} #{options[:version]}" end @@ -134,14 +134,14 @@ extensions will be restored. next end - unless spec.extensions.empty? or options[:extensions] or options[:only_executables] then + unless spec.extensions.empty? or options[:extensions] or options[:only_executables] say "Skipped #{spec.full_name}, it needs to compile an extension" next end gem = spec.cache_file - unless File.exist? gem or options[:only_executables] then + unless File.exist? gem or options[:only_executables] require 'rubygems/remote_fetcher' say "Cached gem for #{spec.full_name} not found, attempting to fetch..." @@ -159,7 +159,7 @@ extensions will be restored. end env_shebang = - if options.include? :env_shebang then + if options.include? :env_shebang options[:env_shebang] else install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install'] @@ -177,7 +177,7 @@ extensions will be restored. :bin_dir => bin_dir } - if options[:only_executables] then + if options[:only_executables] installer = Gem::Installer.for_spec(spec, installer_options) installer.generate_bin else diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 83c7131afc..20812368c4 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -79,7 +79,7 @@ command. For further discussion see the help for the yank command. if latest_rubygems_version < Gem.rubygems_version and Gem.rubygems_version.prerelease? and - Gem::Version.new('2.0.0.rc.2') != Gem.rubygems_version then + Gem::Version.new('2.0.0.rc.2') != Gem.rubygems_version alert_error <<-ERROR You are using a beta release of RubyGems (#{Gem::VERSION}) which is not allowed to push gems. Please downgrade or upgrade to a release version. @@ -96,7 +96,7 @@ You can upgrade or downgrade to the latest release version with: gem_data = Gem::Package.new(name) - unless @host then + unless @host @host = gem_data.spec.metadata['default_gem_server'] end @@ -134,4 +134,3 @@ You can upgrade or downgrade to the latest release version with: ] end end - diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index 4624e5a1e9..d947d588ef 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -91,8 +91,8 @@ is too hard to use. prerelease = options[:prerelease] - unless options[:installed].nil? then - if no_name then + unless options[:installed].nil? + if no_name alert_error "You must specify a gem name" exit_code |= 4 elsif name.count > 1 @@ -102,7 +102,7 @@ is too hard to use. installed = installed? name.first, options[:version] installed = !installed unless options[:installed] - if installed then + if installed say "true" else say "false" @@ -119,8 +119,8 @@ is too hard to use. private - def display_header type - if (ui.outs.tty? and Gem.configuration.verbose) or both? then + def display_header(type) + if (ui.outs.tty? and Gem.configuration.verbose) or both? say say "*** #{type} GEMS ***" say @@ -128,14 +128,14 @@ is too hard to use. end #Guts of original execute - def show_gems name, prerelease + def show_gems(name, prerelease) req = Gem::Requirement.default # TODO: deprecate for real dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req } dep.prerelease = prerelease - if local? then - if prerelease and not both? then + if local? + if prerelease and not both? alert_warning "prereleases are always shown locally" end @@ -152,7 +152,7 @@ is too hard to use. output_query_results spec_tuples end - if remote? then + if remote? display_header 'REMOTE' fetcher = Gem::SpecFetcher.fetcher @@ -205,7 +205,7 @@ is too hard to use. say output.join(options[:details] ? "\n\n" : "\n") end - def output_versions output, versions + def output_versions(output, versions) versions.each do |gem_name, matching_tuples| matching_tuples = matching_tuples.sort_by { |n,_| n.version }.reverse @@ -218,7 +218,7 @@ is too hard to use. seen = {} matching_tuples.delete_if do |n,_| - if seen[n.version] then + if seen[n.version] true else seen[n.version] = true @@ -230,7 +230,7 @@ is too hard to use. end end - def entry_details entry, detail_tuple, specs, platforms + def entry_details(entry, detail_tuple, specs, platforms) return unless options[:details] name_tuple, spec = detail_tuple @@ -247,11 +247,11 @@ is too hard to use. spec_summary entry, spec end - def entry_versions entry, name_tuples, platforms, specs + def entry_versions(entry, name_tuples, platforms, specs) return unless options[:versions] list = - if platforms.empty? or options[:details] then + if platforms.empty? or options[:details] name_tuples.map { |n| n.version }.uniq else platforms.sort.reverse.map do |version, pls| @@ -264,7 +264,7 @@ is too hard to use. out = "default: #{out}" if default end - if pls != [Gem::Platform::RUBY] then + if pls != [Gem::Platform::RUBY] platform_list = [pls.delete(Gem::Platform::RUBY), *pls.sort].compact out = platform_list.unshift(out).join(' ') end @@ -276,7 +276,7 @@ is too hard to use. entry << " (#{list.join ', '})" end - def make_entry entry_tuples, platforms + def make_entry(entry_tuples, platforms) detail_tuple = entry_tuples.first name_tuples, specs = entry_tuples.flatten.partition do |item| @@ -291,19 +291,19 @@ is too hard to use. entry.join end - def spec_authors entry, spec + def spec_authors(entry, spec) authors = "Author#{spec.authors.length > 1 ? 's' : ''}: ".dup authors << spec.authors.join(', ') entry << format_text(authors, 68, 4) end - def spec_homepage entry, spec + def spec_homepage(entry, spec) return if spec.homepage.nil? or spec.homepage.empty? entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4) end - def spec_license entry, spec + def spec_license(entry, spec) return if spec.license.nil? or spec.license.empty? licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: ".dup @@ -311,10 +311,10 @@ is too hard to use. entry << "\n" << format_text(licenses, 68, 4) end - def spec_loaded_from entry, spec, specs + def spec_loaded_from(entry, spec, specs) return unless spec.loaded_from - if specs.length == 1 then + if specs.length == 1 default = spec.default_gem? ? ' (default)' : nil entry << "\n" << " Installed at#{default}: #{spec.base_dir}" else @@ -328,14 +328,14 @@ is too hard to use. end end - def spec_platforms entry, platforms + def spec_platforms(entry, platforms) non_ruby = platforms.any? do |_, pls| pls.any? { |pl| pl != Gem::Platform::RUBY } end return unless non_ruby - if platforms.length == 1 then + if platforms.length == 1 title = platforms.values.length == 1 ? 'Platform' : 'Platforms' entry << " #{title}: #{platforms.values.sort.join ', '}\n" else @@ -351,7 +351,7 @@ is too hard to use. end end - def spec_summary entry, spec + def spec_summary(entry, spec) summary = truncate_text(spec.summary, "the summary for #{spec.full_name}") entry << "\n\n" << format_text(summary, 68, 4) end diff --git a/lib/rubygems/commands/rdoc_command.rb b/lib/rubygems/commands/rdoc_command.rb index 6992040dca..5f8b72eb7a 100644 --- a/lib/rubygems/commands/rdoc_command.rb +++ b/lib/rubygems/commands/rdoc_command.rb @@ -60,7 +60,7 @@ Use --overwrite to force rebuilding of documentation. end def execute - specs = if options[:all] then + specs = if options[:all] Gem::Specification.to_a else get_all_gem_names.map do |name| @@ -68,7 +68,7 @@ Use --overwrite to force rebuilding of documentation. end.flatten.uniq end - if specs.empty? then + if specs.empty? alert_error 'No matching gems found' terminate_interaction 1 end @@ -78,7 +78,7 @@ Use --overwrite to force rebuilding of documentation. doc.force = options[:overwrite] - if options[:overwrite] then + if options[:overwrite] FileUtils.rm_rf File.join(spec.doc_dir, 'ri') FileUtils.rm_rf File.join(spec.doc_dir, 'rdoc') end @@ -94,4 +94,3 @@ Use --overwrite to force rebuilding of documentation. end end - diff --git a/lib/rubygems/commands/search_command.rb b/lib/rubygems/commands/search_command.rb index 933436d84d..c9cb1f2d43 100644 --- a/lib/rubygems/commands/search_command.rb +++ b/lib/rubygems/commands/search_command.rb @@ -38,4 +38,3 @@ To list local gems use the list command. end end - diff --git a/lib/rubygems/commands/server_command.rb b/lib/rubygems/commands/server_command.rb index 245156d50d..e91a8e5176 100644 --- a/lib/rubygems/commands/server_command.rb +++ b/lib/rubygems/commands/server_command.rb @@ -9,7 +9,7 @@ class Gem::Commands::ServerCommand < Gem::Command :port => 8808, :gemdir => [], :daemon => false OptionParser.accept :Port do |port| - if port =~ /\A\d+\z/ then + if port =~ /\A\d+\z/ port = Integer port raise OptionParser::InvalidArgument, "#{port}: not a port number" if port > 65535 @@ -84,4 +84,3 @@ You can set up a shortcut to gem server documentation using the URL: end end - diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 37abe3b2ec..7992818863 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -6,8 +6,8 @@ require 'rubygems/command' # RubyGems checkout or tarball. class Gem::Commands::SetupCommand < Gem::Command - HISTORY_HEADER = /^===\s*[\d.a-zA-Z]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ - VERSION_MATCHER = /^===\s*([\d.a-zA-Z]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ + HISTORY_HEADER = /^===\s*[\d.a-zA-Z]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/.freeze + VERSION_MATCHER = /^===\s*([\d.a-zA-Z]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/.freeze ENV_PATHS = %w[/usr/bin/env /bin/env].freeze @@ -62,7 +62,7 @@ class Gem::Commands::SetupCommand < Gem::Command add_option '--[no-]rdoc', 'Generate RDoc documentation for RubyGems' do |value, options| - if value then + if value options[:document] << 'rdoc' else options[:document].delete 'rdoc' @@ -73,7 +73,7 @@ class Gem::Commands::SetupCommand < Gem::Command add_option '--[no-]ri', 'Generate RI documentation for RubyGems' do |value, options| - if value then + if value options[:document] << 'ri' else options[:document].delete 'ri' @@ -99,7 +99,7 @@ class Gem::Commands::SetupCommand < Gem::Command def check_ruby_version required_version = Gem::Requirement.new '>= 1.8.7' - unless required_version.satisfied_by? Gem.ruby_version then + unless required_version.satisfied_by? Gem.ruby_version alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}" terminate_interaction 1 end @@ -139,7 +139,7 @@ By default, this RubyGems will install gem as: install_destdir = options[:destdir] - unless install_destdir.empty? then + unless install_destdir.empty? ENV['GEM_HOME'] ||= File.join(install_destdir, Gem.default_dir.gsub(/^[a-zA-Z]:/, '')) end @@ -147,7 +147,7 @@ By default, this RubyGems will install gem as: check_ruby_version require 'fileutils' - if Gem.configuration.really_verbose then + if Gem.configuration.really_verbose extend FileUtils::Verbose else extend FileUtils @@ -180,7 +180,7 @@ By default, this RubyGems will install gem as: documentation_success = install_rdoc say - if @verbose then + if @verbose say "-" * 78 say end @@ -201,14 +201,14 @@ By default, this RubyGems will install gem as: say @bin_file_names.map { |name| "\t#{name}\n" } say - unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) then + unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) say "If `gem` was installed by a previous RubyGems installation, you may need" say "to remove it by hand." say end if documentation_success - if options[:document].include? 'rdoc' then + if options[:document].include? 'rdoc' say "Rdoc documentation was installed. You may now invoke:" say " gem server" say "and then peruse beautifully formatted documentation for your gems" @@ -219,7 +219,7 @@ By default, this RubyGems will install gem as: say end - if options[:document].include? 'ri' then + if options[:document].include? 'ri' say "Ruby Interactive (ri) documentation was installed. ri is kind of like man " say "pages for Ruby libraries. You may access it like this:" say " ri Classname" @@ -250,7 +250,7 @@ By default, this RubyGems will install gem as: bin_files -= %w[update_rubygems bundler bundle_ruby] bin_files.each do |bin_file| - bin_file_formatted = if options[:format_executable] then + bin_file_formatted = if options[:format_executable] Gem.default_exec_format % bin_file else bin_file @@ -308,7 +308,7 @@ By default, this RubyGems will install gem as: end end - def install_file file, dest_dir + def install_file(file, dest_dir) dest_file = File.join dest_dir, file dest_dir = File.dirname dest_file unless File.directory? dest_dir @@ -354,7 +354,7 @@ By default, this RubyGems will install gem as: if File.writable? gem_doc_dir and (not File.exist? rubygems_doc_dir or - File.writable? rubygems_doc_dir) then + File.writable? rubygems_doc_dir) say "Removing old RubyGems RDoc and ri" if @verbose Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir| rm_rf dir @@ -374,7 +374,7 @@ By default, this RubyGems will install gem as: rdoc.generate return true - elsif @verbose then + elsif @verbose say "Skipping RDoc generation, #{gem_doc_dir} not writable" say "Set the GEM_HOME environment variable if you want RDoc generated" end @@ -456,7 +456,7 @@ By default, this RubyGems will install gem as: prefix = options[:prefix] site_or_vendor = options[:site_or_vendor] - if prefix.empty? then + if prefix.empty? lib_dir = RbConfig::CONFIG[site_or_vendor] bin_dir = RbConfig::CONFIG['bindir'] else @@ -467,7 +467,7 @@ By default, this RubyGems will install gem as: # just in case Apple and RubyGems don't get this patched up proper. (prefix == RbConfig::CONFIG['libdir'] or # this one is important - prefix == File.join(RbConfig::CONFIG['libdir'], 'ruby')) then + prefix == File.join(RbConfig::CONFIG['libdir'], 'ruby')) lib_dir = RbConfig::CONFIG[site_or_vendor] bin_dir = RbConfig::CONFIG['bindir'] else @@ -476,7 +476,7 @@ By default, this RubyGems will install gem as: end end - unless install_destdir.empty? then + unless install_destdir.empty? lib_dir = File.join install_destdir, lib_dir.gsub(/^[a-zA-Z]:/, '') bin_dir = File.join install_destdir, bin_dir.gsub(/^[a-zA-Z]:/, '') end @@ -484,13 +484,13 @@ By default, this RubyGems will install gem as: [lib_dir, bin_dir] end - def pem_files_in dir + def pem_files_in(dir) Dir.chdir dir do Dir[File.join('**', '*pem')] end end - def rb_files_in dir + def rb_files_in(dir) Dir.chdir dir do Dir[File.join('**', '*rb')] end @@ -505,7 +505,7 @@ By default, this RubyGems will install gem as: end # for cleanup old bundler files - def template_files_in dir + def template_files_in(dir) Dir.chdir dir do (Dir[File.join('templates', '**', '{*,.*}')]). select{|f| !File.directory?(f)} @@ -544,7 +544,7 @@ abort "#{deprecation_message}" end end - def remove_old_lib_files lib_dir + def remove_old_lib_files(lib_dir) lib_dirs = { File.join(lib_dir, 'rubygems') => 'lib/rubygems' } lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler' if Gem::USE_BUNDLER_FOR_GEMDEPS lib_dirs.each do |old_lib_dir, new_lib_dir| @@ -575,7 +575,7 @@ abort "#{deprecation_message}" release_notes = File.join Dir.pwd, 'History.txt' release_notes = - if File.exist? release_notes then + if File.exist? release_notes history = File.read release_notes history.force_encoding Encoding::UTF_8 diff --git a/lib/rubygems/commands/signin_command.rb b/lib/rubygems/commands/signin_command.rb index a48c32b52e..64b187f26f 100644 --- a/lib/rubygems/commands/signin_command.rb +++ b/lib/rubygems/commands/signin_command.rb @@ -12,7 +12,6 @@ class Gem::Commands::SigninCommand < Gem::Command add_option('--host HOST', 'Push to another gemcutter-compatible host') do |value, options| options[:host] = value end - end def description # :nodoc: diff --git a/lib/rubygems/commands/signout_command.rb b/lib/rubygems/commands/signout_command.rb index 2452e8cae1..2d7329c590 100644 --- a/lib/rubygems/commands/signout_command.rb +++ b/lib/rubygems/commands/signout_command.rb @@ -19,9 +19,9 @@ class Gem::Commands::SignoutCommand < Gem::Command def execute credentials_path = Gem.configuration.credentials_path - if !File.exist?(credentials_path) then + if !File.exist?(credentials_path) alert_error 'You are not currently signed in.' - elsif !File.writable?(credentials_path) then + elsif !File.writable?(credentials_path) alert_error "File '#{Gem.configuration.credentials_path}' is read-only."\ ' Please make sure it is writable.' else diff --git a/lib/rubygems/commands/sources_command.rb b/lib/rubygems/commands/sources_command.rb index 7e46963a4c..af145fd7b4 100644 --- a/lib/rubygems/commands/sources_command.rb +++ b/lib/rubygems/commands/sources_command.rb @@ -38,13 +38,13 @@ class Gem::Commands::SourcesCommand < Gem::Command add_proxy_option end - def add_source source_uri # :nodoc: + def add_source(source_uri) # :nodoc: check_rubygems_https source_uri source = Gem::Source.new source_uri begin - if Gem.sources.include? source then + if Gem.sources.include? source say "source #{source_uri} already present in the cache" else source.load_specs :released @@ -62,11 +62,11 @@ class Gem::Commands::SourcesCommand < Gem::Command end end - def check_rubygems_https source_uri # :nodoc: + def check_rubygems_https(source_uri) # :nodoc: uri = URI source_uri if uri.scheme and uri.scheme.downcase == 'http' and - uri.host.downcase == 'rubygems.org' then + uri.host.downcase == 'rubygems.org' question = <<-QUESTION.chomp https://rubygems.org is recommended for security over #{uri} @@ -81,10 +81,10 @@ Do you want to add this insecure source? path = Gem.spec_cache_dir FileUtils.rm_rf path - unless File.exist? path then + unless File.exist? path say "*** Removed specs cache ***" else - unless File.writable? path then + unless File.writable? path say "*** Unable to remove source cache (write protected) ***" else say "*** Unable to remove source cache ***" @@ -175,8 +175,8 @@ To remove a source use the --remove argument: list if list? end - def remove_source source_uri # :nodoc: - unless Gem.sources.include? source_uri then + def remove_source(source_uri) # :nodoc: + unless Gem.sources.include? source_uri say "source #{source_uri} not present in cache" else Gem.sources.delete source_uri @@ -195,12 +195,12 @@ To remove a source use the --remove argument: say "source cache successfully updated" end - def remove_cache_file desc, path # :nodoc: + def remove_cache_file(desc, path) # :nodoc: FileUtils.rm_rf path - if not File.exist?(path) then + if not File.exist?(path) say "*** Removed #{desc} source cache ***" - elsif not File.writable?(path) then + elsif not File.writable?(path) say "*** Unable to remove #{desc} source cache (write protected) ***" else say "*** Unable to remove #{desc} source cache ***" @@ -208,4 +208,3 @@ To remove a source use the --remove argument: end end - diff --git a/lib/rubygems/commands/specification_command.rb b/lib/rubygems/commands/specification_command.rb index ad8840adc2..56b9371686 100644 --- a/lib/rubygems/commands/specification_command.rb +++ b/lib/rubygems/commands/specification_command.rb @@ -75,7 +75,7 @@ Specific fields in the specification can be extracted in YAML format: specs = [] gem = options[:args].shift - unless gem then + unless gem raise Gem::CommandLineError, "Please specify a gem name or file on the command line" end @@ -105,29 +105,29 @@ Specific fields in the specification can be extracted in YAML format: raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive" if field and options[:format] == :ruby - if local? then - if File.exist? gem then + if local? + if File.exist? gem specs << Gem::Package.new(gem).spec rescue nil end - if specs.empty? then + if specs.empty? specs.push(*dep.matching_specs) end end - if remote? then + if remote? dep.prerelease = options[:prerelease] found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep specs.push(*found.map { |spec,| spec }) end - if specs.empty? then + if specs.empty? alert_error "No gem matching '#{dep}' found" terminate_interaction 1 end - unless options[:all] then + unless options[:all] specs = [specs.max_by { |s| s.version }] end diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index d1ffe675fe..3f975ce3bc 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -81,7 +81,7 @@ class Gem::Commands::UninstallCommand < Gem::Command add_option('--vendor', 'Uninstall gem from the vendor directory.', 'Only for use by gem repackagers.') do |value, options| - unless Gem.vendor_dir then + unless Gem.vendor_dir raise OptionParser::InvalidOption.new 'your platform is not supported' end @@ -115,9 +115,9 @@ that is a dependency of an existing gem. You can use the end def execute - if options[:all] and not options[:args].empty? then + if options[:all] and not options[:args].empty? uninstall_specific - elsif options[:all] then + elsif options[:all] uninstall_all else uninstall_specific diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index b2edf7d349..4a1bd8a0d6 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -79,15 +79,15 @@ command help for an example. dependency = Gem::Dependency.new name, options[:version] path = get_path dependency - unless path then + unless path alert_error "Gem '#{name}' not installed nor fetchable." next end - if @options[:spec] then + if @options[:spec] spec, metadata = get_metadata path, security_policy - if metadata.nil? then + if metadata.nil? alert_error "--spec is unsupported on '#{name}' (old format gem)" next end @@ -152,7 +152,7 @@ command help for an example. # TODO: It just uses Gem.dir for now. What's an easy way to get the list of # source directories? - def get_path dependency + def get_path(dependency) return dependency.name if dependency.name =~ /\.gem$/i specs = dependency.matching_specs @@ -180,7 +180,7 @@ command help for an example. #-- # TODO move to Gem::Package as #raw_spec or something - def get_metadata path, security_policy = nil + def get_metadata(path, security_policy = nil) format = Gem::Package.new path, security_policy spec = format.spec @@ -202,4 +202,3 @@ command help for an example. end end - diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index dc924265b0..9ab3b80e96 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -68,8 +68,8 @@ command to remove old versions. "#{program_name} GEMNAME [GEMNAME ...]" end - def check_latest_rubygems version # :nodoc: - if Gem.rubygems_version == version then + def check_latest_rubygems(version) # :nodoc: + if Gem.rubygems_version == version say "Latest version already installed. Done." terminate_interaction end @@ -78,14 +78,14 @@ command to remove old versions. end def check_update_arguments # :nodoc: - unless options[:args].empty? then + unless options[:args].empty? alert_error "Gem names are not allowed with the --system option" terminate_interaction 1 end end def execute - if options[:system] then + if options[:system] update_rubygems return end @@ -111,7 +111,7 @@ command to remove old versions. updated_names = updated.map { |spec| spec.name } not_updated_names = options[:args].uniq - updated_names - if updated.empty? then + if updated.empty? say "Nothing to update" else say "Gems updated: #{updated_names.join(' ')}" @@ -119,7 +119,7 @@ command to remove old versions. end end - def fetch_remote_gems spec # :nodoc: + def fetch_remote_gems(spec) # :nodoc: dependency = Gem::Dependency.new spec.name, "> #{spec.version}" dependency.prerelease = options[:prerelease] @@ -138,7 +138,7 @@ command to remove old versions. hig = {} # highest installed gems Gem::Specification.each do |spec| - if hig[spec.name].nil? or hig[spec.name].version < spec.version then + if hig[spec.name].nil? or hig[spec.name].version < spec.version hig[spec.name] = spec end end @@ -146,7 +146,7 @@ command to remove old versions. hig end - def highest_remote_version spec # :nodoc: + def highest_remote_version(spec) # :nodoc: spec_tuples = fetch_remote_gems spec matching_gems = spec_tuples.select do |g,_| @@ -160,7 +160,7 @@ command to remove old versions. highest_remote_gem.first.version end - def install_rubygems version # :nodoc: + def install_rubygems(version) # :nodoc: args = update_rubygems_arguments update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}" @@ -177,7 +177,7 @@ command to remove old versions. version = options[:system] update_latest = version == true - if update_latest then + if update_latest version = Gem::Version.new Gem::VERSION requirement = Gem::Requirement.new ">= #{Gem::VERSION}" else @@ -196,7 +196,7 @@ command to remove old versions. gems_to_update = which_to_update hig, options[:args], :system _, up_ver = gems_to_update.first - target = if update_latest then + target = if update_latest up_ver else version @@ -205,7 +205,7 @@ command to remove old versions. return target, requirement end - def update_gem name, version = Gem::Requirement.default + def update_gem(name, version = Gem::Requirement.default) return if @updated.any? { |spec| spec.name == name } update_options = options.dup @@ -225,7 +225,7 @@ command to remove old versions. end end - def update_gems gems_to_update + def update_gems(gems_to_update) gems_to_update.uniq.sort.each do |(name, version)| update_gem name, version end @@ -264,7 +264,7 @@ command to remove old versions. args end - def which_to_update highest_installed_gems, gem_names, system = false + def which_to_update(highest_installed_gems, gem_names, system = false) result = [] highest_installed_gems.each do |l_name, l_spec| @@ -273,7 +273,7 @@ command to remove old versions. highest_remote_ver = highest_remote_version l_spec - if system or (l_spec.version < highest_remote_ver) then + if system or (l_spec.version < highest_remote_ver) result << [l_spec.name, [l_spec.version, highest_remote_ver].max] end end diff --git a/lib/rubygems/commands/which_command.rb b/lib/rubygems/commands/which_command.rb index 704d79fc60..5c51ed72dd 100644 --- a/lib/rubygems/commands/which_command.rb +++ b/lib/rubygems/commands/which_command.rb @@ -44,8 +44,8 @@ requiring to see why it does not behave as you expect. spec = Gem::Specification.find_by_path arg - if spec then - if options[:search_gems_first] then + if spec + if options[:search_gems_first] dirs = spec.full_require_paths + $LOAD_PATH else dirs = $LOAD_PATH + spec.full_require_paths @@ -55,7 +55,7 @@ requiring to see why it does not behave as you expect. # TODO: this is totally redundant and stupid paths = find_paths arg, dirs - if paths.empty? then + if paths.empty? alert_error "Can't find Ruby library file or shared library #{arg}" found &&= false @@ -73,7 +73,7 @@ requiring to see why it does not behave as you expect. dirs.each do |dir| Gem.suffixes.each do |ext| full_path = File.join dir, "#{package_name}#{ext}" - if File.exist? full_path and not File.directory? full_path then + if File.exist? full_path and not File.directory? full_path result << full_path return result unless options[:show_all] end @@ -88,4 +88,3 @@ requiring to see why it does not behave as you expect. end end - diff --git a/lib/rubygems/commands/yank_command.rb b/lib/rubygems/commands/yank_command.rb index ebf24e5c77..d13b674b48 100644 --- a/lib/rubygems/commands/yank_command.rb +++ b/lib/rubygems/commands/yank_command.rb @@ -51,7 +51,7 @@ data you will need to change them immediately and yank your gem. version = get_version_from_requirements(options[:version]) platform = get_platform_from_requirements(options) - if version then + if version yank_gem(version, platform) else say "A version argument is required: #{usage}" @@ -93,4 +93,3 @@ data you will need to change them immediately and yank your gem. end end - diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index f8782015a1..e02655fc51 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -174,12 +174,12 @@ class Gem::ConfigFile arg_list = [] args.each do |arg| - if need_config_file_name then + if need_config_file_name @config_file_name = arg need_config_file_name = false - elsif arg =~ /^--config-file=(.*)/ then + elsif arg =~ /^--config-file=(.*)/ @config_file_name = $1 - elsif arg =~ /^--config-file$/ then + elsif arg =~ /^--config-file$/ need_config_file_name = true else arg_list << arg @@ -281,13 +281,13 @@ if you believe they were disclosed to a third party. def load_api_keys check_credentials_permissions - @api_keys = if File.exist? credentials_path then + @api_keys = if File.exist? credentials_path load_file(credentials_path) else @hash end - if @api_keys.key? :rubygems_api_key then + if @api_keys.key? :rubygems_api_key @rubygems_api_key = @api_keys[:rubygems_api_key] @api_keys[:rubygems] = @api_keys.delete :rubygems_api_key unless @api_keys.key? :rubygems @@ -306,7 +306,7 @@ if you believe they were disclosed to a third party. ## # Sets the RubyGems.org API key to +api_key+ - def rubygems_api_key= api_key + def rubygems_api_key=(api_key) set_api_key :rubygems_api_key, api_key @rubygems_api_key = api_key @@ -315,7 +315,7 @@ if you believe they were disclosed to a third party. ## # Set a specific host's API key to +api_key+ - def set_api_key host, api_key + def set_api_key(host, api_key) check_credentials_permissions config = load_file(credentials_path).merge(host => api_key) diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index e93cd7c728..3b78011619 100755 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -31,7 +31,7 @@ module Kernel # The normal require functionality of returning false if # that file has already been loaded is preserved. - def require path + def require(path) RUBYGEMS_ACTIVATION_MONITOR.enter path = path.to_path if path.respond_to? :to_path @@ -49,7 +49,7 @@ module Kernel # If there are no unresolved deps, then we can use just try # normal require handle loading a gem from the rescue below. - if Gem::Specification.unresolved_deps.empty? then + if Gem::Specification.unresolved_deps.empty? RUBYGEMS_ACTIVATION_MONITOR.exit return gem_original_require(path) end @@ -79,7 +79,7 @@ module Kernel # requested, then find_in_unresolved_tree will find d.rb in d because # it's a dependency of c. # - if found_specs.empty? then + if found_specs.empty? found_specs = Gem::Specification.find_in_unresolved_tree path found_specs.each do |found_spec| @@ -94,7 +94,7 @@ module Kernel # versions of the same gem names = found_specs.map(&:name).uniq - if names.size > 1 then + if names.size > 1 RUBYGEMS_ACTIVATION_MONITOR.exit raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ', '}" end @@ -103,7 +103,7 @@ module Kernel # at the highest version. valid = found_specs.find { |s| !s.has_conflicts? } - unless valid then + unless valid le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate" le.name = names.first RUBYGEMS_ACTIVATION_MONITOR.exit @@ -120,7 +120,7 @@ module Kernel begin if load_error.message.start_with?("Could not find") or - (load_error.message.end_with?(path) and Gem.try_activate(path)) then + (load_error.message.end_with?(path) and Gem.try_activate(path)) require_again = true end ensure diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 334ef4d4c1..50f46b32a2 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -28,13 +28,13 @@ module Gem # specified in the environment def self.default_dir - path = if defined? RUBY_FRAMEWORK_VERSION then + path = if defined? RUBY_FRAMEWORK_VERSION [ File.dirname(RbConfig::CONFIG['sitedir']), 'Gems', RbConfig::CONFIG['ruby_version'] ] - elsif RbConfig::CONFIG['rubylibprefix'] then + elsif RbConfig::CONFIG['rubylibprefix'] [ RbConfig::CONFIG['rubylibprefix'], 'gems', @@ -59,7 +59,7 @@ module Gem # By default, the binary extensions are located side by side with their # Ruby counterparts, therefore nil is returned - def self.default_ext_dir_for base_dir + def self.default_ext_dir_for(base_dir) nil end @@ -103,7 +103,7 @@ module Gem def self.default_exec_format exec_format = RbConfig::CONFIG['ruby_install_name'].sub('ruby', '%s') rescue '%s' - unless exec_format =~ /%s/ then + unless exec_format =~ /%s/ raise Gem::Exception, "[BUG] invalid exec_format #{exec_format.inspect}, no %s" end @@ -115,7 +115,7 @@ module Gem # The default directory for binaries def self.default_bindir - if defined? RUBY_FRAMEWORK_VERSION then # mac framework support + if defined? RUBY_FRAMEWORK_VERSION # mac framework support '/usr/bin' else # generic install RbConfig::CONFIG['bindir'] @@ -126,7 +126,7 @@ module Gem # A wrapper around RUBY_ENGINE const that may not be defined def self.ruby_engine - if defined? RUBY_ENGINE then + if defined? RUBY_ENGINE RUBY_ENGINE else 'ruby' @@ -165,7 +165,7 @@ module Gem # Directory where vendor gems are installed. def self.vendor_dir # :nodoc: - if vendor_dir = ENV['GEM_VENDOR'] then + if vendor_dir = ENV['GEM_VENDOR'] return vendor_dir.dup end diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index c06df0fa35..33ba1968d1 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -36,7 +36,7 @@ class Gem::Dependency # argument can optionally be the dependency type, which defaults to # :runtime. - def initialize name, *requirements + def initialize(name, *requirements) case name when String then # ok when Regexp then @@ -76,7 +76,7 @@ class Gem::Dependency end def inspect # :nodoc: - if prerelease? then + if prerelease? "<%s type=%p name=%p requirements=%p prerelease=ok>" % [self.class, self.type, self.name, requirement.to_s] else @@ -100,7 +100,7 @@ class Gem::Dependency @requirement.none? end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 1, 'Gem::Dependency.new(', ')' do q.pp name q.text ',' @@ -152,7 +152,7 @@ class Gem::Dependency end def to_s # :nodoc: - if type != :runtime then + if type != :runtime "#{name} (#{requirement}, #{type})" else "#{name} (#{requirement})" @@ -170,7 +170,7 @@ class Gem::Dependency @type == :runtime || !@type end - def == other # :nodoc: + def ==(other) # :nodoc: Gem::Dependency === other && self.name == other.name && self.type == other.type && @@ -180,7 +180,7 @@ class Gem::Dependency ## # Dependencies are ordered by name. - def <=> other + def <=>(other) self.name <=> other.name end @@ -190,7 +190,7 @@ class Gem::Dependency # other has only an equal version requirement that satisfies this # dependency. - def =~ other + def =~(other) unless Gem::Dependency === other return unless other.respond_to?(:name) && other.respond_to?(:version) other = Gem::Dependency.new other.name, other.version @@ -222,7 +222,7 @@ class Gem::Dependency # NOTE: Unlike #matches_spec? this method does not return true when the # version is a prerelease version unless this is a prerelease dependency. - def match? obj, version=nil, allow_prerelease=false + def match?(obj, version=nil, allow_prerelease=false) if !version name = obj.name version = obj.version @@ -249,7 +249,7 @@ class Gem::Dependency # returns true when +spec+ is a prerelease version even if this dependency # is not a prerelease dependency. - def matches_spec? spec + def matches_spec?(spec) return false unless name === spec.name return true if requirement.none? @@ -259,8 +259,8 @@ class Gem::Dependency ## # Merges the requirements of +other+ into this dependency - def merge other - unless name == other.name then + def merge(other) + unless name == other.name raise ArgumentError, "#{self} and #{other} have different names" end @@ -275,7 +275,7 @@ class Gem::Dependency self.class.new name, self_req.as_list.concat(other_req.as_list) end - def matching_specs platform_only = false + def matching_specs(platform_only = false) env_req = Gem.env_requirement(name) matches = Gem::Specification.stubs_for(name).find_all { |spec| requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version) @@ -304,7 +304,7 @@ class Gem::Dependency # TODO: check Gem.activated_spec[self.name] in case matches falls outside - if matches.empty? then + if matches.empty? specs = Gem::Specification.stubs_for name if specs.empty? diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 89ce9afe29..346208603c 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -66,7 +66,7 @@ class Gem::DependencyInstaller # :wrappers:: See Gem::Installer::new # :build_args:: See Gem::Installer::new - def initialize options = {} + def initialize(options = {}) @only_install_dir = !!options[:install_dir] @install_dir = options[:install_dir] || Gem.dir @build_root = options[:build_root] @@ -110,7 +110,7 @@ class Gem::DependencyInstaller #-- # TODO remove at RubyGems 4, no longer used - def add_found_dependencies to_do, dependency_list # :nodoc: + def add_found_dependencies(to_do, dependency_list) # :nodoc: seen = {} dependencies = Hash.new { |h, name| h[name] = Gem::Dependency.new name } @@ -164,8 +164,8 @@ class Gem::DependencyInstaller # Creates an AvailableSet to install from based on +dep_or_name+ and # +version+ - def available_set_for dep_or_name, version # :nodoc: - if String === dep_or_name then + def available_set_for(dep_or_name, version) # :nodoc: + if String === dep_or_name find_spec_by_name_and_version dep_or_name, version, @prerelease else dep = dep_or_name.dup @@ -198,7 +198,7 @@ class Gem::DependencyInstaller # sources. Gems are sorted with newer gems preferred over older gems, and # local gems preferred over remote gems. - def find_gems_with_sources dep, best_only=false # :nodoc: + def find_gems_with_sources(dep, best_only=false) # :nodoc: set = Gem::AvailableSet.new if consider_local? @@ -272,16 +272,16 @@ class Gem::DependencyInstaller # +version+. Returns an Array of specs and sources required for # installation of the gem. - def find_spec_by_name_and_version gem_name, + def find_spec_by_name_and_version(gem_name, version = Gem::Requirement.default, - prerelease = false + prerelease = false) set = Gem::AvailableSet.new if consider_local? - if gem_name =~ /\.gem$/ and File.file? gem_name then + if gem_name =~ /\.gem$/ and File.file? gem_name src = Gem::Source::SpecificFile.new(gem_name) set.add src.spec, src - elsif gem_name =~ /\.gem$/ then + elsif gem_name =~ /\.gem$/ Dir[gem_name].each do |name| begin src = Gem::Source::SpecificFile.new name @@ -341,7 +341,7 @@ class Gem::DependencyInstaller Gem::Specification.include?(spec) } - unless dependency_list.ok? or @ignore_dependencies or @force then + unless dependency_list.ok? or @ignore_dependencies or @force reason = dependency_list.why_not_ok?.map { |k,v| "#{k} requires #{v.join(", ")}" }.join("; ") @@ -352,7 +352,7 @@ class Gem::DependencyInstaller end deprecate :gather_dependencies, :none, 2018, 12 - def in_background what # :nodoc: + def in_background(what) # :nodoc: fork_happened = false if @build_docs_in_background and Process.respond_to?(:fork) begin @@ -381,7 +381,7 @@ class Gem::DependencyInstaller # c-1.a, b-1 and a-1.a will be installed. b-1.a will need to be installed # separately. - def install dep_or_name, version = Gem::Requirement.default + def install(dep_or_name, version = Gem::Requirement.default) request_set = resolve_dependencies dep_or_name, version @installed_gems = [] @@ -425,16 +425,16 @@ class Gem::DependencyInstaller end def install_development_deps # :nodoc: - if @development and @dev_shallow then + if @development and @dev_shallow :shallow - elsif @development then + elsif @development :all else :none end end - def resolve_dependencies dep_or_name, version # :nodoc: + def resolve_dependencies(dep_or_name, version) # :nodoc: request_set = Gem::RequestSet.new request_set.development = @development request_set.development_shallow = @dev_shallow @@ -446,11 +446,11 @@ class Gem::DependencyInstaller installer_set.ignore_installed = @only_install_dir if consider_local? - if dep_or_name =~ /\.gem$/ and File.file? dep_or_name then + if dep_or_name =~ /\.gem$/ and File.file? dep_or_name src = Gem::Source::SpecificFile.new dep_or_name installer_set.add_local dep_or_name, src.spec, src version = src.spec.version if version == Gem::Requirement.default - elsif dep_or_name =~ /\.gem$/ then + elsif dep_or_name =~ /\.gem$/ Dir[dep_or_name].each do |name| begin src = Gem::Source::SpecificFile.new name @@ -463,9 +463,9 @@ class Gem::DependencyInstaller end dependency = - if spec = installer_set.local?(dep_or_name) then + if spec = installer_set.local?(dep_or_name) Gem::Dependency.new spec.name, version - elsif String === dep_or_name then + elsif String === dep_or_name Gem::Dependency.new dep_or_name, version else dep_or_name @@ -479,7 +479,7 @@ class Gem::DependencyInstaller request_set.always_install = installer_set.always_install - if @ignore_dependencies then + if @ignore_dependencies installer_set.ignore_dependencies = true request_set.ignore_dependencies = true request_set.soft_missing = true diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb index d8314eaf60..ee2e4c7343 100644 --- a/lib/rubygems/dependency_list.rb +++ b/lib/rubygems/dependency_list.rb @@ -40,7 +40,7 @@ class Gem::DependencyList # Creates a new DependencyList. If +development+ is true, development # dependencies will be included. - def initialize development = false + def initialize(development = false) @specs = [] @development = development @@ -79,8 +79,8 @@ class Gem::DependencyList seen = {} sorted.each do |spec| - if index = seen[spec.name] then - if result[index].version < spec.version then + if index = seen[spec.name] + if result[index].version < spec.version result[index] = spec end else @@ -114,7 +114,7 @@ class Gem::DependencyList why_not_ok?(:quick).empty? end - def why_not_ok? quick = false + def why_not_ok?(quick = false) unsatisfied = Hash.new { |h,k| h[k] = [] } each do |spec| spec.runtime_dependencies.each do |dep| @@ -123,7 +123,7 @@ class Gem::DependencyList dep.requirement.satisfied_by? installed_spec.version } - unless inst or @specs.find { |s| s.satisfies_requirement? dep } then + unless inst or @specs.find { |s| s.satisfies_requirement? dep } unsatisfied[spec.name] << dep return unsatisfied if quick end @@ -172,7 +172,7 @@ class Gem::DependencyList # satisfy items in +dependencies+ (a hash of gem names to arrays of # dependencies). - def remove_specs_unsatisfied_by dependencies + def remove_specs_unsatisfied_by(dependencies) specs.reject! { |spec| dep = dependencies[spec.name] dep and not dep.requirement.satisfied_by? spec.version @@ -200,7 +200,7 @@ class Gem::DependencyList next if spec == other other.dependencies.each do |dep| - if spec.satisfies_requirement? dep then + if spec.satisfies_requirement? dep result[spec] << other end end @@ -222,7 +222,7 @@ class Gem::DependencyList dependencies.each do |dep| specs.each do |spec| - if spec.satisfies_requirement? dep then + if spec.satisfies_requirement? dep yield spec break end @@ -241,4 +241,3 @@ class Gem::DependencyList end end - diff --git a/lib/rubygems/deprecate.rb b/lib/rubygems/deprecate.rb index 375194c1e8..815f42ae8c 100644 --- a/lib/rubygems/deprecate.rb +++ b/lib/rubygems/deprecate.rb @@ -27,7 +27,7 @@ module Gem::Deprecate @skip ||= false end - def self.skip= v # :nodoc: + def self.skip=(v) # :nodoc: @skip = v end @@ -47,7 +47,7 @@ module Gem::Deprecate # telling the user of +repl+ (unless +repl+ is :none) and the # year/month that it is planned to go away. - def deprecate name, repl, year, month + def deprecate(name, repl, year, month) class_eval { old = "_deprecated_#{name}" alias_method old, name @@ -68,4 +68,3 @@ module Gem::Deprecate module_function :deprecate, :skip_during end - diff --git a/lib/rubygems/doctor.rb b/lib/rubygems/doctor.rb index e5d8c43de8..661ae5a4e1 100644 --- a/lib/rubygems/doctor.rb +++ b/lib/rubygems/doctor.rb @@ -41,7 +41,7 @@ class Gem::Doctor # # If +dry_run+ is true no files or directories will be removed. - def initialize gem_repository, dry_run = false + def initialize(gem_repository, dry_run = false) @gem_repository = gem_repository @dry_run = dry_run @@ -73,7 +73,7 @@ class Gem::Doctor Gem.use_paths @gem_repository.to_s - unless gem_repository? then + unless gem_repository? say 'This directory does not appear to be a RubyGems repository, ' + 'skipping' say @@ -99,7 +99,7 @@ class Gem::Doctor ## # Removes files in +sub_directory+ with +extension+ - def doctor_child sub_directory, extension # :nodoc: + def doctor_child(sub_directory, extension) # :nodoc: directory = File.join(@gem_repository, sub_directory) Dir.entries(directory).sort.each do |ent| @@ -115,7 +115,7 @@ class Gem::Doctor type = File.directory?(child) ? 'directory' : 'file' - action = if @dry_run then + action = if @dry_run 'Extra' else FileUtils.rm_r(child) @@ -129,4 +129,3 @@ class Gem::Doctor end end - diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb index 6f2847d548..6773bbcd26 100644 --- a/lib/rubygems/errors.rb +++ b/lib/rubygems/errors.rb @@ -25,7 +25,7 @@ module Gem # system. Instead of rescuing from this class, make sure to rescue from the # superclass Gem::LoadError to catch all types of load errors. class MissingSpecError < Gem::LoadError - def initialize name, requirement + def initialize(name, requirement) @name = name @requirement = requirement end @@ -50,7 +50,7 @@ module Gem class MissingSpecVersionError < MissingSpecError attr_reader :specs - def initialize name, requirement, specs + def initialize(name, requirement, specs) super(name, requirement) @specs = specs end @@ -81,7 +81,7 @@ module Gem attr_reader :target - def initialize target, conflicts + def initialize(target, conflicts) @target = target @conflicts = conflicts @name = target.name diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index 5999bc2a0d..a387cd390f 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -36,7 +36,7 @@ class Gem::DependencyResolutionError < Gem::DependencyError attr_reader :conflict - def initialize conflict + def initialize(conflict) @conflict = conflict a, b = conflicting_dependencies @@ -77,7 +77,7 @@ class Gem::FilePermissionError < Gem::Exception attr_reader :directory - def initialize directory + def initialize(directory) @directory = directory super "You don't have write permissions for the #{directory} directory." @@ -137,7 +137,7 @@ class Gem::ImpossibleDependenciesError < Gem::Exception attr_reader :conflicts attr_reader :request - def initialize request, conflicts + def initialize(request, conflicts) @request = request @conflicts = conflicts @@ -249,7 +249,7 @@ class Gem::UnsatisfiableDependencyError < Gem::DependencyError # Creates a new UnsatisfiableDependencyError for the unsatisfiable # Gem::Resolver::DependencyRequest +dep+ - def initialize dep, platform_mismatch=nil + def initialize(dep, platform_mismatch=nil) if platform_mismatch and !platform_mismatch.empty? plats = platform_mismatch.map { |x| x.platform.to_s }.sort.uniq super "Unable to resolve dependency: No match for '#{dep}' on this platform. Found: #{plats.join(', ')}" diff --git a/lib/rubygems/ext.rb b/lib/rubygems/ext.rb index 18d2bc233a..35a486606a 100644 --- a/lib/rubygems/ext.rb +++ b/lib/rubygems/ext.rb @@ -16,4 +16,3 @@ require 'rubygems/ext/configure_builder' require 'rubygems/ext/ext_conf_builder' require 'rubygems/ext/rake_builder' require 'rubygems/ext/cmake_builder' - diff --git a/lib/rubygems/ext/build_error.rb b/lib/rubygems/ext/build_error.rb index 0b3c17a9a0..6dffddb5cc 100644 --- a/lib/rubygems/ext/build_error.rb +++ b/lib/rubygems/ext/build_error.rb @@ -4,4 +4,3 @@ class Gem::Ext::BuildError < Gem::InstallError end - diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index 54eeae57b6..f578e7feee 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -27,14 +27,14 @@ class Gem::Ext::Builder end def self.make(dest_path, results) - unless File.exist? 'Makefile' then + unless File.exist? 'Makefile' raise Gem::InstallError, 'Makefile not found' end # try to find make program from Ruby configure arguments first RbConfig::CONFIG['configure_args'] =~ /with-make-prog\=(\w+)/ make_program = ENV['MAKE'] || ENV['make'] || $1 - unless make_program then + unless make_program make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make' end @@ -86,13 +86,13 @@ class Gem::Ext::Builder ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps end - unless $?.success? then + unless $?.success? results << "Building has failed. See above output for more information on the failure." if verbose exit_reason = - if $?.exited? then + if $?.exited? ", exit code #{$?.exitstatus}" - elsif $?.signaled? then + elsif $?.signaled? ", uncaught signal #{$?.termsig}" end @@ -105,7 +105,7 @@ class Gem::Ext::Builder # have build arguments, saved, set +build_args+ which is an ARGV-style # array. - def initialize spec, build_args = spec.build_args + def initialize(spec, build_args = spec.build_args) @spec = spec @build_args = build_args @gem_dir = spec.full_gem_path @@ -116,7 +116,7 @@ class Gem::Ext::Builder ## # Chooses the extension builder class for +extension+ - def builder_for extension # :nodoc: + def builder_for(extension) # :nodoc: case extension when /extconf/ then Gem::Ext::ExtConfBuilder @@ -138,7 +138,7 @@ class Gem::Ext::Builder ## # Logs the build +output+ in +build_dir+, then raises Gem::Ext::BuildError. - def build_error build_dir, output, backtrace = nil # :nodoc: + def build_error(build_dir, output, backtrace = nil) # :nodoc: gem_make_out = write_gem_make_out output message = <<-EOF @@ -153,7 +153,7 @@ EOF raise Gem::Ext::BuildError, message, backtrace end - def build_extension extension, dest_path # :nodoc: + def build_extension(extension, dest_path) # :nodoc: results = [] # FIXME: Determine if this line is necessary and, if so, why. @@ -235,7 +235,7 @@ EOF ## # Writes +output+ to gem_make.out in the extension install directory. - def write_gem_make_out output # :nodoc: + def write_gem_make_out(output) # :nodoc: destination = File.join @spec.extension_dir, 'gem_make.out' FileUtils.mkdir_p @spec.extension_dir diff --git a/lib/rubygems/ext/cmake_builder.rb b/lib/rubygems/ext/cmake_builder.rb index cfcc83c9a7..ab226733d9 100644 --- a/lib/rubygems/ext/cmake_builder.rb +++ b/lib/rubygems/ext/cmake_builder.rb @@ -3,7 +3,7 @@ require 'rubygems/command' class Gem::Ext::CmakeBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil) - unless File.exist?('Makefile') then + unless File.exist?('Makefile') cmd = "cmake . -DCMAKE_INSTALL_PREFIX=#{dest_path}" cmd << " #{Gem::Command.build_args.join ' '}" unless Gem::Command.build_args.empty? diff --git a/lib/rubygems/ext/configure_builder.rb b/lib/rubygems/ext/configure_builder.rb index 1b9e374075..7d105c9bd3 100644 --- a/lib/rubygems/ext/configure_builder.rb +++ b/lib/rubygems/ext/configure_builder.rb @@ -8,7 +8,7 @@ class Gem::Ext::ConfigureBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil) - unless File.exist?('Makefile') then + unless File.exist?('Makefile') cmd = "sh ./configure --prefix=#{dest_path}" cmd << " #{args.join ' '}" unless args.empty? diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index 97bb789fb8..5a2b3eb533 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -47,7 +47,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder run cmd, results ensure if File.exist? 'mkmf.log' - unless $?.success? then + unless $?.success? results << "To see why this extension failed to compile, please check" \ " the mkmf.log which can be found here:\n" results << " " + File.join(dest_path, 'mkmf.log') + "\n" @@ -63,7 +63,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder if tmp_dest # TODO remove in RubyGems 3 - if Gem.install_extension_in_lib and lib_dir then + if Gem.install_extension_in_lib and lib_dir FileUtils.mkdir_p lib_dir entries = Dir.entries(tmp_dest) - %w[. ..] entries = entries.map { |entry| File.join tmp_dest, entry } diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index f41e5618dc..52041a2713 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/lib/rubygems/ext/rake_builder.rb @@ -10,7 +10,7 @@ require "shellwords" class Gem::Ext::RakeBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil) - if File.basename(extension) =~ /mkrf_conf/i then + if File.basename(extension) =~ /mkrf_conf/i run([Gem.ruby, File.basename(extension), *args], results) end diff --git a/lib/rubygems/gem_runner.rb b/lib/rubygems/gem_runner.rb index 349d49d66e..4159d81389 100644 --- a/lib/rubygems/gem_runner.rb +++ b/lib/rubygems/gem_runner.rb @@ -38,7 +38,7 @@ class Gem::GemRunner ## # Run the gem command with the following arguments. - def run args + def run(args) build_args = extract_build_args args do_configuration args @@ -63,7 +63,7 @@ class Gem::GemRunner # Separates the build arguments (those following --) from the # other arguments in the list. - def extract_build_args args # :nodoc: + def extract_build_args(args) # :nodoc: return [] unless offset = args.index('--') build_args = args.slice!(offset...args.length) diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index 7c6d6bb364..6fe8455498 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -28,7 +28,7 @@ module Gem::GemcutterUtilities # The API key from the command options or from the user's configuration. def api_key - if options[:key] then + if options[:key] verify_api_key options[:key] elsif Gem.configuration.api_keys.key?(host) Gem.configuration.api_keys[host] @@ -90,11 +90,11 @@ module Gem::GemcutterUtilities # Signs in with the RubyGems API at +sign_in_host+ and sets the rubygems API # key. - def sign_in sign_in_host = nil + def sign_in(sign_in_host = nil) sign_in_host ||= self.host return if api_key - pretty_host = if Gem::DEFAULT_HOST == sign_in_host then + pretty_host = if Gem::DEFAULT_HOST == sign_in_host 'RubyGems.org' else sign_in_host @@ -124,7 +124,7 @@ module Gem::GemcutterUtilities # an error. def verify_api_key(key) - if Gem.configuration.api_keys.key? key then + if Gem.configuration.api_keys.key? key Gem.configuration.api_keys[key] else alert_error "No such API key. Please add it to your configuration (done automatically on initial `gem push`)." @@ -139,10 +139,10 @@ module Gem::GemcutterUtilities # If the response was not successful, shows an error to the user including # the +error_prefix+ and the response body. - def with_response response, error_prefix = nil + def with_response(response, error_prefix = nil) case response when Net::HTTPSuccess then - if block_given? then + if block_given? yield response else say response.body @@ -156,7 +156,7 @@ module Gem::GemcutterUtilities end end - def set_api_key host, key + def set_api_key(host, key) if host == Gem::DEFAULT_HOST Gem.configuration.rubygems_api_key = key else @@ -165,4 +165,3 @@ module Gem::GemcutterUtilities end end - diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb index 1bc2746c43..8e59997dba 100644 --- a/lib/rubygems/indexer.rb +++ b/lib/rubygems/indexer.rb @@ -4,17 +4,10 @@ require 'rubygems/package' require 'time' require 'tmpdir' -rescue_exceptions = [LoadError] -begin - require 'bundler/errors' -rescue LoadError # this rubygems + old ruby -else # this rubygems + ruby trunk with bundler - rescue_exceptions << Bundler::GemfileNotFound -end begin gem 'builder' require 'builder/xchar' -rescue *rescue_exceptions +rescue LoadError end ## @@ -62,7 +55,7 @@ class Gem::Indexer require 'tmpdir' require 'zlib' - unless defined?(Builder::XChar) then + unless defined?(Builder::XChar) raise "Gem::Indexer requires that the XML Builder library be installed:" + "\n\tgem install builder" end @@ -116,7 +109,7 @@ class Gem::Indexer ## # Builds Marshal quick index gemspecs. - def build_marshal_gemspecs specs + def build_marshal_gemspecs(specs) count = specs.count progress = ui.progress_reporter count, "Generating Marshal quick index gemspecs for #{count} gems", @@ -161,7 +154,7 @@ class Gem::Indexer platform = spec.original_platform # win32-api-1.0.4-x86-mswin32-60 - unless String === platform then + unless String === platform alert_warning "Skipping invalid platform in gem: #{spec.full_name}" next end @@ -179,7 +172,7 @@ class Gem::Indexer ## # Builds indices for RubyGems 1.2 and newer. Handles full, latest, prerelease - def build_modern_indices specs + def build_modern_indices(specs) prerelease, released = specs.partition { |s| s.version.prerelease? } @@ -199,9 +192,9 @@ class Gem::Indexer "#{@prerelease_specs_index}.gz"] end - def map_gems_to_specs gems + def map_gems_to_specs(gems) gems.map { |gemfile| - if File.size(gemfile) == 0 then + if File.size(gemfile) == 0 alert_warning "Skipping zero-length gem: #{gemfile}" next end @@ -235,7 +228,7 @@ class Gem::Indexer say "Compressing indices" Gem.time 'Compressed indices' do - if @build_modern then + if @build_modern gzip @specs_index gzip @latest_specs_index gzip @prerelease_specs_index @@ -313,7 +306,7 @@ class Gem::Indexer files = @files files.delete @quick_marshal_dir if files.include? @quick_dir - if files.include? @quick_marshal_dir and not files.include? @quick_dir then + if files.include? @quick_marshal_dir and not files.include? @quick_dir files.delete @quick_marshal_dir dst_name = File.join(@dest_directory, @quick_marshal_dir_base) @@ -354,7 +347,7 @@ class Gem::Indexer data = Gem.read_binary path compressed_data = Gem.read_binary "#{path}.#{extension}" - unless data == Gem::Util.inflate(compressed_data) then + unless data == Gem::Util.inflate(compressed_data) raise "Compressed file #{compressed_path} does not match uncompressed file #{path}" end end @@ -374,7 +367,7 @@ class Gem::Indexer gem_mtime >= specs_mtime end - if updated_gems.empty? then + if updated_gems.empty? say 'No new gems' terminate_interaction 0 end diff --git a/lib/rubygems/install_default_message.rb b/lib/rubygems/install_default_message.rb index dc73fd962b..f68fd2fd04 100644 --- a/lib/rubygems/install_default_message.rb +++ b/lib/rubygems/install_default_message.rb @@ -10,4 +10,3 @@ Gem.post_install do |installer| ui = Gem::DefaultUserInteraction.ui ui.say "Successfully installed #{installer.spec.full_name} as a default gem" end - diff --git a/lib/rubygems/install_message.rb b/lib/rubygems/install_message.rb index 6880db583e..3c13888a84 100644 --- a/lib/rubygems/install_message.rb +++ b/lib/rubygems/install_message.rb @@ -10,4 +10,3 @@ Gem.post_install do |installer| ui = Gem::DefaultUserInteraction.ui ui.say "Successfully installed #{installer.spec.full_name}" end - diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb index 824682f9ad..f05491a31c 100644 --- a/lib/rubygems/install_update_options.rb +++ b/lib/rubygems/install_update_options.rb @@ -50,7 +50,7 @@ module Gem::InstallUpdateOptions add_option(:"Install/Update", '--vendor', 'Install gem into the vendor directory.', 'Only for use by gem repackagers.') do |value, options| - unless Gem.vendor_dir then + unless Gem.vendor_dir raise OptionParser::InvalidOption.new 'your platform is not supported' end @@ -140,7 +140,7 @@ module Gem::InstallUpdateOptions File.exist? file end unless v - unless v then + unless v message = v ? v : "(tried #{Gem::GEM_DEP_FILES.join ', '})" raise OptionParser::InvalidArgument, @@ -178,7 +178,6 @@ module Gem::InstallUpdateOptions 'Suggest alternates when gems are not found') do |v,o| options[:suggest_alternate] = v end - end ## @@ -189,4 +188,3 @@ module Gem::InstallUpdateOptions end end - diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 7587c259dc..3c2a2ac3c2 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -101,7 +101,7 @@ class Gem::Installer ## # Construct an installer object for the gem file located at +path+ - def self.at path, options = {} + def self.at(path, options = {}) security_policy = options[:security_policy] package = Gem::Package.new path, security_policy new package, options @@ -118,7 +118,7 @@ class Gem::Installer @spec = spec end - def extract_files destination_dir, pattern = '*' + def extract_files(destination_dir, pattern = '*') FileUtils.mkdir_p destination_dir spec.files.each do |file| @@ -129,7 +129,7 @@ class Gem::Installer end end - def copy_to path + def copy_to(path) end end @@ -137,7 +137,7 @@ class Gem::Installer # Construct an installer object for an ephemeral gem (one where we don't # actually have a .gem file, just a spec) - def self.for_spec spec, options = {} + def self.for_spec(spec, options = {}) # FIXME: we should have a real Package class for this new FakePackage.new(spec), options end @@ -189,7 +189,7 @@ class Gem::Installer @bin_dir = options[:bin_dir] if options[:bin_dir] - if options[:user_install] and not options[:unpack] then + if options[:user_install] and not options[:unpack] @gem_home = Gem.user_dir @bin_dir = Gem.bindir gem_home unless options[:bin_dir] check_that_user_bin_dir_is_in_path @@ -209,7 +209,7 @@ class Gem::Installer # # Otherwise +filename+ is overwritten. - def check_executable_overwrite filename # :nodoc: + def check_executable_overwrite(filename) # :nodoc: return if @force generated_bin = File.join @bin_dir, formatted_program_filename(filename) @@ -245,7 +245,7 @@ class Gem::Installer question = "#{spec.name}'s executable \"#{filename}\" conflicts with ".dup - if ruby_executable then + if ruby_executable question << (existing || 'an unknown executable') return if ask_yes_no "#{question}\nOverwrite the executable?", false @@ -298,7 +298,7 @@ class Gem::Installer run_pre_install_hooks # Set loaded_from to ensure extension_dir is correct - if @options[:install_as_default] then + if @options[:install_as_default] spec.loaded_from = default_spec_file else spec.loaded_from = spec_file @@ -311,7 +311,7 @@ class Gem::Installer dir_mode = options[:dir_mode] FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0700 - if @options[:install_as_default] then + if @options[:install_as_default] extract_bin write_default_spec else @@ -344,7 +344,7 @@ class Gem::Installer def run_pre_install_hooks # :nodoc: Gem.pre_install_hooks.each do |hook| - if hook.call(self) == false then + if hook.call(self) == false location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/ message = "pre-install hook#{location} failed for #{spec.full_name}" @@ -355,7 +355,7 @@ class Gem::Installer def run_post_build_hooks # :nodoc: Gem.post_build_hooks.each do |hook| - if hook.call(self) == false then + if hook.call(self) == false FileUtils.rm_rf gem_dir location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/ @@ -398,7 +398,7 @@ class Gem::Installer # dependency :: Gem::Dependency def ensure_dependency(spec, dependency) - unless installation_satisfies_dependency? dependency then + unless installation_satisfies_dependency? dependency raise Gem::InstallError, "#{spec.name} requires #{dependency}" end true @@ -466,7 +466,7 @@ class Gem::Installer # Creates windows .bat files for easy running of commands def generate_windows_script(filename, bindir) - if Gem.win_platform? then + if Gem.win_platform? script_name = filename + ".bat" script_path = File.join bindir, File.basename(script_name) File.open script_path, 'w' do |file| @@ -492,7 +492,7 @@ class Gem::Installer filename.untaint bin_path = File.join gem_dir, spec.bindir, filename - unless File.exist? bin_path then + unless File.exist? bin_path # TODO change this to a more useful warning warn "`#{bin_path}` does not exist, maybe `gem pristine #{spec.name}` will fix it?" next @@ -504,7 +504,7 @@ class Gem::Installer check_executable_overwrite filename - if @wrappers then + if @wrappers generate_bin_script filename, @bin_dir else generate_bin_symlink filename, @bin_dir @@ -543,8 +543,8 @@ class Gem::Installer src = File.join gem_dir, spec.bindir, filename dst = File.join bindir, formatted_program_filename(filename) - if File.exist? dst then - if File.symlink? dst then + if File.exist? dst + if File.symlink? dst link = File.readlink(dst).split File::SEPARATOR cur_version = Gem::Version.create(link[-3].sub(/^.*-/, '')) return if spec.version < cur_version @@ -578,7 +578,7 @@ class Gem::Installer path = File.join gem_dir, spec.bindir, bin_file_name first_line = File.open(path, "rb") {|file| file.gets} - if /\A#!/ =~ first_line then + if /\A#!/ =~ first_line # Preserve extra words on shebang line, like "-w". Thanks RPA. shebang = first_line.sub(/\A\#!.*?ruby\S*((\s+\S+)+)/, "#!#{Gem.ruby}") opts = $1 @@ -603,9 +603,9 @@ class Gem::Installer end "#!#{which}" - elsif not ruby_name then + elsif not ruby_name "#!#{Gem.ruby}#{opts}" - elsif opts then + elsif opts "#!/bin/sh\n'exec' #{ruby_name.dump} '-x' \"$0\" \"$@\"\n#{shebang}" else # Create a plain shebang line. @@ -631,9 +631,9 @@ class Gem::Installer end def ensure_required_ruby_version_met # :nodoc: - if rrv = spec.required_ruby_version then - unless rrv.satisfied_by? Gem.ruby_version then - ruby_version = Gem.ruby_api_version + if rrv = spec.required_ruby_version + ruby_version = Gem.ruby_version + unless rrv.satisfied_by? ruby_version raise Gem::RuntimeRequirementNotMetError, "#{spec.name} requires Ruby version #{rrv}. The current ruby version is #{ruby_version}." end @@ -641,8 +641,8 @@ class Gem::Installer end def ensure_required_rubygems_version_met # :nodoc: - if rrgv = spec.required_rubygems_version then - unless rrgv.satisfied_by? Gem.rubygems_version then + if rrgv = spec.required_rubygems_version + unless rrgv.satisfied_by? Gem.rubygems_version rg_version = Gem::VERSION raise Gem::RuntimeRequirementNotMetError, "#{spec.name} requires RubyGems version #{rrgv}. The current RubyGems version is #{rg_version}. " + @@ -702,16 +702,16 @@ class Gem::Installer File::ALT_SEPARATOR path = ENV['PATH'] - if Gem.win_platform? then + if Gem.win_platform? path = path.downcase user_bin_dir = user_bin_dir.downcase end path = path.split(File::PATH_SEPARATOR) - unless path.include? user_bin_dir then + unless path.include? user_bin_dir unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV['HOME'], '~')) - unless self.class.path_warning then + unless self.class.path_warning alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run." self.class.path_warning = true end @@ -752,7 +752,7 @@ version = "#{Gem::Requirement.default}.a" if ARGV.first str = ARGV.first str = str.dup.force_encoding("BINARY") - if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) then + if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) version = $1 ARGV.shift end @@ -847,7 +847,7 @@ TEXT # Prefix and suffix the program filename the same as ruby. def formatted_program_filename(filename) - if @format_executable then + if @format_executable self.class.exec_format % File.basename(filename) else filename diff --git a/lib/rubygems/installer_test_case.rb b/lib/rubygems/installer_test_case.rb index 943c6c1256..d6d16a9194 100644 --- a/lib/rubygems/installer_test_case.rb +++ b/lib/rubygems/installer_test_case.rb @@ -183,4 +183,3 @@ class Gem::InstallerTestCase < Gem::TestCase end end - diff --git a/lib/rubygems/local_remote_options.rb b/lib/rubygems/local_remote_options.rb index fe09e34e54..9fa256b08a 100644 --- a/lib/rubygems/local_remote_options.rb +++ b/lib/rubygems/local_remote_options.rb @@ -108,7 +108,7 @@ module Gem::LocalRemoteOptions source << '/' if source !~ /\/\z/ - if options.delete :sources_cleared then + if options.delete :sources_cleared Gem.sources = [source] else Gem.sources << source unless Gem.sources.include?(source) @@ -148,4 +148,3 @@ module Gem::LocalRemoteOptions end end - diff --git a/lib/rubygems/mock_gem_ui.rb b/lib/rubygems/mock_gem_ui.rb index 0223f8c35d..92ec85625c 100644 --- a/lib/rubygems/mock_gem_ui.rb +++ b/lib/rubygems/mock_gem_ui.rb @@ -12,7 +12,7 @@ class Gem::MockGemUi < Gem::StreamUI class InputEOFError < RuntimeError - def initialize question + def initialize(question) super "Out of input for MockGemUi on #{question.inspect}" end @@ -21,7 +21,7 @@ class Gem::MockGemUi < Gem::StreamUI class TermError < RuntimeError attr_reader :exit_code - def initialize exit_code + def initialize(exit_code) super @exit_code = exit_code end @@ -56,7 +56,7 @@ class Gem::MockGemUi < Gem::StreamUI @terminated = false end - def ask question + def ask(question) raise InputEOFError, question if @ins.eof? super @@ -86,4 +86,3 @@ class Gem::MockGemUi < Gem::StreamUI end end - diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb index 316329a0bd..e948fb3d86 100644 --- a/lib/rubygems/name_tuple.rb +++ b/lib/rubygems/name_tuple.rb @@ -24,7 +24,7 @@ class Gem::NameTuple # Turn an array of [name, version, platform] into an array of # NameTuple objects. - def self.from_list list + def self.from_list(list) list.map { |t| new(*t) } end @@ -32,7 +32,7 @@ class Gem::NameTuple # Turn an array of NameTuple objects back into an array of # [name, version, platform] tuples. - def self.to_basic list + def self.to_basic(list) list.map { |t| t.to_a } end @@ -90,7 +90,7 @@ class Gem::NameTuple alias to_s inspect # :nodoc: - def <=> other + def <=>(other) [@name, @version, @platform == Gem::Platform::RUBY ? -1 : 1] <=> [other.name, other.version, other.platform == Gem::Platform::RUBY ? -1 : 1] @@ -102,7 +102,7 @@ class Gem::NameTuple # Compare with +other+. Supports another NameTuple or an Array # in the [name, version, platform] format. - def == other + def ==(other) case other when self.class @name == other.name and diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index a71c41afc7..9af84981a4 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -55,7 +55,7 @@ class Gem::Package class FormatError < Error attr_reader :path - def initialize message, source = nil + def initialize(message, source = nil) if source @path = source.path @@ -68,7 +68,7 @@ class Gem::Package end class PathError < Error - def initialize destination, destination_dir + def initialize(destination, destination_dir) super "installing into parent path %s of %s is not allowed" % [destination, destination_dir] end @@ -119,7 +119,7 @@ class Gem::Package # Permission for other files attr_accessor :data_mode - def self.build spec, skip_validation = false, strict_validation = false + def self.build(spec, skip_validation = false, strict_validation = false) gem_file = spec.file_name package = new gem_file @@ -136,7 +136,7 @@ class Gem::Package # If +gem+ is an existing file in the old format a Gem::Package::Old will be # returned. - def self.new gem, security_policy = nil + def self.new(gem, security_policy = nil) gem = if gem.is_a?(Gem::Package::Source) gem elsif gem.respond_to? :read @@ -157,7 +157,7 @@ class Gem::Package ## # Creates a new package that will read or write to the file +gem+. - def initialize gem, security_policy # :notnew: + def initialize(gem, security_policy) # :notnew: @gem = gem @build_time = ENV["SOURCE_DATE_EPOCH"] ? Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc : Time.now @@ -174,14 +174,14 @@ class Gem::Package ## # Copies this package to +path+ (if possible) - def copy_to path + def copy_to(path) FileUtils.cp @gem.path, path unless File.exist? path end ## # Adds a checksum for each entry in the gem to checksums.yaml.gz. - def add_checksums tar + def add_checksums(tar) Gem.load_yaml checksums_by_algorithm = Hash.new { |h, algorithm| h[algorithm] = {} } @@ -203,7 +203,7 @@ class Gem::Package # Adds the files listed in the packages's Gem::Specification to data.tar.gz # and adds this file to the +tar+. - def add_contents tar # :nodoc: + def add_contents(tar) # :nodoc: digests = tar.add_file_signed 'data.tar.gz', 0444, @signer do |io| gzip_to io do |gz_io| Gem::Package::TarWriter.new gz_io do |data_tar| @@ -218,7 +218,7 @@ class Gem::Package ## # Adds files included the package's Gem::Specification to the +tar+ file - def add_files tar # :nodoc: + def add_files(tar) # :nodoc: @spec.files.each do |file| stat = File.lstat file @@ -241,7 +241,7 @@ class Gem::Package ## # Adds the package's Gem::Specification to the +tar+ file - def add_metadata tar # :nodoc: + def add_metadata(tar) # :nodoc: digests = tar.add_file_signed 'metadata.gz', 0444, @signer do |io| gzip_to io do |gz_io| gz_io.write @spec.to_yaml @@ -254,7 +254,7 @@ class Gem::Package ## # Builds this package based on the specification set by #spec= - def build skip_validation = false, strict_validation = false + def build(skip_validation = false, strict_validation = false) raise ArgumentError, "skip_validation = true and strict_validation = true are incompatible" if skip_validation && strict_validation Gem.load_yaml @@ -318,8 +318,8 @@ EOM # Creates a digest of the TarEntry +entry+ from the digest algorithm set by # the security policy. - def digest entry # :nodoc: - algorithms = if @checksums then + def digest(entry) # :nodoc: + algorithms = if @checksums @checksums.keys else [Gem::Security::DIGEST_NAME].compact @@ -327,7 +327,7 @@ EOM algorithms.each do |algorithm| digester = - if defined?(OpenSSL::Digest) then + if defined?(OpenSSL::Digest) OpenSSL::Digest.new algorithm else Digest.const_get(algorithm).new @@ -349,7 +349,7 @@ EOM # If +pattern+ is specified, only entries matching that glob will be # extracted. - def extract_files destination_dir, pattern = "*" + def extract_files(destination_dir, pattern = "*") verify unless @spec FileUtils.mkdir_p destination_dir, :mode => dir_mode && 0700 @@ -378,7 +378,7 @@ EOM # If +pattern+ is specified, only entries matching that glob will be # extracted. - def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc: + def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc: directories = [] if dir_mode open_tar_gz io do |tar| tar.each do |entry| @@ -391,7 +391,7 @@ EOM mkdir_options = {} mkdir_options[:mode] = dir_mode ? 0700 : (entry.header.mode if entry.directory?) mkdir = - if entry.directory? then + if entry.directory? destination else File.dirname destination @@ -427,7 +427,7 @@ EOM # Also sets the gzip modification time to the package build time to ease # testing. - def gzip_to io # :yields: gz_io + def gzip_to(io) # :yields: gz_io gz_io = Zlib::GzipWriter.new io, Zlib::BEST_COMPRESSION gz_io.mtime = @build_time @@ -441,7 +441,7 @@ EOM # # If +filename+ is not inside +destination_dir+ an exception is raised. - def install_location filename, destination_dir # :nodoc: + def install_location(filename, destination_dir) # :nodoc: raise Gem::Package::PathError.new(filename, destination_dir) if filename.start_with? '/' @@ -463,7 +463,7 @@ EOM end end - def mkdir_p_safe mkdir, mkdir_options, destination_dir, file_name + def mkdir_p_safe(mkdir, mkdir_options, destination_dir, file_name) destination_dir = File.realpath(File.expand_path(destination_dir)) parts = mkdir.split(File::SEPARATOR) parts.reduce do |path, basename| @@ -482,7 +482,7 @@ EOM ## # Loads a Gem::Specification from the TarEntry +entry+ - def load_spec entry # :nodoc: + def load_spec(entry) # :nodoc: case entry.full_name when 'metadata' then @spec = Gem::Specification.from_yaml entry.read @@ -500,7 +500,7 @@ EOM ## # Opens +io+ as a gzipped tar archive - def open_tar_gz io # :nodoc: + def open_tar_gz(io) # :nodoc: Zlib::GzipReader.wrap io do |gzio| tar = Gem::Package::TarReader.new gzio @@ -511,7 +511,7 @@ EOM ## # Reads and loads checksums.yaml.gz from the tar file +gem+ - def read_checksums gem + def read_checksums(gem) Gem.load_yaml @checksums = gem.seek 'checksums.yaml.gz' do |entry| @@ -527,7 +527,7 @@ EOM def setup_signer(signer_options: {}) passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE'] - if @spec.signing_key then + if @spec.signing_key @signer = Gem::Security::Signer.new( @spec.signing_key, @@ -600,14 +600,14 @@ EOM # Verifies the +checksums+ against the +digests+. This check is not # cryptographically secure. Missing checksums are ignored. - def verify_checksums digests, checksums # :nodoc: + def verify_checksums(digests, checksums) # :nodoc: return unless checksums checksums.sort.each do |algorithm, gem_digests| gem_digests.sort.each do |file_name, gem_hexdigest| computed_digest = digests[algorithm][file_name] - unless computed_digest.hexdigest == gem_hexdigest then + unless computed_digest.hexdigest == gem_hexdigest raise Gem::Package::FormatError.new \ "#{algorithm} checksum mismatch for #{file_name}", @gem end @@ -618,7 +618,7 @@ EOM ## # Verifies +entry+ in a .gem file. - def verify_entry entry + def verify_entry(entry) file_name = entry.full_name @files << file_name @@ -645,16 +645,16 @@ EOM ## # Verifies the files of the +gem+ - def verify_files gem + def verify_files(gem) gem.each do |entry| verify_entry entry end - unless @spec then + unless @spec raise Gem::Package::FormatError.new 'package metadata is missing', @gem end - unless @files.include? 'data.tar.gz' then + unless @files.include? 'data.tar.gz' raise Gem::Package::FormatError.new \ 'package content (data.tar.gz) is missing', @gem end @@ -667,7 +667,7 @@ EOM ## # Verifies that +entry+ is a valid gzipped file. - def verify_gz entry # :nodoc: + def verify_gz(entry) # :nodoc: Zlib::GzipReader.wrap entry do |gzio| gzio.read 16384 until gzio.eof? # gzip checksum verification end diff --git a/lib/rubygems/package/digest_io.rb b/lib/rubygems/package/digest_io.rb index 4930c9aa7d..d9e6c3c021 100644 --- a/lib/rubygems/package/digest_io.rb +++ b/lib/rubygems/package/digest_io.rb @@ -31,7 +31,7 @@ class Gem::Package::DigestIO # digests['SHA1'].hexdigest #=> "aaf4c61d[...]" # digests['SHA512'].hexdigest #=> "9b71d224[...]" - def self.wrap io, digests + def self.wrap(io, digests) digest_io = new io, digests yield digest_io @@ -43,7 +43,7 @@ class Gem::Package::DigestIO # Creates a new DigestIO instance. Using ::wrap is recommended, see the # ::wrap documentation for documentation of +io+ and +digests+. - def initialize io, digests + def initialize(io, digests) @io = io @digests = digests end @@ -51,7 +51,7 @@ class Gem::Package::DigestIO ## # Writes +data+ to the underlying IO and updates the digests - def write data + def write(data) result = @io.write data @digests.each do |_, digest| @@ -62,4 +62,3 @@ class Gem::Package::DigestIO end end - diff --git a/lib/rubygems/package/file_source.rb b/lib/rubygems/package/file_source.rb index ecc3a68677..8a4f9da6f2 100644 --- a/lib/rubygems/package/file_source.rb +++ b/lib/rubygems/package/file_source.rb @@ -10,7 +10,7 @@ class Gem::Package::FileSource < Gem::Package::Source # :nodoc: all attr_reader :path - def initialize path + def initialize(path) @path = path end @@ -22,13 +22,12 @@ class Gem::Package::FileSource < Gem::Package::Source # :nodoc: all File.exist? path end - def with_write_io &block + def with_write_io(&block) File.open path, 'wb', &block end - def with_read_io &block + def with_read_io(&block) File.open path, 'rb', &block end end - diff --git a/lib/rubygems/package/io_source.rb b/lib/rubygems/package/io_source.rb index ee79a21083..669a859d0a 100644 --- a/lib/rubygems/package/io_source.rb +++ b/lib/rubygems/package/io_source.rb @@ -11,7 +11,7 @@ class Gem::Package::IOSource < Gem::Package::Source # :nodoc: all attr_reader :io - def initialize io + def initialize(io) @io = io end @@ -43,4 +43,3 @@ class Gem::Package::IOSource < Gem::Package::Source # :nodoc: all end end - diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb index a8457948ff..d028be134b 100644 --- a/lib/rubygems/package/old.rb +++ b/lib/rubygems/package/old.rb @@ -19,7 +19,7 @@ class Gem::Package::Old < Gem::Package # Creates a new old-format package reader for +gem+. Old-format packages # cannot be written. - def initialize gem, security_policy + def initialize(gem, security_policy) require 'fileutils' require 'zlib' Gem.load_yaml @@ -49,7 +49,7 @@ class Gem::Package::Old < Gem::Package ## # Extracts the files in this package into +destination_dir+ - def extract_files destination_dir + def extract_files(destination_dir) verify errstr = "Error reading files from gem" @@ -94,7 +94,7 @@ class Gem::Package::Old < Gem::Package ## # Reads the file list section from the old-format gem +io+ - def file_list io # :nodoc: + def file_list(io) # :nodoc: header = String.new read_until_dashes io do |line| @@ -107,7 +107,7 @@ class Gem::Package::Old < Gem::Package ## # Reads lines until a "---" separator is found - def read_until_dashes io # :nodoc: + def read_until_dashes(io) # :nodoc: while (line = io.gets) && line.chomp.strip != "---" do yield line if block_given? end @@ -116,7 +116,7 @@ class Gem::Package::Old < Gem::Package ## # Skips the Ruby self-install header in +io+. - def skip_ruby io # :nodoc: + def skip_ruby(io) # :nodoc: loop do line = io.gets diff --git a/lib/rubygems/package/source.rb b/lib/rubygems/package/source.rb index fe19776c38..69701e55e9 100644 --- a/lib/rubygems/package/source.rb +++ b/lib/rubygems/package/source.rb @@ -1,4 +1,3 @@ # frozen_string_literal: true class Gem::Package::Source # :nodoc: end - diff --git a/lib/rubygems/package/tar_header.rb b/lib/rubygems/package/tar_header.rb index d3c242f815..c7b5f88dbd 100644 --- a/lib/rubygems/package/tar_header.rb +++ b/lib/rubygems/package/tar_header.rb @@ -134,7 +134,7 @@ class Gem::Package::TarHeader # Creates a new TarHeader using +vals+ def initialize(vals) - unless vals[:name] && vals[:size] && vals[:prefix] && vals[:mode] then + unless vals[:name] && vals[:size] && vals[:prefix] && vals[:mode] raise ArgumentError, ":name, :size, :prefix and :mode required" end diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb index d00f89e7f6..f64915eaea 100644 --- a/lib/rubygems/package/tar_reader.rb +++ b/lib/rubygems/package/tar_reader.rb @@ -92,7 +92,7 @@ class Gem::Package::TarReader # NOTE: Do not call #rewind during #each def rewind - if @init_pos == 0 then + if @init_pos == 0 @io.rewind else @io.pos = @init_pos @@ -104,7 +104,7 @@ class Gem::Package::TarReader # yields it. Rewinds the tar file to the beginning when the block # terminates. - def seek name # :yields: entry + def seek(name) # :yields: entry found = find do |entry| entry.full_name == name end diff --git a/lib/rubygems/package/tar_reader/entry.rb b/lib/rubygems/package/tar_reader/entry.rb index 77b06af233..19054c1635 100644 --- a/lib/rubygems/package/tar_reader/entry.rb +++ b/lib/rubygems/package/tar_reader/entry.rb @@ -64,7 +64,7 @@ class Gem::Package::TarReader::Entry # Full name of the tar entry def full_name - if @header.prefix != "" then + if @header.prefix != "" File.join @header.prefix, @header.name else @header.name diff --git a/lib/rubygems/package/tar_test_case.rb b/lib/rubygems/package/tar_test_case.rb index 381a5d0f43..75978c8ed0 100644 --- a/lib/rubygems/package/tar_test_case.rb +++ b/lib/rubygems/package/tar_test_case.rb @@ -52,7 +52,7 @@ class Gem::Package::TarTestCase < Gem::TestCase name = fields.shift length = fields.shift.to_i - if name == "checksum" then + if name == "checksum" chksum_off = offset offset += length next diff --git a/lib/rubygems/package/tar_writer.rb b/lib/rubygems/package/tar_writer.rb index aa00633cdd..87ee39a944 100644 --- a/lib/rubygems/package/tar_writer.rb +++ b/lib/rubygems/package/tar_writer.rb @@ -139,11 +139,11 @@ class Gem::Package::TarWriter # # The created digest object is returned. - def add_file_digest name, mode, digest_algorithms # :yields: io + def add_file_digest(name, mode, digest_algorithms) # :yields: io digests = digest_algorithms.map do |digest_algorithm| digest = digest_algorithm.new digest_name = - if digest.respond_to? :name then + if digest.respond_to? :name digest.name else /::([^:]+)$/ =~ digest_algorithm.name @@ -172,7 +172,7 @@ class Gem::Package::TarWriter # # Returns the digest. - def add_file_signed name, mode, signer + def add_file_signed(name, mode, signer) digest_algorithms = [ signer.digest_algorithm, Digest::SHA512, @@ -184,7 +184,7 @@ class Gem::Package::TarWriter signature_digest = digests.values.compact.find do |digest| digest_name = - if digest.respond_to? :name then + if digest.respond_to? :name digest.name else digest.class.name[/::([^:]+)\z/, 1] @@ -195,7 +195,7 @@ class Gem::Package::TarWriter raise "no #{signer.digest_name} in #{digests.values.compact}" unless signature_digest - if signer.key then + if signer.key signature = signer.sign signature_digest.digest add_file_simple "#{name}.sig", 0444, signature.length do |io| @@ -309,12 +309,12 @@ class Gem::Package::TarWriter # Splits +name+ into a name and prefix that can fit in the TarHeader def split_name(name) # :nodoc: - if name.bytesize > 256 then + if name.bytesize > 256 raise Gem::Package::TooLongFileName.new("File \"#{name}\" has a too long path (should be 256 or less)") end prefix = '' - if name.bytesize > 100 then + if name.bytesize > 100 parts = name.split('/', -1) # parts are never empty here name = parts.pop # initially empty for names with a trailing slash ("foo/.../bar/") prefix = parts.join('/') # if empty, then it's impossible to split (parts is empty too) @@ -323,11 +323,11 @@ class Gem::Package::TarWriter prefix = parts.join('/') end - if name.bytesize > 100 or prefix.empty? then + if name.bytesize > 100 or prefix.empty? raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long name (should be 100 or less)") end - if prefix.bytesize > 155 then + if prefix.bytesize > 155 raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long base path (should be 155 or less)") end end diff --git a/lib/rubygems/package_task.rb b/lib/rubygems/package_task.rb index d554e3697b..a11d09fb21 100644 --- a/lib/rubygems/package_task.rb +++ b/lib/rubygems/package_task.rb @@ -126,4 +126,3 @@ class Gem::PackageTask < Rake::PackageTask end end - diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index 02332cef80..ed680d6553 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -25,7 +25,7 @@ class Gem::PathSupport def initialize(env) @home = env["GEM_HOME"] || Gem.default_dir - if File::ALT_SEPARATOR then + if File::ALT_SEPARATOR @home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) end @@ -43,7 +43,7 @@ class Gem::PathSupport ## # Split the Gem search path (as reported by Gem.path). - def split_gem_path gpaths, home + def split_gem_path(gpaths, home) # FIX: it should be [home, *path], not [*path, home] gem_path = [] @@ -56,7 +56,7 @@ class Gem::PathSupport gem_path += default_path end - if File::ALT_SEPARATOR then + if File::ALT_SEPARATOR gem_path.map! do |this_path| this_path.gsub File::ALT_SEPARATOR, File::SEPARATOR end diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 1019fc22b9..f8fe4dad54 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -56,7 +56,7 @@ class Gem::Platform when String then arch = arch.split '-' - if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu + if arch.length > 2 and arch.last !~ /\d/ # reassemble x86-linux-gnu extra = arch.pop arch.last << "-#{extra}" end @@ -68,7 +68,7 @@ class Gem::Platform else cpu end - if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ then # for command-line + if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ # for command-line @os, @version = arch return end @@ -203,4 +203,3 @@ class Gem::Platform CURRENT = 'current'.freeze end - diff --git a/lib/rubygems/psych_tree.rb b/lib/rubygems/psych_tree.rb index 41a7314b53..6f399a289e 100644 --- a/lib/rubygems/psych_tree.rb +++ b/lib/rubygems/psych_tree.rb @@ -18,7 +18,7 @@ module Gem end # This is ported over from the yaml_tree in 1.9.3 - def format_time time + def format_time(time) if time.utc? time.strftime("%Y-%m-%d %H:%M:%S.%9N Z") else diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 7c4f3f9a6f..446bed3c72 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -97,7 +97,7 @@ class Gem::RemoteFetcher # Should probably be integrated with #download below, but that will be a # larger, more encompassing effort. -erikh - def download_to_cache dependency + def download_to_cache(dependency) found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dependency return if found.empty? @@ -114,9 +114,9 @@ class Gem::RemoteFetcher def download(spec, source_uri, install_dir = Gem.dir) cache_dir = - if Dir.pwd == install_dir then # see fetch_command + if Dir.pwd == install_dir # see fetch_command install_dir - elsif File.writable? install_dir then + elsif File.writable? install_dir File.join install_dir, "cache" else File.join Gem.user_dir, "cache" @@ -149,7 +149,7 @@ class Gem::RemoteFetcher # REFACTOR: be sure to clean up fake fetcher when you do this... cleaner case scheme when 'http', 'https', 's3' then - unless File.exist? local_gem_path then + unless File.exist? local_gem_path begin verbose "Downloading gem #{gem_file_name}" @@ -183,7 +183,7 @@ class Gem::RemoteFetcher verbose "Using local gem #{local_gem_path}" when nil then # TODO test for local overriding cache source_path = if Gem.win_platform? && source_uri.scheme && - !source_uri.path.include?(':') then + !source_uri.path.include?(':') "#{source_uri.scheme}:#{source_uri.path}" else source_uri.path @@ -209,14 +209,14 @@ class Gem::RemoteFetcher ## # File Fetcher. Dispatched by +fetch_path+. Use it instead. - def fetch_file uri, *_ + def fetch_file(uri, *_) Gem.read_binary correct_for_windows_path uri.path end ## # HTTP Fetcher. Dispatched by +fetch_path+. Use it instead. - def fetch_http uri, last_modified = nil, head = false, depth = 0 + def fetch_http(uri, last_modified = nil, head = false, depth = 0) fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get response = request uri, fetch_type, last_modified do |req| headers.each { |k,v| req.add_field(k,v) } @@ -291,7 +291,7 @@ class Gem::RemoteFetcher # Downloads +uri+ to +path+ if necessary. If no path is given, it just # passes the data. - def cache_update_path uri, path = nil, update = true + def cache_update_path(uri, path = nil, update = true) mtime = path && File.stat(path).mtime rescue nil data = fetch_path(uri, mtime) @@ -375,11 +375,11 @@ class Gem::RemoteFetcher private - def proxy_for proxy, uri + def proxy_for(proxy, uri) Gem::Request.proxy_uri(proxy || Gem::Request.get_proxy_from_env(uri.scheme)) end - def pools_for proxy + def pools_for(proxy) @pool_lock.synchronize do @pools[proxy] ||= Gem::Request::ConnectionPools.new proxy, @cert_files end diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb index b6674281d1..fb164d79cf 100644 --- a/lib/rubygems/request.rb +++ b/lib/rubygems/request.rb @@ -10,7 +10,7 @@ class Gem::Request ### # Legacy. This is used in tests. - def self.create_with_proxy uri, request_class, last_modified, proxy # :nodoc: + def self.create_with_proxy(uri, request_class, last_modified, proxy) # :nodoc: cert_files = get_cert_files proxy ||= get_proxy_from_env(uri.scheme) pool = ConnectionPools.new proxy_uri(proxy), cert_files @@ -18,7 +18,7 @@ class Gem::Request new(uri, request_class, last_modified, pool.pool_for(uri)) end - def self.proxy_uri proxy # :nodoc: + def self.proxy_uri(proxy) # :nodoc: case proxy when :no_proxy then nil when URI::HTTP then proxy @@ -51,7 +51,7 @@ class Gem::Request Gem.configuration.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER store = OpenSSL::X509::Store.new - if Gem.configuration.ssl_client_cert then + if Gem.configuration.ssl_client_cert pem = File.read Gem.configuration.ssl_client_cert connection.cert = OpenSSL::X509::Certificate.new pem connection.key = OpenSSL::PKey::RSA.new pem @@ -85,7 +85,7 @@ class Gem::Request 'Unable to require openssl, install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources') end - def self.verify_certificate store_context + def self.verify_certificate(store_context) depth = store_context.error_depth error = store_context.error_string number = store_context.error @@ -98,7 +98,7 @@ class Gem::Request ui.alert_error extra_message if extra_message end - def self.verify_certificate_message error_number, cert + def self.verify_certificate_message(error_number, cert) return unless cert case error_number when OpenSSL::X509::V_ERR_CERT_HAS_EXPIRED then @@ -139,7 +139,7 @@ class Gem::Request def fetch request = @request_class.new @uri.request_uri - unless @uri.nil? || @uri.user.nil? || @uri.user.empty? then + unless @uri.nil? || @uri.user.nil? || @uri.user.empty? request.basic_auth Gem::UriFormatter.new(@uri.user).unescape, Gem::UriFormatter.new(@uri.password).unescape end @@ -148,7 +148,7 @@ class Gem::Request request.add_field 'Connection', 'keep-alive' request.add_field 'Keep-Alive', '30' - if @last_modified then + if @last_modified request.add_field 'If-Modified-Since', @last_modified.httpdate end @@ -161,7 +161,7 @@ class Gem::Request # Returns a proxy URI for the given +scheme+ if one is set in the # environment variables. - def self.get_proxy_from_env scheme = 'http' + def self.get_proxy_from_env(scheme = 'http') _scheme = scheme.downcase _SCHEME = scheme.upcase env_proxy = ENV["#{_scheme}_proxy"] || ENV["#{_SCHEME}_PROXY"] @@ -173,7 +173,7 @@ class Gem::Request uri = URI(Gem::UriFormatter.new(env_proxy).normalize) - if uri and uri.user.nil? and uri.password.nil? then + if uri and uri.user.nil? and uri.password.nil? user = ENV["#{_scheme}_proxy_user"] || ENV["#{_SCHEME}_PROXY_USER"] password = ENV["#{_scheme}_proxy_pass"] || ENV["#{_SCHEME}_PROXY_PASS"] @@ -184,7 +184,7 @@ class Gem::Request uri end - def perform_request request # :nodoc: + def perform_request(request) # :nodoc: connection = connection_for @uri retried = false @@ -276,9 +276,9 @@ class Gem::Request ruby_version += 'dev' if RUBY_PATCHLEVEL == -1 ua << " Ruby/#{ruby_version} (#{RUBY_RELEASE_DATE}" - if RUBY_PATCHLEVEL >= 0 then + if RUBY_PATCHLEVEL >= 0 ua << " patchlevel #{RUBY_PATCHLEVEL}" - elsif defined?(RUBY_REVISION) then + elsif defined?(RUBY_REVISION) ua << " revision #{RUBY_REVISION}" end ua << ")" diff --git a/lib/rubygems/request/connection_pools.rb b/lib/rubygems/request/connection_pools.rb index f95dd8aabf..c02f083b63 100644 --- a/lib/rubygems/request/connection_pools.rb +++ b/lib/rubygems/request/connection_pools.rb @@ -8,19 +8,19 @@ class Gem::Request::ConnectionPools # :nodoc: attr_accessor :client end - def initialize proxy_uri, cert_files + def initialize(proxy_uri, cert_files) @proxy_uri = proxy_uri @cert_files = cert_files @pools = {} @pool_mutex = Mutex.new end - def pool_for uri + def pool_for(uri) http_args = net_http_args(uri, @proxy_uri) key = http_args + [https?(uri)] @pool_mutex.synchronize do @pools[key] ||= - if https? uri then + if https? uri Gem::Request::HTTPSPool.new(http_args, @cert_files, @proxy_uri) else Gem::Request::HTTPPool.new(http_args, @cert_files, @proxy_uri) @@ -45,11 +45,11 @@ class Gem::Request::ConnectionPools # :nodoc: env_no_proxy.split(/\s*,\s*/) end - def https? uri + def https?(uri) uri.scheme.downcase == 'https' end - def no_proxy? host, env_no_proxy + def no_proxy?(host, env_no_proxy) host = host.downcase env_no_proxy.any? do |pattern| @@ -73,7 +73,7 @@ class Gem::Request::ConnectionPools # :nodoc: end end - def net_http_args uri, proxy_uri + def net_http_args(uri, proxy_uri) # URI::Generic#hostname was added in ruby 1.9.3, use it if exists, otherwise # don't support IPv6 literals and use host. hostname = uri.respond_to?(:hostname) ? uri.hostname : uri.host @@ -81,7 +81,7 @@ class Gem::Request::ConnectionPools # :nodoc: no_proxy = get_no_proxy_from_env - if proxy_uri and not no_proxy?(hostname, no_proxy) then + if proxy_uri and not no_proxy?(hostname, no_proxy) proxy_hostname = proxy_uri.respond_to?(:hostname) ? proxy_uri.hostname : proxy_uri.host net_http_args + [ proxy_hostname, @@ -89,7 +89,7 @@ class Gem::Request::ConnectionPools # :nodoc: Gem::UriFormatter.new(proxy_uri.user).unescape, Gem::UriFormatter.new(proxy_uri.password).unescape, ] - elsif no_proxy? hostname, no_proxy then + elsif no_proxy? hostname, no_proxy net_http_args + [nil, nil] else net_http_args @@ -97,4 +97,3 @@ class Gem::Request::ConnectionPools # :nodoc: end end - diff --git a/lib/rubygems/request/http_pool.rb b/lib/rubygems/request/http_pool.rb index bfcd15399d..a85fc2bdf6 100644 --- a/lib/rubygems/request/http_pool.rb +++ b/lib/rubygems/request/http_pool.rb @@ -8,7 +8,7 @@ class Gem::Request::HTTPPool # :nodoc: attr_reader :cert_files, :proxy_uri - def initialize http_args, cert_files, proxy_uri + def initialize(http_args, cert_files, proxy_uri) @http_args = http_args @cert_files = cert_files @proxy_uri = proxy_uri @@ -20,7 +20,7 @@ class Gem::Request::HTTPPool # :nodoc: @queue.pop || make_connection end - def checkin connection + def checkin(connection) @queue.push connection end @@ -39,10 +39,9 @@ class Gem::Request::HTTPPool # :nodoc: setup_connection Gem::Request::ConnectionPools.client.new(*@http_args) end - def setup_connection connection + def setup_connection(connection) connection.start connection end end - diff --git a/lib/rubygems/request/https_pool.rb b/lib/rubygems/request/https_pool.rb index e82c2440e1..50f42d9e0d 100644 --- a/lib/rubygems/request/https_pool.rb +++ b/lib/rubygems/request/https_pool.rb @@ -2,10 +2,8 @@ class Gem::Request::HTTPSPool < Gem::Request::HTTPPool # :nodoc: private - def setup_connection connection + def setup_connection(connection) Gem::Request.configure_connection_for_https(connection, @cert_files) super end end - - diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb index c68e40ee9e..6017d15d13 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -91,7 +91,7 @@ class Gem::RequestSet # # set = Gem::RequestSet.new nokogiri, pg - def initialize *deps + def initialize(*deps) @dependencies = deps @always_install = [] @@ -119,8 +119,8 @@ class Gem::RequestSet ## # Declare that a gem of name +name+ with +reqs+ requirements is needed. - def gem name, *reqs - if dep = @dependency_names[name] then + def gem(name, *reqs) + if dep = @dependency_names[name] dep.requirement.concat reqs else dep = Gem::Dependency.new name, *reqs @@ -132,7 +132,7 @@ class Gem::RequestSet ## # Add +deps+ Gem::Dependency objects to the set. - def import deps + def import(deps) @dependencies.concat deps end @@ -143,7 +143,7 @@ class Gem::RequestSet # The +installer+ will be +nil+ if a gem matching the request was already # installed. - def install options, &block # :yields: request, installer + def install(options, &block) # :yields: request, installer if dir = options[:install_dir] requests = install_into dir, false, options, &block return requests @@ -181,10 +181,10 @@ class Gem::RequestSet # Install requested gems after they have been downloaded sorted_requests.each do |req| - if req.installed? then + if req.installed? req.spec.spec.build_extensions - if @always_install.none? { |spec| spec == req.spec.spec } then + if @always_install.none? { |spec| spec == req.spec.spec } yield req, nil if block_given? next end @@ -230,7 +230,7 @@ class Gem::RequestSet # If +:without_groups+ is given in the +options+, those groups in the gem # dependencies file are not used. See Gem::Installer for other +options+. - def install_from_gemdeps options, &block + def install_from_gemdeps(options, &block) gemdeps = options[:gemdeps] @install_dir = options[:install_dir] || Gem.dir @@ -255,7 +255,7 @@ class Gem::RequestSet else installed = install options, &block - if options.fetch :lock, true then + if options.fetch :lock, true lockfile = Gem::RequestSet::Lockfile.build self, gemdeps, gem_deps_api.dependencies lockfile.write @@ -265,7 +265,7 @@ class Gem::RequestSet end end - def install_into dir, force = true, options = {} + def install_into(dir, force = true, options = {}) gem_home, ENV['GEM_HOME'] = ENV['GEM_HOME'], dir existing = force ? [] : specs_in(dir) @@ -283,7 +283,7 @@ class Gem::RequestSet sorted_requests.each do |request| spec = request.spec - if existing.find { |s| s.full_name == spec.full_name } then + if existing.find { |s| s.full_name == spec.full_name } yield request, nil if block_given? next end @@ -305,7 +305,7 @@ class Gem::RequestSet ## # Call hooks on installed gems - def install_hooks requests, options + def install_hooks(requests, options) specs = requests.map do |request| case request when Gem::Resolver::ActivationRequest then @@ -327,7 +327,7 @@ class Gem::RequestSet ## # Load a dependency management file. - def load_gemdeps path, without_groups = [], installing = false + def load_gemdeps(path, without_groups = [], installing = false) @git_set = Gem::Resolver::GitSet.new @vendor_set = Gem::Resolver::VendorSet.new @source_set = Gem::Resolver::SourceSet.new @@ -348,29 +348,29 @@ class Gem::RequestSet gf.load end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[RequestSet:', ']' do q.breakable - if @remote then + if @remote q.text 'remote' q.breakable end - if @prerelease then + if @prerelease q.text 'prerelease' q.breakable end - if @development_shallow then + if @development_shallow q.text 'shallow development' q.breakable - elsif @development then + elsif @development q.text 'development' q.breakable end - if @soft_missing then + if @soft_missing q.text 'soft missing' end @@ -394,7 +394,7 @@ class Gem::RequestSet # Resolve the requested dependencies and return an Array of Specification # objects to be activated. - def resolve set = Gem::Resolver::BestSet.new + def resolve(set = Gem::Resolver::BestSet.new) @sets << set @sets << @git_set @sets << @vendor_set @@ -443,17 +443,17 @@ class Gem::RequestSet @specs ||= @requests.map { |r| r.full_spec } end - def specs_in dir + def specs_in(dir) Gem::Util.glob_files_in_dir("*.gemspec", File.join(dir, "specifications")).map do |g| Gem::Specification.load g end end - def tsort_each_node &block # :nodoc: + def tsort_each_node(&block) # :nodoc: @requests.each(&block) end - def tsort_each_child node # :nodoc: + def tsort_each_child(node) # :nodoc: node.spec.dependencies.each do |dep| next if dep.type == :development and not @development @@ -461,7 +461,7 @@ class Gem::RequestSet dep.match? r.spec.name, r.spec.version, @prerelease } - unless match then + unless match next if dep.type == :development and @development_shallow next if @soft_missing raise Gem::DependencyError, diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb index 177079da03..3892e7aa5f 100644 --- a/lib/rubygems/request_set/gem_dependency_api.rb +++ b/lib/rubygems/request_set/gem_dependency_api.rb @@ -191,7 +191,7 @@ class Gem::RequestSet::GemDependencyAPI # Creates a new GemDependencyAPI that will add dependencies to the # Gem::RequestSet +set+ based on the dependency API description in +path+. - def initialize set, path + def initialize(set, path) @set = set @path = path @@ -228,7 +228,7 @@ class Gem::RequestSet::GemDependencyAPI # Adds +dependencies+ to the request set if any of the +groups+ are allowed. # This is used for gemspec dependencies. - def add_dependencies groups, dependencies # :nodoc: + def add_dependencies(groups, dependencies) # :nodoc: return unless (groups & @without_groups).empty? dependencies.each do |dep| @@ -241,7 +241,7 @@ class Gem::RequestSet::GemDependencyAPI ## # Finds a gemspec with the given +name+ that lives at +path+. - def find_gemspec name, path # :nodoc: + def find_gemspec(name, path) # :nodoc: glob = File.join path, "#{name}.gemspec" spec_files = Dir[glob] @@ -269,7 +269,7 @@ class Gem::RequestSet::GemDependencyAPI # In installing mode certain restrictions are ignored such as ruby version # mismatch checks. - def installing= installing # :nodoc: + def installing=(installing) # :nodoc: @installing = installing end @@ -353,7 +353,7 @@ class Gem::RequestSet::GemDependencyAPI # tag: :: # Use the given tag for git:, gist: and github: dependencies. - def gem name, *requirements + def gem(name, *requirements) options = requirements.pop if requirements.last.kind_of?(Hash) options ||= {} @@ -369,9 +369,9 @@ class Gem::RequestSet::GemDependencyAPI duplicate = @dependencies.include? name @dependencies[name] = - if requirements.empty? and not source_set then + if requirements.empty? and not source_set Gem::Requirement.default - elsif source_set then + elsif source_set Gem::Requirement.source_set else Gem::Requirement.create requirements @@ -387,7 +387,7 @@ class Gem::RequestSet::GemDependencyAPI gem_requires name, options - if duplicate then + if duplicate warn <<-WARNING Gem dependencies file #{@path} requires #{name} more than once. WARNING @@ -401,8 +401,8 @@ Gem dependencies file #{@path} requires #{name} more than once. # # Returns +true+ if the gist or git option was handled. - def gem_git name, options # :nodoc: - if gist = options.delete(:gist) then + def gem_git(name, options) # :nodoc: + if gist = options.delete(:gist) options[:git] = "https://gist.github.com/#{gist}.git" end @@ -424,7 +424,7 @@ Gem dependencies file #{@path} requires #{name} more than once. # # Returns reference for the git gem. - def gem_git_reference options # :nodoc: + def gem_git_reference(options) # :nodoc: ref = options.delete :ref branch = options.delete :branch tag = options.delete :tag @@ -457,7 +457,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # # Returns +true+ if the custom source option was handled. - def gem_git_source name, options # :nodoc: + def gem_git_source(name, options) # :nodoc: return unless git_source = (@git_sources.keys & options.keys).last source_callback = @git_sources[git_source] @@ -478,7 +478,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # Handles the :group and :groups +options+ for the gem with the given # +name+. - def gem_group name, options # :nodoc: + def gem_group(name, options) # :nodoc: g = options.delete :group all_groups = g ? Array(g) : [] @@ -497,7 +497,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # # Returns +true+ if the path option was handled. - def gem_path name, options # :nodoc: + def gem_path(name, options) # :nodoc: return unless directory = options.delete(:path) pin_gem_source name, :path, directory @@ -514,7 +514,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # # Returns +true+ if the source option was handled. - def gem_source name, options # :nodoc: + def gem_source(name, options) # :nodoc: return unless source = options.delete(:source) pin_gem_source name, :source, source @@ -530,7 +530,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # Handles the platforms: option from +options+. Returns true if the # platform matches the current platform. - def gem_platforms options # :nodoc: + def gem_platforms(options) # :nodoc: platform_names = Array(options.delete :platform) platform_names.concat Array(options.delete :platforms) platform_names.concat @current_platforms if @current_platforms @@ -543,7 +543,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta next false unless Gem::Platform.match platform - if engines = ENGINE_MAP[platform_name] then + if engines = ENGINE_MAP[platform_name] next false unless engines.include? Gem.ruby_engine end @@ -564,9 +564,9 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # Records the require: option from +options+ and adds those files, or the # default file to the require list for +name+. - def gem_requires name, options # :nodoc: - if options.include? :require then - if requires = options.delete(:require) then + def gem_requires(name, options) # :nodoc: + if options.include? :require + if requires = options.delete(:require) @requires[name].concat Array requires end else @@ -587,7 +587,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # gem 'activerecord' # end - def git repository + def git(repository) @current_repository = repository yield @@ -601,7 +601,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # for use in gems built from git repositories. You must provide a block # that accepts a git repository name for expansion. - def git_source name, &callback + def git_source(name, &callback) @git_sources[name] = callback end @@ -634,7 +634,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # The group to add development dependencies to. By default this is # :development. Only one group may be specified. - def gemspec options = {} + def gemspec(options = {}) name = options.delete(:name) || '{,*}' path = options.delete(:path) || '.' development_group = options.delete(:development_group) || :development @@ -679,7 +679,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # development`. See `gem help install` and `gem help gem_dependencies` for # further details. - def group *groups + def group(*groups) @current_groups = groups yield @@ -692,7 +692,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # Pins the gem +name+ to the given +source+. Adding a gem with the same # name from a different +source+ will raise an exception. - def pin_gem_source name, type = :default, source = nil + def pin_gem_source(name, type = :default, source = nil) source_description = case type when :default then '(default)' @@ -754,7 +754,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # NOTE: There is inconsistency in what environment a platform matches. You # may need to read the source to know the exact details. - def platform *platforms + def platform(*platforms) @current_platforms = platforms yield @@ -781,7 +781,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # version. This matching is performed by using the RUBY_ENGINE and # engine_specific VERSION constants. (For JRuby, JRUBY_VERSION). - def ruby version, options = {} + def ruby(version, options = {}) engine = options[:engine] engine_version = options[:engine_version] @@ -791,24 +791,24 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta return true if @installing - unless RUBY_VERSION == version then + unless RUBY_VERSION == version message = "Your Ruby version is #{RUBY_VERSION}, " + "but your #{gem_deps_file} requires #{version}" raise Gem::RubyVersionMismatch, message end - if engine and engine != Gem.ruby_engine then + if engine and engine != Gem.ruby_engine message = "Your Ruby engine is #{Gem.ruby_engine}, " + "but your #{gem_deps_file} requires #{engine}" raise Gem::RubyVersionMismatch, message end - if engine_version then + if engine_version my_engine_version = Object.const_get "#{Gem.ruby_engine.upcase}_VERSION" - if engine_version != my_engine_version then + if engine_version != my_engine_version message = "Your Ruby engine version is #{Gem.ruby_engine} #{my_engine_version}, " + "but your #{gem_deps_file} requires #{engine} #{engine_version}" @@ -834,7 +834,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta # * The +prepend:+ option is not supported. If you wish to order sources # then list them in your preferred order. - def source url + def source(url) Gem.sources.clear if @default_sources @default_sources = false diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb index 76ad17d486..1b374660f0 100644 --- a/lib/rubygems/request_set/lockfile.rb +++ b/lib/rubygems/request_set/lockfile.rb @@ -29,7 +29,7 @@ class Gem::RequestSet::Lockfile # Raises a ParseError with the given +message+ which was encountered at a # +line+ and +column+ while parsing. - def initialize message, column, line, path + def initialize(message, column, line, path) @line = line @column = column @path = path @@ -41,13 +41,13 @@ class Gem::RequestSet::Lockfile # Creates a new Lockfile for the given +request_set+ and +gem_deps_file+ # location. - def self.build request_set, gem_deps_file, dependencies = nil + def self.build(request_set, gem_deps_file, dependencies = nil) request_set.resolve dependencies ||= requests_to_deps request_set.sorted_requests new request_set, gem_deps_file, dependencies end - def self.requests_to_deps requests # :nodoc: + def self.requests_to_deps(requests) # :nodoc: deps = {} requests.each do |request| @@ -56,7 +56,7 @@ class Gem::RequestSet::Lockfile requirement = request.request.dependency.requirement deps[name] = if [Gem::Resolver::VendorSpecification, - Gem::Resolver::GitSpecification].include? spec.class then + Gem::Resolver::GitSpecification].include? spec.class Gem::Requirement.source_set else requirement @@ -71,7 +71,7 @@ class Gem::RequestSet::Lockfile attr_reader :platforms - def initialize request_set, gem_deps_file, dependencies + def initialize(request_set, gem_deps_file, dependencies) @set = request_set @dependencies = dependencies @gem_deps_file = File.expand_path(gem_deps_file) @@ -82,7 +82,7 @@ class Gem::RequestSet::Lockfile @platforms = [] end - def add_DEPENDENCIES out # :nodoc: + def add_DEPENDENCIES(out) # :nodoc: out << "DEPENDENCIES" out.concat @dependencies.sort_by { |name,| name }.map { |name, requirement| @@ -92,7 +92,7 @@ class Gem::RequestSet::Lockfile out << nil end - def add_GEM out, spec_groups # :nodoc: + def add_GEM(out, spec_groups) # :nodoc: return if spec_groups.empty? source_groups = spec_groups.values.flatten.group_by do |request| @@ -122,7 +122,7 @@ class Gem::RequestSet::Lockfile end end - def add_GIT out, git_requests + def add_GIT(out, git_requests) return if git_requests.empty? by_repository_revision = git_requests.group_by do |request| @@ -148,11 +148,11 @@ class Gem::RequestSet::Lockfile end end - def relative_path_from dest, base # :nodoc: + def relative_path_from(dest, base) # :nodoc: dest = File.expand_path(dest) base = File.expand_path(base) - if dest.index(base) == 0 then + if dest.index(base) == 0 offset = dest[base.size+1..-1] return '.' unless offset @@ -163,7 +163,7 @@ class Gem::RequestSet::Lockfile end end - def add_PATH out, path_requests # :nodoc: + def add_PATH(out, path_requests) # :nodoc: return if path_requests.empty? out << "PATH" @@ -178,7 +178,7 @@ class Gem::RequestSet::Lockfile out << nil end - def add_PLATFORMS out # :nodoc: + def add_PLATFORMS(out) # :nodoc: out << "PLATFORMS" platforms = requests.map { |request| request.spec.platform }.uniq diff --git a/lib/rubygems/request_set/lockfile/parser.rb b/lib/rubygems/request_set/lockfile/parser.rb index 368b56e6e6..0fe0405e32 100644 --- a/lib/rubygems/request_set/lockfile/parser.rb +++ b/lib/rubygems/request_set/lockfile/parser.rb @@ -3,7 +3,7 @@ class Gem::RequestSet::Lockfile::Parser ### # Parses lockfiles - def initialize tokenizer, set, platforms, filename = nil + def initialize(tokenizer, set, platforms, filename = nil) @tokens = tokenizer @filename = filename @set = set @@ -41,10 +41,10 @@ class Gem::RequestSet::Lockfile::Parser ## # Gets the next token for a Lockfile - def get expected_types = nil, expected_value = nil # :nodoc: + def get(expected_types = nil, expected_value = nil) # :nodoc: token = @tokens.shift - if expected_types and not Array(expected_types).include? token.type then + if expected_types and not Array(expected_types).include? token.type unget token message = "unexpected token [#{token.type.inspect}, #{token.value.inspect}], " + @@ -53,7 +53,7 @@ class Gem::RequestSet::Lockfile::Parser raise Gem::RequestSet::Lockfile::ParseError.new message, token.column, token.line, @filename end - if expected_value and expected_value != token.value then + if expected_value and expected_value != token.value unget token message = "unexpected token [#{token.type.inspect}, #{token.value.inspect}], " + @@ -93,7 +93,7 @@ class Gem::RequestSet::Lockfile::Parser get :r_paren - if peek[0] == :bang then + if peek[0] == :bang requirements.clear requirements << pinned_requirement(token.value) @@ -144,7 +144,7 @@ class Gem::RequestSet::Lockfile::Parser type = token.type data = token.value - if type == :text and column == 4 then + if type == :text and column == 4 version, platform = data.split '-', 2 platform = @@ -183,7 +183,7 @@ class Gem::RequestSet::Lockfile::Parser type = peek.type value = peek.value - if type == :entry and %w[branch ref tag].include? value then + if type == :entry and %w[branch ref tag].include? value get get :text @@ -214,7 +214,7 @@ class Gem::RequestSet::Lockfile::Parser type = token.type data = token.value - if type == :text and column == 4 then + if type == :text and column == 4 last_spec = set.add_git_spec name, data, repository, revision, true else dependency = parse_dependency name, data @@ -261,7 +261,7 @@ class Gem::RequestSet::Lockfile::Parser type = token.type data = token.value - if type == :text and column == 4 then + if type == :text and column == 4 last_spec = set.add_vendor_gem name, directory else dependency = parse_dependency name, data @@ -294,7 +294,7 @@ class Gem::RequestSet::Lockfile::Parser # Parses the requirements following the dependency +name+ and the +op+ for # the first token of the requirements and returns a Gem::Dependency object. - def parse_dependency name, op # :nodoc: + def parse_dependency(name, op) # :nodoc: return Gem::Dependency.new name, op unless peek[0] == :text version = get(:text).value @@ -314,7 +314,7 @@ class Gem::RequestSet::Lockfile::Parser private - def skip type # :nodoc: + def skip(type) # :nodoc: @tokens.skip type end @@ -325,7 +325,7 @@ class Gem::RequestSet::Lockfile::Parser @tokens.peek end - def pinned_requirement name # :nodoc: + def pinned_requirement(name) # :nodoc: requirement = Gem::Dependency.new name specification = @set.sets.flat_map { |set| set.find_all(requirement) @@ -337,7 +337,7 @@ class Gem::RequestSet::Lockfile::Parser ## # Ungets the last token retrieved by #get - def unget token # :nodoc: + def unget(token) # :nodoc: @tokens.unshift token end end diff --git a/lib/rubygems/request_set/lockfile/tokenizer.rb b/lib/rubygems/request_set/lockfile/tokenizer.rb index a758743dda..bb69c85fb4 100644 --- a/lib/rubygems/request_set/lockfile/tokenizer.rb +++ b/lib/rubygems/request_set/lockfile/tokenizer.rb @@ -5,11 +5,11 @@ class Gem::RequestSet::Lockfile::Tokenizer Token = Struct.new :type, :value, :column, :line EOF = Token.new :EOF - def self.from_file file + def self.from_file(file) new File.read(file), file end - def initialize input, filename = nil, line = 0, pos = 0 + def initialize(input, filename = nil, line = 0, pos = 0) @line = line @line_pos = pos @tokens = [] @@ -17,7 +17,7 @@ class Gem::RequestSet::Lockfile::Tokenizer tokenize input end - def make_parser set, platforms + def make_parser(set, platforms) Gem::RequestSet::Lockfile::Parser.new self, set, platforms, @filename end @@ -25,7 +25,7 @@ class Gem::RequestSet::Lockfile::Tokenizer @tokens.map { |token| [token.type, token.value, token.column, token.line] } end - def skip type + def skip(type) @tokens.shift while not @tokens.empty? and peek.type == type end @@ -33,7 +33,7 @@ class Gem::RequestSet::Lockfile::Tokenizer # Calculates the column (by byte) and the line of the current token based on # +byte_offset+. - def token_pos byte_offset # :nodoc: + def token_pos(byte_offset) # :nodoc: [byte_offset - @line_pos, @line] end @@ -41,7 +41,7 @@ class Gem::RequestSet::Lockfile::Tokenizer @tokens.empty? end - def unshift token + def unshift(token) @tokens.unshift token end @@ -56,7 +56,7 @@ class Gem::RequestSet::Lockfile::Tokenizer private - def tokenize input + def tokenize(input) require 'strscan' s = StringScanner.new input @@ -65,7 +65,7 @@ class Gem::RequestSet::Lockfile::Tokenizer pos = s.pos if leading_whitespace = s.scan(/ +/) - if s.scan(/[<|=>]{7}/) then + if s.scan(/[<|=>]{7}/) message = "your #{@filename} contains merge conflict markers" column, line = token_pos pos @@ -80,7 +80,7 @@ class Gem::RequestSet::Lockfile::Tokenizer @line += 1 token when s.scan(/[A-Z]+/) then - if leading_whitespace then + if leading_whitespace text = s.matched text += s.scan(/[^\s)]*/).to_s # in case of no match Token.new(:text, text, *token_pos(pos)) diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb index 93bfe7d022..1a73274c01 100644 --- a/lib/rubygems/requirement.rb +++ b/lib/rubygems/requirement.rb @@ -32,7 +32,7 @@ class Gem::Requirement ## # A regular expression that matches a requirement - PATTERN = /\A#{PATTERN_RAW}\z/ + PATTERN = /\A#{PATTERN_RAW}\z/.freeze ## # The default requirement matches any version @@ -51,7 +51,7 @@ class Gem::Requirement # If the input is "weird", the default version requirement is # returned. - def self.create *inputs + def self.create(*inputs) return new inputs if inputs.length > 1 input = inputs.shift @@ -64,7 +64,7 @@ class Gem::Requirement when '!' then source_set else - if input.respond_to? :to_str then + if input.respond_to? :to_str new [input.to_str] else default @@ -98,7 +98,7 @@ class Gem::Requirement # parse("1.0") # => ["=", Gem::Version.new("1.0")] # parse(Gem::Version.new("1.0")) # => ["=, Gem::Version.new("1.0")] - def self.parse obj + def self.parse(obj) return ["=", obj] if Gem::Version === obj unless PATTERN =~ obj.to_s @@ -124,7 +124,7 @@ class Gem::Requirement # requirements are ignored. An empty set of +requirements+ is the # same as ">= 0". - def initialize *requirements + def initialize(*requirements) requirements = requirements.flatten requirements.compact! requirements.uniq! @@ -140,7 +140,7 @@ class Gem::Requirement ## # Concatenates the +new+ requirements onto this requirement. - def concat new + def concat(new) new = new.flatten new.compact! new.uniq! @@ -198,7 +198,7 @@ class Gem::Requirement [@requirements] end - def marshal_load array # :nodoc: + def marshal_load(array) # :nodoc: @requirements = array[0] fix_syck_default_key_in_requirements @@ -213,7 +213,7 @@ class Gem::Requirement fix_syck_default_key_in_requirements end - def init_with coder # :nodoc: + def init_with(coder) # :nodoc: yaml_initialize coder.tag, coder.map end @@ -221,7 +221,7 @@ class Gem::Requirement ["@requirements"] end - def encode_with coder # :nodoc: + def encode_with(coder) # :nodoc: coder.add 'requirements', @requirements end @@ -233,7 +233,7 @@ class Gem::Requirement requirements.any? { |r| r.last.prerelease? } end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 1, 'Gem::Requirement.new(', ')' do q.pp as_list end @@ -242,7 +242,7 @@ class Gem::Requirement ## # True if +version+ satisfies this Requirement. - def satisfied_by? version + def satisfied_by?(version) raise ArgumentError, "Need a Gem::Version: #{version.inspect}" unless Gem::Version === version # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey @@ -265,7 +265,7 @@ class Gem::Requirement as_list.join ", " end - def == other # :nodoc: + def ==(other) # :nodoc: return unless Gem::Requirement === other requirements == other.requirements end diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 866998dc59..46276f3260 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -59,7 +59,7 @@ class Gem::Resolver # uniform manner. If one of the +sets+ is itself a ComposedSet its sets are # flattened into the result ComposedSet. - def self.compose_sets *sets + def self.compose_sets(*sets) sets.compact! sets = sets.map do |set| @@ -87,7 +87,7 @@ class Gem::Resolver # Creates a Resolver that queries only against the already installed gems # for the +needed+ dependencies. - def self.for_current_gems needed + def self.for_current_gems(needed) new needed, Gem::Resolver::CurrentSet.new end @@ -99,7 +99,7 @@ class Gem::Resolver # satisfy the Dependencies. This defaults to IndexSet, which will query # rubygems.org. - def initialize needed, set = nil + def initialize(needed, set = nil) @set = set || Gem::Resolver::IndexSet.new @needed = needed @@ -112,14 +112,14 @@ class Gem::Resolver @stats = Gem::Resolver::Stats.new end - def explain stage, *data # :nodoc: + def explain(stage, *data) # :nodoc: return unless DEBUG_RESOLVER d = data.map { |x| x.pretty_inspect }.join(", ") $stderr.printf "%10s %s\n", stage.to_s.upcase, d end - def explain_list stage # :nodoc: + def explain_list(stage) # :nodoc: return unless DEBUG_RESOLVER data = yield @@ -133,7 +133,7 @@ class Gem::Resolver # # Returns the Specification and the ActivationRequest - def activation_request dep, possible # :nodoc: + def activation_request(dep, possible) # :nodoc: spec = possible.pop explain :activate, [spec.full_name, possible.size] @@ -145,7 +145,7 @@ class Gem::Resolver return spec, activation_request end - def requests s, act, reqs=[] # :nodoc: + def requests(s, act, reqs=[]) # :nodoc: return reqs if @ignore_dependencies s.fetch_development_dependencies if @development @@ -197,7 +197,7 @@ class Gem::Resolver # Extracts the specifications that may be able to fulfill +dependency+ and # returns those that match the local platform and all those that match. - def find_possible dependency # :nodoc: + def find_possible(dependency) # :nodoc: all = @set.find_all dependency if (skip_dep_gems = skip_gems[dependency.name]) && !skip_dep_gems.empty? @@ -216,7 +216,7 @@ class Gem::Resolver ## # Returns the gems in +specs+ that match the local platform. - def select_local_platforms specs # :nodoc: + def select_local_platforms(specs) # :nodoc: specs.select do |spec| Gem::Platform.installable? spec end diff --git a/lib/rubygems/resolver/activation_request.rb b/lib/rubygems/resolver/activation_request.rb index 135d75d6bc..b28e1bef32 100644 --- a/lib/rubygems/resolver/activation_request.rb +++ b/lib/rubygems/resolver/activation_request.rb @@ -22,13 +22,13 @@ class Gem::Resolver::ActivationRequest # +others_possible+ indicates that other specifications may also match this # activation request. - def initialize spec, request, others_possible = true + def initialize(spec, request, others_possible = true) @spec = spec @request = request @others_possible = others_possible end - def == other # :nodoc: + def ==(other) # :nodoc: case other when Gem::Specification @spec == other @@ -49,7 +49,7 @@ class Gem::Resolver::ActivationRequest ## # Downloads a gem at +path+ and returns the file path. - def download path + def download(path) Gem.ensure_gem_subdirectories path if @spec.respond_to? :sources @@ -97,7 +97,7 @@ class Gem::Resolver::ActivationRequest when false then # TODO remove at RubyGems 3 nil else - unless @others_possible.empty? then + unless @others_possible.empty? others = @others_possible.map { |s| s.full_name } " (others possible: #{others.join ', '})" end @@ -152,7 +152,7 @@ class Gem::Resolver::ActivationRequest @request.requester end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[Activation request', ']' do q.breakable q.pp @spec @@ -167,7 +167,7 @@ class Gem::Resolver::ActivationRequest q.breakable q.text 'others possible' else - unless @others_possible.empty? then + unless @others_possible.empty? q.breakable q.text 'others ' q.pp @others_possible.map { |s| s.full_name } diff --git a/lib/rubygems/resolver/api_set.rb b/lib/rubygems/resolver/api_set.rb index ee3046af63..6fd91e3b73 100644 --- a/lib/rubygems/resolver/api_set.rb +++ b/lib/rubygems/resolver/api_set.rb @@ -25,7 +25,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set # API URL +dep_uri+ which is described at # http://guides.rubygems.org/rubygems-org-api - def initialize dep_uri = 'https://rubygems.org/api/v1/dependencies' + def initialize(dep_uri = 'https://rubygems.org/api/v1/dependencies') super() dep_uri = URI dep_uri unless URI === dep_uri # for ruby 1.8 @@ -43,7 +43,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set # Return an array of APISpecification objects matching # DependencyRequest +req+. - def find_all req + def find_all(req) res = [] return res unless @remote @@ -65,7 +65,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set # A hint run by the resolver to allow the Set to fetch # data for DependencyRequests +reqs+. - def prefetch reqs + def prefetch(reqs) return unless @remote names = reqs.map { |r| r.dependency.name } needed = names - @data.keys - @to_fetch @@ -93,7 +93,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set end end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[APISet', ']' do q.breakable q.text "URI: #{@dep_uri}" @@ -107,7 +107,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set ## # Return data for all versions of the gem +name+. - def versions name # :nodoc: + def versions(name) # :nodoc: if @data.key?(name) return @data[name] end @@ -123,4 +123,3 @@ class Gem::Resolver::APISet < Gem::Resolver::Set end end - diff --git a/lib/rubygems/resolver/api_specification.rb b/lib/rubygems/resolver/api_specification.rb index c4e8a7cb54..9bbc095788 100644 --- a/lib/rubygems/resolver/api_specification.rb +++ b/lib/rubygems/resolver/api_specification.rb @@ -27,7 +27,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification end end - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and @set == other.set and @name == other.name and @@ -46,7 +46,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification Gem::Platform.match @platform end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[APISpecification', ']' do q.breakable q.text "name: #{name}" @@ -88,4 +88,3 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification end end - diff --git a/lib/rubygems/resolver/best_set.rb b/lib/rubygems/resolver/best_set.rb index 4479535abe..cc91b65c0b 100644 --- a/lib/rubygems/resolver/best_set.rb +++ b/lib/rubygems/resolver/best_set.rb @@ -10,7 +10,7 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet # Creates a BestSet for the given +sources+ or Gem::sources if none are # specified. +sources+ must be a Gem::SourceList. - def initialize sources = Gem.sources + def initialize(sources = Gem.sources) super() @sources = sources @@ -25,7 +25,7 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet end end - def find_all req # :nodoc: + def find_all(req) # :nodoc: pick_sets if @remote and @sets.empty? super @@ -35,13 +35,13 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet retry end - def prefetch reqs # :nodoc: + def prefetch(reqs) # :nodoc: pick_sets if @remote and @sets.empty? super end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[BestSet', ']' do q.breakable q.text 'sets:' @@ -58,7 +58,7 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet # # The calling method must retry the exception to repeat the lookup. - def replace_failed_api_set error # :nodoc: + def replace_failed_api_set(error) # :nodoc: uri = error.uri uri = URI uri unless URI === uri uri.query = nil @@ -76,4 +76,3 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet end end - diff --git a/lib/rubygems/resolver/composed_set.rb b/lib/rubygems/resolver/composed_set.rb index 0b65942dca..4baac9c75b 100644 --- a/lib/rubygems/resolver/composed_set.rb +++ b/lib/rubygems/resolver/composed_set.rb @@ -16,7 +16,7 @@ class Gem::Resolver::ComposedSet < Gem::Resolver::Set # Creates a new ComposedSet containing +sets+. Use # Gem::Resolver::compose_sets instead. - def initialize *sets + def initialize(*sets) super() @sets = sets @@ -26,7 +26,7 @@ class Gem::Resolver::ComposedSet < Gem::Resolver::Set # When +allow_prerelease+ is set to +true+ prereleases gems are allowed to # match dependencies. - def prerelease= allow_prerelease + def prerelease=(allow_prerelease) super sets.each do |set| @@ -37,7 +37,7 @@ class Gem::Resolver::ComposedSet < Gem::Resolver::Set ## # Sets the remote network access for all composed sets. - def remote= remote + def remote=(remote) super @sets.each { |set| set.remote = remote } @@ -50,7 +50,7 @@ class Gem::Resolver::ComposedSet < Gem::Resolver::Set ## # Finds all specs matching +req+ in all sets. - def find_all req + def find_all(req) @sets.map do |s| s.find_all req end.flatten @@ -59,9 +59,8 @@ class Gem::Resolver::ComposedSet < Gem::Resolver::Set ## # Prefetches +reqs+ in all sets. - def prefetch reqs + def prefetch(reqs) @sets.each { |s| s.prefetch(reqs) } end end - diff --git a/lib/rubygems/resolver/conflict.rb b/lib/rubygems/resolver/conflict.rb index 7997f92950..fb1e661b21 100644 --- a/lib/rubygems/resolver/conflict.rb +++ b/lib/rubygems/resolver/conflict.rb @@ -27,7 +27,7 @@ class Gem::Resolver::Conflict @failed_dep = failed_dep end - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and @dependency == other.dependency and @activated == other.activated and @@ -57,7 +57,7 @@ class Gem::Resolver::Conflict requirement = dependency.requirement alternates = dependency.matching_specs.map { |spec| spec.full_name } - unless alternates.empty? then + unless alternates.empty? matching = <<-MATCHING.chomp Gems matching %s: @@ -97,7 +97,7 @@ class Gem::Resolver::Conflict @dependency.name == spec.name end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[Dependency conflict: ', ']' do q.breakable @@ -109,7 +109,7 @@ class Gem::Resolver::Conflict q.pp @dependency q.breakable - if @dependency == @failed_dep then + if @dependency == @failed_dep q.text ' failed' else q.text ' failed dependency ' @@ -121,7 +121,7 @@ class Gem::Resolver::Conflict ## # Path of activations from the +current+ list. - def request_path current + def request_path(current) path = [] while current do diff --git a/lib/rubygems/resolver/current_set.rb b/lib/rubygems/resolver/current_set.rb index 265c639f15..d60e46389d 100644 --- a/lib/rubygems/resolver/current_set.rb +++ b/lib/rubygems/resolver/current_set.rb @@ -6,9 +6,8 @@ class Gem::Resolver::CurrentSet < Gem::Resolver::Set - def find_all req + def find_all(req) req.dependency.matching_specs end end - diff --git a/lib/rubygems/resolver/dependency_request.rb b/lib/rubygems/resolver/dependency_request.rb index c2918911cd..1984aa9ddc 100644 --- a/lib/rubygems/resolver/dependency_request.rb +++ b/lib/rubygems/resolver/dependency_request.rb @@ -19,12 +19,12 @@ class Gem::Resolver::DependencyRequest # Creates a new DependencyRequest for +dependency+ from +requester+. # +requester may be nil if the request came from a user. - def initialize dependency, requester + def initialize(dependency, requester) @dependency = dependency @requester = requester end - def == other # :nodoc: + def ==(other) # :nodoc: case other when Gem::Dependency @dependency == other @@ -48,7 +48,7 @@ class Gem::Resolver::DependencyRequest # NOTE: #match? only matches prerelease versions when #dependency is a # prerelease dependency. - def match? spec, allow_prerelease = false + def match?(spec, allow_prerelease = false) @dependency.match? spec, nil, allow_prerelease end @@ -95,7 +95,7 @@ class Gem::Resolver::DependencyRequest @requester ? @requester.request : "(unknown)" end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[Dependency request ', ']' do q.breakable q.text @dependency.to_s diff --git a/lib/rubygems/resolver/git_set.rb b/lib/rubygems/resolver/git_set.rb index 723a202d7a..6340b92fae 100644 --- a/lib/rubygems/resolver/git_set.rb +++ b/lib/rubygems/resolver/git_set.rb @@ -43,7 +43,7 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set @specs = {} end - def add_git_gem name, repository, reference, submodules # :nodoc: + def add_git_gem(name, repository, reference, submodules) # :nodoc: @repositories[name] = [repository, reference] @need_submodules[repository] = submodules end @@ -56,7 +56,7 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set # This fills in the prefetch information as enough information about the gem # is present in the arguments. - def add_git_spec name, version, repository, reference, submodules # :nodoc: + def add_git_spec(name, version, repository, reference, submodules) # :nodoc: add_git_gem name, repository, reference, submodules source = Gem::Source::Git.new name, repository, reference @@ -77,7 +77,7 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set ## # Finds all git gems matching +req+ - def find_all req + def find_all(req) prefetch nil specs.values.select do |spec| @@ -88,7 +88,7 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set ## # Prefetches specifications from the git repositories in this set. - def prefetch reqs + def prefetch(reqs) return unless @specs.empty? @repositories.each do |name, (repository, reference)| @@ -104,7 +104,7 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set end end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[GitSet', ']' do next if @repositories.empty? q.breakable @@ -120,4 +120,3 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set end end - diff --git a/lib/rubygems/resolver/git_specification.rb b/lib/rubygems/resolver/git_specification.rb index 2448797d3f..f43cfba853 100644 --- a/lib/rubygems/resolver/git_specification.rb +++ b/lib/rubygems/resolver/git_specification.rb @@ -6,14 +6,14 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and @set == other.set and @spec == other.spec and @source == other.source end - def add_dependency dependency # :nodoc: + def add_dependency(dependency) # :nodoc: spec.dependencies << dependency end @@ -21,7 +21,7 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification # Installing a git gem only involves building the extensions and generating # the executables. - def install options = {} + def install(options = {}) require 'rubygems/installer' installer = Gem::Installer.for_spec spec, options @@ -35,7 +35,7 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification installer.run_post_install_hooks end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[GitSpecification', ']' do q.breakable q.text "name: #{name}" @@ -56,4 +56,3 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification end end - diff --git a/lib/rubygems/resolver/index_set.rb b/lib/rubygems/resolver/index_set.rb index 2450f14b4f..e32e1fa5ba 100644 --- a/lib/rubygems/resolver/index_set.rb +++ b/lib/rubygems/resolver/index_set.rb @@ -5,11 +5,11 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set - def initialize source = nil # :nodoc: + def initialize(source = nil) # :nodoc: super() @f = - if source then + if source sources = Gem::SourceList.from [source] Gem::SpecFetcher.new sources @@ -36,7 +36,7 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set # Return an array of IndexSpecification objects matching # DependencyRequest +req+. - def find_all req + def find_all(req) res = [] return res unless @remote @@ -44,7 +44,7 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set name = req.dependency.name @all[name].each do |uri, n| - if req.match? n, @prerelease then + if req.match? n, @prerelease res << Gem::Resolver::IndexSpecification.new( self, n.name, n.version, uri, n.platform) end @@ -53,7 +53,7 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set res end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[IndexSet', ']' do q.breakable q.text 'sources:' @@ -78,4 +78,3 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set end end - diff --git a/lib/rubygems/resolver/index_specification.rb b/lib/rubygems/resolver/index_specification.rb index 4340f46943..ed9423791c 100644 --- a/lib/rubygems/resolver/index_specification.rb +++ b/lib/rubygems/resolver/index_specification.rb @@ -15,7 +15,7 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification # The +name+, +version+ and +platform+ are the name, version and platform of # the gem. - def initialize set, name, version, source, platform + def initialize(set, name, version, source, platform) super() @set = set @@ -38,12 +38,12 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification '#<%s %s source %s>' % [self.class, full_name, @source] end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[Index specification', ']' do q.breakable q.text full_name - unless Gem::Platform::RUBY == @platform then + unless Gem::Platform::RUBY == @platform q.breakable q.text @platform.to_s end @@ -67,4 +67,3 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification end end - diff --git a/lib/rubygems/resolver/installed_specification.rb b/lib/rubygems/resolver/installed_specification.rb index d9c6a5e5cf..9d996fc1da 100644 --- a/lib/rubygems/resolver/installed_specification.rb +++ b/lib/rubygems/resolver/installed_specification.rb @@ -5,7 +5,7 @@ class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and @set == other.set and @spec == other.spec @@ -15,7 +15,7 @@ class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification # This is a null install as this specification is already installed. # +options+ are ignored. - def install options = {} + def install(options = {}) yield nil end @@ -30,7 +30,7 @@ class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification super end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[InstalledSpecification', ']' do q.breakable q.text "name: #{name}" @@ -56,4 +56,3 @@ class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification end end - diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb index f24293c0a0..f3827ad4e9 100644 --- a/lib/rubygems/resolver/installer_set.rb +++ b/lib/rubygems/resolver/installer_set.rb @@ -29,7 +29,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set ## # Creates a new InstallerSet that will look for gems in +domain+. - def initialize domain + def initialize(domain) super() @domain = domain @@ -50,7 +50,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set # Looks up the latest specification for +dependency+ and adds it to the # always_install list. - def add_always_install dependency + def add_always_install(dependency) request = Gem::Resolver::DependencyRequest.new dependency, nil found = find_all request @@ -65,7 +65,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set Gem::Platform.local === s.platform end - if found.empty? then + if found.empty? exc = Gem::UnsatisfiableDependencyError.new request exc.errors = errors @@ -83,7 +83,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set # Adds a local gem requested using +dep_name+ with the given +spec+ that can # be loaded and installed using the +source+. - def add_local dep_name, spec, source + def add_local(dep_name, spec, source) @local[dep_name] = [spec, source] end @@ -112,7 +112,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set # Returns an array of IndexSpecification objects matching DependencyRequest # +req+. - def find_all req + def find_all(req) res = [] dep = req.dependency @@ -128,7 +128,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set res << Gem::Resolver::InstalledSpecification.new(self, gemspec) end unless @ignore_installed - if consider_local? then + if consider_local? matching_local = @local.values.select do |spec, _| req.match? spec end.map do |spec, source| @@ -138,7 +138,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set res.concat matching_local begin - if local_spec = @local_source.find_gem(name, dep.requirement) then + if local_spec = @local_source.find_gem(name, dep.requirement) res << Gem::Resolver::IndexSpecification.new( self, local_spec.name, local_spec.version, @local_source, local_spec.platform) @@ -161,7 +161,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set @remote_set.prefetch(reqs) if consider_remote? end - def prerelease= allow_prerelease + def prerelease=(allow_prerelease) super @remote_set.prerelease = allow_prerelease @@ -179,7 +179,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set # Called from IndexSpecification to get a true Specification # object. - def load_spec name, ver, platform, source # :nodoc: + def load_spec(name, ver, platform, source) # :nodoc: key = "#{name}-#{ver}-#{platform}" @specs.fetch key do @@ -192,13 +192,13 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set ## # Has a local gem for +dep_name+ been added to this set? - def local? dep_name # :nodoc: + def local?(dep_name) # :nodoc: spec, _ = @local[dep_name] spec end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[InstallerSet', ']' do q.breakable q.text "domain: #{@domain}" @@ -213,7 +213,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set end end - def remote= remote # :nodoc: + def remote=(remote) # :nodoc: case @domain when :local then @domain = :both if remote diff --git a/lib/rubygems/resolver/local_specification.rb b/lib/rubygems/resolver/local_specification.rb index 1d9d22f0ac..7418cfcc86 100644 --- a/lib/rubygems/resolver/local_specification.rb +++ b/lib/rubygems/resolver/local_specification.rb @@ -17,7 +17,7 @@ class Gem::Resolver::LocalSpecification < Gem::Resolver::SpecSpecification true end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[LocalSpecification', ']' do q.breakable q.text "name: #{name}" @@ -39,4 +39,3 @@ class Gem::Resolver::LocalSpecification < Gem::Resolver::SpecSpecification end end - diff --git a/lib/rubygems/resolver/lock_set.rb b/lib/rubygems/resolver/lock_set.rb index 7fddc93e1c..4002a963a4 100644 --- a/lib/rubygems/resolver/lock_set.rb +++ b/lib/rubygems/resolver/lock_set.rb @@ -9,7 +9,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set ## # Creates a new LockSet from the given +sources+ - def initialize sources + def initialize(sources) super() @sources = sources.map do |source| @@ -26,7 +26,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set # The specification's set will be the current set, and the source will be # the current set's source. - def add name, version, platform # :nodoc: + def add(name, version, platform) # :nodoc: version = Gem::Version.new version specs = [ Gem::Resolver::LockSpecification.new(self, name, version, @sources, platform) @@ -41,7 +41,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set # Returns an Array of IndexSpecification objects matching the # DependencyRequest +req+. - def find_all req + def find_all(req) @specs.select do |spec| req.match? spec end @@ -51,7 +51,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set # Loads a Gem::Specification with the given +name+, +version+ and # +platform+. +source+ is ignored. - def load_spec name, version, platform, source # :nodoc: + def load_spec(name, version, platform, source) # :nodoc: dep = Gem::Dependency.new name, version found = @specs.find do |spec| @@ -63,7 +63,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set found.source.fetch_spec tuple end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[LockSet', ']' do q.breakable q.text 'source:' @@ -80,4 +80,3 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set end end - diff --git a/lib/rubygems/resolver/lock_specification.rb b/lib/rubygems/resolver/lock_specification.rb index f485675673..e29b567de4 100644 --- a/lib/rubygems/resolver/lock_specification.rb +++ b/lib/rubygems/resolver/lock_specification.rb @@ -9,7 +9,7 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification attr_reader :sources - def initialize set, name, version, sources, platform + def initialize(set, name, version, sources, platform) super() @name = name @@ -27,10 +27,10 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification # This is a null install as a locked specification is considered installed. # +options+ are ignored. - def install options = {} + def install(options = {}) destination = options[:install_dir] || Gem.dir - if File.exist? File.join(destination, 'specifications', spec.spec_name) then + if File.exist? File.join(destination, 'specifications', spec.spec_name) yield nil return end @@ -41,11 +41,11 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification ## # Adds +dependency+ from the lockfile to this specification - def add_dependency dependency # :nodoc: + def add_dependency(dependency) # :nodoc: @dependencies << dependency end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[LockSpecification', ']' do q.breakable q.text "name: #{@name}" @@ -53,12 +53,12 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification q.breakable q.text "version: #{@version}" - unless @platform == Gem::Platform::RUBY then + unless @platform == Gem::Platform::RUBY q.breakable q.text "platform: #{@platform}" end - unless @dependencies.empty? then + unless @dependencies.empty? q.breakable q.text 'dependencies:' q.breakable @@ -85,4 +85,3 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification end end - diff --git a/lib/rubygems/resolver/requirement_list.rb b/lib/rubygems/resolver/requirement_list.rb index 2768c80170..98d086e63c 100644 --- a/lib/rubygems/resolver/requirement_list.rb +++ b/lib/rubygems/resolver/requirement_list.rb @@ -18,7 +18,7 @@ class Gem::Resolver::RequirementList @list = [] end - def initialize_copy other # :nodoc: + def initialize_copy(other) # :nodoc: @exact = @exact.dup @list = @list.dup end diff --git a/lib/rubygems/resolver/set.rb b/lib/rubygems/resolver/set.rb index 11704d5c4c..242f9cd3dc 100644 --- a/lib/rubygems/resolver/set.rb +++ b/lib/rubygems/resolver/set.rb @@ -31,7 +31,7 @@ class Gem::Resolver::Set # The find_all method must be implemented. It returns all Resolver # Specification objects matching the given DependencyRequest +req+. - def find_all req + def find_all(req) raise NotImplementedError end @@ -43,7 +43,7 @@ class Gem::Resolver::Set # When overridden, the #prefetch method should look up specifications # matching +reqs+. - def prefetch reqs + def prefetch(reqs) end ## diff --git a/lib/rubygems/resolver/source_set.rb b/lib/rubygems/resolver/source_set.rb index 696d963732..8e799514fd 100644 --- a/lib/rubygems/resolver/source_set.rb +++ b/lib/rubygems/resolver/source_set.rb @@ -16,7 +16,7 @@ class Gem::Resolver::SourceSet < Gem::Resolver::Set @sets = {} end - def find_all req # :nodoc: + def find_all(req) # :nodoc: if set = get_set(req.dependency.name) set.find_all req else @@ -25,7 +25,7 @@ class Gem::Resolver::SourceSet < Gem::Resolver::Set end # potentially no-op - def prefetch reqs # :nodoc: + def prefetch(reqs) # :nodoc: reqs.each do |req| if set = get_set(req.dependency.name) set.prefetch reqs @@ -33,7 +33,7 @@ class Gem::Resolver::SourceSet < Gem::Resolver::Set end end - def add_source_gem name, source + def add_source_gem(name, source) @links[name] = source end @@ -45,4 +45,3 @@ class Gem::Resolver::SourceSet < Gem::Resolver::Set end end - diff --git a/lib/rubygems/resolver/spec_specification.rb b/lib/rubygems/resolver/spec_specification.rb index 35ee8cc247..d0e744f3a7 100644 --- a/lib/rubygems/resolver/spec_specification.rb +++ b/lib/rubygems/resolver/spec_specification.rb @@ -10,7 +10,7 @@ class Gem::Resolver::SpecSpecification < Gem::Resolver::Specification # +spec+. The +source+ is either where the +spec+ came from, or should be # loaded from. - def initialize set, spec, source = nil + def initialize(set, spec, source = nil) @set = set @source = source @spec = spec @@ -54,4 +54,3 @@ class Gem::Resolver::SpecSpecification < Gem::Resolver::Specification end end - diff --git a/lib/rubygems/resolver/specification.rb b/lib/rubygems/resolver/specification.rb index 530ea9994d..7c1e9be702 100644 --- a/lib/rubygems/resolver/specification.rb +++ b/lib/rubygems/resolver/specification.rb @@ -81,7 +81,7 @@ class Gem::Resolver::Specification # After installation #spec is updated to point to the just-installed # specification. - def install options = {} + def install(options = {}) require 'rubygems/installer' gem = download options @@ -93,7 +93,7 @@ class Gem::Resolver::Specification @spec = installer.install end - def download options + def download(options) dir = options[:install_dir] || Gem.dir Gem.ensure_gem_subdirectories dir @@ -112,4 +112,3 @@ class Gem::Resolver::Specification false end end - diff --git a/lib/rubygems/resolver/vendor_set.rb b/lib/rubygems/resolver/vendor_set.rb index f30ce534af..7e2e917d5c 100644 --- a/lib/rubygems/resolver/vendor_set.rb +++ b/lib/rubygems/resolver/vendor_set.rb @@ -32,7 +32,7 @@ class Gem::Resolver::VendorSet < Gem::Resolver::Set # Adds a specification to the set with the given +name+ which has been # unpacked into the given +directory+. - def add_vendor_gem name, directory # :nodoc: + def add_vendor_gem(name, directory) # :nodoc: gemspec = File.join directory, "#{name}.gemspec" spec = Gem::Specification.load gemspec @@ -52,7 +52,7 @@ class Gem::Resolver::VendorSet < Gem::Resolver::Set # Returns an Array of VendorSpecification objects matching the # DependencyRequest +req+. - def find_all req + def find_all(req) @specs.values.select do |spec| req.match? spec end.map do |spec| @@ -65,11 +65,11 @@ class Gem::Resolver::VendorSet < Gem::Resolver::Set # Loads a spec with the given +name+. +version+, +platform+ and +source+ are # ignored. - def load_spec name, version, platform, source # :nodoc: + def load_spec(name, version, platform, source) # :nodoc: @specs.fetch name end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[VendorSet', ']' do next if @directories.empty? q.breakable @@ -85,4 +85,3 @@ class Gem::Resolver::VendorSet < Gem::Resolver::Set end end - diff --git a/lib/rubygems/resolver/vendor_specification.rb b/lib/rubygems/resolver/vendor_specification.rb index c624f3e834..56f2e6eb2c 100644 --- a/lib/rubygems/resolver/vendor_specification.rb +++ b/lib/rubygems/resolver/vendor_specification.rb @@ -6,7 +6,7 @@ class Gem::Resolver::VendorSpecification < Gem::Resolver::SpecSpecification - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and @set == other.set and @spec == other.spec and @@ -17,9 +17,8 @@ class Gem::Resolver::VendorSpecification < Gem::Resolver::SpecSpecification # This is a null install as this gem was unpacked into a directory. # +options+ are ignored. - def install options = {} + def install(options = {}) yield nil end end - diff --git a/lib/rubygems/safe_yaml.rb b/lib/rubygems/safe_yaml.rb index f3313b33e8..3540fd74dd 100644 --- a/lib/rubygems/safe_yaml.rb +++ b/lib/rubygems/safe_yaml.rb @@ -27,7 +27,7 @@ module Gem ).freeze if ::YAML.respond_to? :safe_load - def self.safe_load input + 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) else @@ -35,7 +35,7 @@ module Gem end end - def self.load input + def self.load(input) if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') ::YAML.safe_load(input, permitted_classes: [::Symbol]) else @@ -47,11 +47,11 @@ module Gem warn "YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0)." end - def self.safe_load input, *args + def self.safe_load(input, *args) ::YAML.load input end - def self.load input + def self.load(input) ::YAML.load input end end diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb index f896039fa4..7b0a0b3c6a 100644 --- a/lib/rubygems/security.rb +++ b/lib/rubygems/security.rb @@ -340,9 +340,9 @@ module Gem::Security # Digest algorithm used to sign gems DIGEST_ALGORITHM = - if defined?(OpenSSL::Digest::SHA256) then + if defined?(OpenSSL::Digest::SHA256) OpenSSL::Digest::SHA256 - elsif defined?(OpenSSL::Digest::SHA1) then + elsif defined?(OpenSSL::Digest::SHA1) OpenSSL::Digest::SHA1 else require 'digest' @@ -353,7 +353,7 @@ module Gem::Security # Used internally to select the signing digest from all computed digests DIGEST_NAME = # :nodoc: - if DIGEST_ALGORITHM.method_defined? :name then + if DIGEST_ALGORITHM.method_defined? :name DIGEST_ALGORITHM.new.name else DIGEST_ALGORITHM.name[/::([^:]+)\z/, 1] @@ -363,7 +363,7 @@ module Gem::Security # Algorithm for creating the key pair used to sign gems KEY_ALGORITHM = - if defined?(OpenSSL::PKey::RSA) then + if defined?(OpenSSL::PKey::RSA) OpenSSL::PKey::RSA end @@ -403,7 +403,7 @@ module Gem::Security 'subjectKeyIdentifier' => 'hash', }.freeze - def self.alt_name_or_x509_entry certificate, x509_entry + def self.alt_name_or_x509_entry(certificate, x509_entry) alt_name = certificate.extensions.find do |extension| extension.oid == "#{x509_entry}AltName" end @@ -419,8 +419,8 @@ module Gem::Security # # The +extensions+ restrict the key to the indicated uses. - def self.create_cert subject, key, age = ONE_YEAR, extensions = EXTENSIONS, - serial = 1 + def self.create_cert(subject, key, age = ONE_YEAR, extensions = EXTENSIONS, + serial = 1) cert = OpenSSL::X509::Certificate.new cert.public_key = key.public_key @@ -446,7 +446,7 @@ module Gem::Security # a subject alternative name of +email+ and the given +extensions+ for the # +key+. - def self.create_cert_email email, key, age = ONE_YEAR, extensions = EXTENSIONS + def self.create_cert_email(email, key, age = ONE_YEAR, extensions = EXTENSIONS) subject = email_to_name email extensions = extensions.merge "subjectAltName" => "email:#{email}" @@ -458,8 +458,8 @@ module Gem::Security # Creates a self-signed certificate with an issuer and subject of +subject+ # and the given +extensions+ for the +key+. - def self.create_cert_self_signed subject, key, age = ONE_YEAR, - extensions = EXTENSIONS, serial = 1 + def self.create_cert_self_signed(subject, key, age = ONE_YEAR, + extensions = EXTENSIONS, serial = 1) certificate = create_cert subject, key, age, extensions sign certificate, key, certificate, age, extensions, serial @@ -469,14 +469,14 @@ module Gem::Security # Creates a new key pair of the specified +length+ and +algorithm+. The # default is a 3072 bit RSA key. - def self.create_key length = KEY_LENGTH, algorithm = KEY_ALGORITHM + def self.create_key(length = KEY_LENGTH, algorithm = KEY_ALGORITHM) algorithm.new length end ## # Turns +email_address+ into an OpenSSL::X509::Name - def self.email_to_name email_address + def self.email_to_name(email_address) email_address = email_address.gsub(/[^\w@.-]+/i, '_') cn, dcs = email_address.split '@' @@ -494,15 +494,15 @@ module Gem::Security #-- # TODO increment serial - def self.re_sign expired_certificate, private_key, age = ONE_YEAR, - extensions = EXTENSIONS + def self.re_sign(expired_certificate, private_key, age = ONE_YEAR, + extensions = EXTENSIONS) raise Gem::Security::Exception, "incorrect signing key for re-signing " + "#{expired_certificate.subject}" unless expired_certificate.public_key.to_pem == private_key.public_key.to_pem unless expired_certificate.subject.to_s == - expired_certificate.issuer.to_s then + expired_certificate.issuer.to_s subject = alt_name_or_x509_entry expired_certificate, :subject issuer = alt_name_or_x509_entry expired_certificate, :issuer @@ -531,8 +531,8 @@ module Gem::Security # # Returns the newly signed certificate. - def self.sign certificate, signing_key, signing_cert, - age = ONE_YEAR, extensions = EXTENSIONS, serial = 1 + def self.sign(certificate, signing_key, signing_cert, + age = ONE_YEAR, extensions = EXTENSIONS, serial = 1) signee_subject = certificate.subject signee_key = certificate.public_key @@ -571,7 +571,7 @@ module Gem::Security ## # Enumerates the trusted certificates via Gem::Security::TrustDir. - def self.trusted_certificates &block + def self.trusted_certificates(&block) trust_dir.each_certificate(&block) end @@ -580,7 +580,7 @@ module Gem::Security # +permissions+. If passed +cipher+ and +passphrase+ those arguments will be # passed to +to_pem+. - def self.write pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER + def self.write(pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER) path = File.expand_path path File.open path, 'wb', permissions do |io| @@ -598,11 +598,10 @@ module Gem::Security end -if defined?(OpenSSL::SSL) then +if defined?(OpenSSL::SSL) require 'rubygems/security/policy' require 'rubygems/security/policies' require 'rubygems/security/trust_dir' end require 'rubygems/security/signer' - diff --git a/lib/rubygems/security/policies.rb b/lib/rubygems/security/policies.rb index 49ca8d860d..8f6ad99316 100644 --- a/lib/rubygems/security/policies.rb +++ b/lib/rubygems/security/policies.rb @@ -113,4 +113,3 @@ module Gem::Security }.freeze end - diff --git a/lib/rubygems/security/policy.rb b/lib/rubygems/security/policy.rb index 2e9159797c..1aa6eab18c 100644 --- a/lib/rubygems/security/policy.rb +++ b/lib/rubygems/security/policy.rb @@ -24,7 +24,7 @@ class Gem::Security::Policy # Create a new Gem::Security::Policy object with the given mode and # options. - def initialize name, policy = {}, opt = {} + def initialize(name, policy = {}, opt = {}) require 'openssl' @name = name @@ -55,7 +55,7 @@ class Gem::Security::Policy # Verifies each certificate in +chain+ has signed the following certificate # and is valid for the given +time+. - def check_chain chain, time + def check_chain(chain, time) raise Gem::Security::Exception, 'missing signing chain' unless chain raise Gem::Security::Exception, 'empty signing chain' if chain.empty? @@ -74,7 +74,7 @@ class Gem::Security::Policy # Verifies that +data+ matches the +signature+ created by +public_key+ and # the +digest+ algorithm. - def check_data public_key, digest, signature, data + def check_data(public_key, digest, signature, data) raise Gem::Security::Exception, "invalid signature" unless public_key.verify digest.new, signature, data.digest @@ -85,22 +85,22 @@ class Gem::Security::Policy # Ensures that +signer+ is valid for +time+ and was signed by the +issuer+. # If the +issuer+ is +nil+ no verification is performed. - def check_cert signer, issuer, time + def check_cert(signer, issuer, time) raise Gem::Security::Exception, 'missing signing certificate' unless signer message = "certificate #{signer.subject}" - if not_before = signer.not_before and not_before > time then + if not_before = signer.not_before and not_before > time raise Gem::Security::Exception, "#{message} not valid before #{not_before}" end - if not_after = signer.not_after and not_after < time then + if not_after = signer.not_after and not_after < time raise Gem::Security::Exception, "#{message} not valid after #{not_after}" end - if issuer and not signer.verify issuer.public_key then + if issuer and not signer.verify issuer.public_key raise Gem::Security::Exception, "#{message} was not issued by #{issuer.subject}" end @@ -111,8 +111,8 @@ class Gem::Security::Policy ## # Ensures the public key of +key+ matches the public key in +signer+ - def check_key signer, key - unless signer and key then + def check_key(signer, key) + unless signer and key return true unless @only_signed raise Gem::Security::Exception, 'missing key or signature' @@ -129,7 +129,7 @@ class Gem::Security::Policy # Ensures the root certificate in +chain+ is self-signed and valid for # +time+. - def check_root chain, time + def check_root(chain, time) raise Gem::Security::Exception, 'missing signing chain' unless chain root = chain.first @@ -148,7 +148,7 @@ class Gem::Security::Policy # Ensures the root of +chain+ has a trusted certificate in +trust_dir+ and # the digests of the two certificates match according to +digester+ - def check_trust chain, digester, trust_dir + def check_trust(chain, digester, trust_dir) raise Gem::Security::Exception, 'missing signing chain' unless chain root = chain.first @@ -157,7 +157,7 @@ class Gem::Security::Policy path = Gem::Security.trust_dir.cert_path root - unless File.exist? path then + unless File.exist? path message = "root cert #{root.subject} is not trusted".dup message << " (root of signing cert #{chain.last.subject})" if @@ -183,7 +183,7 @@ class Gem::Security::Policy ## # Extracts the email or subject from +certificate+ - def subject certificate # :nodoc: + def subject(certificate) # :nodoc: certificate.extensions.each do |extension| next unless extension.oid == 'subjectAltName' @@ -208,13 +208,13 @@ class Gem::Security::Policy # # If +key+ is given it is used to validate the signing certificate. - def verify chain, key = nil, digests = {}, signatures = {}, - full_name = '(unknown)' - if signatures.empty? then - if @only_signed then + def verify(chain, key = nil, digests = {}, signatures = {}, + full_name = '(unknown)') + if signatures.empty? + if @only_signed raise Gem::Security::Exception, "unsigned gems are not allowed by the #{name} policy" - elsif digests.empty? then + elsif digests.empty? # lack of signatures is irrelevant if there is nothing to check # against else @@ -232,7 +232,7 @@ class Gem::Security::Policy file_digests.values.first.name == Gem::Security::DIGEST_NAME end - if @verify_data then + if @verify_data raise Gem::Security::Exception, 'no digests provided (probable bug)' if signer_digests.nil? or signer_digests.empty? else @@ -249,9 +249,9 @@ class Gem::Security::Policy check_root chain, time if @verify_root - if @only_trusted then + if @only_trusted check_trust chain, digester, trust_dir - elsif signatures.empty? and digests.empty? then + elsif signatures.empty? and digests.empty? # trust is irrelevant if there's no signatures to verify else alert_warning "#{subject signer} is not trusted for #{full_name}" @@ -280,7 +280,7 @@ class Gem::Security::Policy # Extracts the certificate chain from the +spec+ and calls #verify to ensure # the signatures and certificate chain is valid according to the policy.. - def verify_signatures spec, digests, signatures + def verify_signatures(spec, digests, signatures) chain = spec.cert_chain.map do |cert_pem| OpenSSL::X509::Certificate.new cert_pem end diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb index 32dab9fa81..34e86e921a 100644 --- a/lib/rubygems/security/signer.rb +++ b/lib/rubygems/security/signer.rb @@ -65,18 +65,18 @@ class Gem::Security::Signer # +chain+ containing X509 certificates, encoding certificates or paths to # certificates. - def initialize key, cert_chain, passphrase = nil, options = {} + def initialize(key, cert_chain, passphrase = nil, options = {}) @cert_chain = cert_chain @key = key @passphrase = passphrase @options = DEFAULT_OPTIONS.merge(options) - unless @key then + unless @key default_key = File.join Gem.default_key_path @key = default_key if File.exist? default_key end - unless @cert_chain then + unless @cert_chain default_cert = File.join Gem.default_cert_path @cert_chain = [default_cert] if File.exist? default_cert end @@ -89,7 +89,7 @@ class Gem::Security::Signer @key = OpenSSL::PKey::RSA.new(File.read(@key), @passphrase) end - if @cert_chain then + if @cert_chain @cert_chain = @cert_chain.compact.map do |cert| next cert if OpenSSL::X509::Certificate === cert @@ -106,10 +106,10 @@ class Gem::Security::Signer # Extracts the full name of +cert+. If the certificate has a subjectAltName # this value is preferred, otherwise the subject is used. - def extract_name cert # :nodoc: + def extract_name(cert) # :nodoc: subject_alt_name = cert.extensions.find { |e| 'subjectAltName' == e.oid } - if subject_alt_name then + if subject_alt_name /\Aemail:/ =~ subject_alt_name.value $' || subject_alt_name.value @@ -138,12 +138,12 @@ class Gem::Security::Signer ## # Sign data with given digest algorithm - def sign data + def sign(data) return unless @key raise Gem::Security::Exception, 'no certs provided' if @cert_chain.empty? - if @cert_chain.length == 1 and @cert_chain.last.not_after < Time.now then + if @cert_chain.length == 1 and @cert_chain.last.not_after < Time.now re_sign_key( expiration_length: (Gem::Security::ONE_DAY * options[:expiration_length_days]) ) @@ -203,4 +203,3 @@ class Gem::Security::Signer end end - diff --git a/lib/rubygems/security/trust_dir.rb b/lib/rubygems/security/trust_dir.rb index 6d837affa1..98031ea22b 100644 --- a/lib/rubygems/security/trust_dir.rb +++ b/lib/rubygems/security/trust_dir.rb @@ -22,7 +22,7 @@ class Gem::Security::TrustDir # Creates a new TrustDir using +dir+ where the directory and file # permissions will be checked according to +permissions+ - def initialize dir, permissions = DEFAULT_PERMISSIONS + def initialize(dir, permissions = DEFAULT_PERMISSIONS) @dir = dir @permissions = permissions @@ -32,7 +32,7 @@ class Gem::Security::TrustDir ## # Returns the path to the trusted +certificate+ - def cert_path certificate + def cert_path(certificate) name_path certificate.subject end @@ -59,7 +59,7 @@ class Gem::Security::TrustDir # Returns the issuer certificate of the given +certificate+ if it exists in # the trust directory. - def issuer_of certificate + def issuer_of(certificate) path = name_path certificate.issuer return unless File.exist? path @@ -70,7 +70,7 @@ class Gem::Security::TrustDir ## # Returns the path to the trusted certificate with the given ASN.1 +name+ - def name_path name + def name_path(name) digest = @digester.hexdigest name.to_s File.join @dir, "cert-#{digest}.pem" @@ -79,7 +79,7 @@ class Gem::Security::TrustDir ## # Loads the given +certificate_file+ - def load_certificate certificate_file + def load_certificate(certificate_file) pem = File.read certificate_file OpenSSL::X509::Certificate.new pem @@ -88,7 +88,7 @@ class Gem::Security::TrustDir ## # Add a certificate to trusted certificate list. - def trust_cert certificate + def trust_cert(certificate) verify destination = cert_path certificate @@ -105,7 +105,7 @@ class Gem::Security::TrustDir # permissions. def verify - if File.exist? @dir then + if File.exist? @dir raise Gem::Security::Exception, "trust directory #{@dir} is not a directory" unless File.directory? @dir @@ -117,4 +117,3 @@ class Gem::Security::TrustDir end end - diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb index 5c65f74aa3..1453bf2323 100644 --- a/lib/rubygems/server.rb +++ b/lib/rubygems/server.rb @@ -450,7 +450,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } @have_rdoc_4_plus = nil end - def add_date res + def add_date(res) res['date'] = @spec_dirs.map do |spec_dir| File.stat(spec_dir).mtime end.max @@ -462,8 +462,8 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } end end - def doc_root gem_name - if have_rdoc_4_plus? then + def doc_root(gem_name) + if have_rdoc_4_plus? "/doc_root/#{u gem_name}/" else "/doc_root/#{u gem_name}/rdoc/index.html" @@ -491,14 +491,14 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } specs = Marshal.dump specs - if req.path =~ /\.gz$/ then + if req.path =~ /\.gz$/ specs = Gem::Util.gzip specs res['content-type'] = 'application/x-gzip' else res['content-type'] = 'application/octet-stream' end - if req.request_method == 'HEAD' then + if req.request_method == 'HEAD' res['content-length'] = specs.length else res.body << specs @@ -509,7 +509,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } # Creates server sockets based on the addresses option. If no addresses # were given a server socket for all interfaces is created. - def listen addresses = @addresses + def listen(addresses = @addresses) addresses = [nil] unless addresses listeners = 0 @@ -529,14 +529,14 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } end end - if @server.listeners.empty? then + if @server.listeners.empty? say "Unable to start a server." say "Check for running servers or your --bind and --port arguments" terminate_interaction 1 end end - def prerelease_specs req, res + def prerelease_specs(req, res) reset_gems res['content-type'] = 'application/x-gzip' @@ -552,14 +552,14 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } specs = Marshal.dump specs - if req.path =~ /\.gz$/ then + if req.path =~ /\.gz$/ specs = Gem::Util.gzip specs res['content-type'] = 'application/x-gzip' else res['content-type'] = 'application/octet-stream' end - if req.request_method == 'HEAD' then + if req.request_method == 'HEAD' res['content-length'] = specs.length else res.body << specs @@ -579,13 +579,13 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } selector = full_name.inspect - if specs.empty? then + if specs.empty? res.status = 404 res.body = "No gems found matching #{selector}" - elsif specs.length > 1 then + elsif specs.length > 1 res.status = 500 res.body = "Multiple gems found matching #{selector}" - elsif marshal_format then + elsif marshal_format res['content-type'] = 'application/x-deflate' res.body << Gem.deflate(Marshal.dump(specs.first)) end @@ -818,7 +818,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } '/gems' => '/cache/', } - if have_rdoc_4_plus? then + if have_rdoc_4_plus? @server.mount '/doc_root', RDoc::Servlet, '/doc_root' else file_handlers['/doc_root'] = '/doc/' @@ -851,14 +851,14 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } specs = Marshal.dump specs - if req.path =~ /\.gz$/ then + if req.path =~ /\.gz$/ specs = Gem::Util.gzip specs res['content-type'] = 'application/x-gzip' else res['content-type'] = 'application/octet-stream' end - if req.request_method == 'HEAD' then + if req.request_method == 'HEAD' res['content-length'] = specs.length else res.body << specs diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb index 5530c2ce32..faed7bd350 100644 --- a/lib/rubygems/source.rb +++ b/lib/rubygems/source.rb @@ -68,7 +68,7 @@ class Gem::Source end end - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and @uri == other.uri end @@ -88,7 +88,7 @@ class Gem::Source rescue Gem::RemoteFetcher::FetchError Gem::Resolver::IndexSet.new self else - if response.respond_to? :uri then + if response.respond_to? :uri Gem::Resolver::APISet.new response.uri else Gem::Resolver::APISet.new bundler_api_uri @@ -126,7 +126,7 @@ class Gem::Source ## # Fetches a specification for the given +name_tuple+. - def fetch_spec name_tuple + def fetch_spec(name_tuple) fetcher = Gem::RemoteFetcher.fetcher spec_file_name = name_tuple.spec_name @@ -137,7 +137,7 @@ class Gem::Source local_spec = File.join cache_dir, spec_file_name - if File.exist? local_spec then + if File.exist? local_spec spec = Gem.read_binary local_spec spec = Marshal.load(spec) rescue nil return spec if spec @@ -148,7 +148,7 @@ class Gem::Source spec = fetcher.fetch_path source_uri spec = Gem::Util.inflate spec - if update_cache? then + if update_cache? FileUtils.mkdir_p cache_dir File.open local_spec, 'wb' do |io| @@ -206,7 +206,7 @@ class Gem::Source fetcher.download spec, uri.to_s, dir end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[Remote:', ']' do q.breakable q.text @uri.to_s diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb index 23f8928a4e..0b8a4339cc 100644 --- a/lib/rubygems/source/git.rb +++ b/lib/rubygems/source/git.rb @@ -50,7 +50,7 @@ class Gem::Source::Git < Gem::Source # repository may contain multiple gems. If +submodules+ is true, submodules # will be checked out when the gem is installed. - def initialize name, repository, reference, submodules = false + def initialize(name, repository, reference, submodules = false) super repository @name = name @@ -63,7 +63,7 @@ class Gem::Source::Git < Gem::Source @git = ENV['git'] || 'git' end - def <=> other + def <=>(other) case other when Gem::Source::Git then 0 @@ -77,7 +77,7 @@ class Gem::Source::Git < Gem::Source end end - def == other # :nodoc: + def ==(other) # :nodoc: super and @name == other.name and @repository == other.repository and @@ -93,7 +93,7 @@ class Gem::Source::Git < Gem::Source return false unless File.exist? repo_cache_dir - unless File.exist? install_dir then + unless File.exist? install_dir system @git, 'clone', '--quiet', '--no-checkout', repo_cache_dir, install_dir end @@ -117,7 +117,7 @@ class Gem::Source::Git < Gem::Source def cache # :nodoc: return unless @remote - if File.exist? repo_cache_dir then + if File.exist? repo_cache_dir Dir.chdir repo_cache_dir do system @git, 'fetch', '--quiet', '--force', '--tags', @repository, 'refs/heads/*:refs/heads/*' @@ -145,7 +145,7 @@ class Gem::Source::Git < Gem::Source ## # Nothing to download for git gems - def download full_spec, path # :nodoc: + def download(full_spec, path) # :nodoc: end ## @@ -157,7 +157,7 @@ class Gem::Source::Git < Gem::Source File.join base_dir, 'gems', "#{@name}-#{dir_shortref}" end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[Git: ', ']' do q.breakable q.text @repository @@ -206,7 +206,7 @@ class Gem::Source::Git < Gem::Source Dir.chdir directory do spec = Gem::Specification.load file - if spec then + if spec spec.base_dir = base_dir spec.extension_dir = @@ -228,7 +228,7 @@ class Gem::Source::Git < Gem::Source require 'digest' # required here to avoid deadlocking in Gem.activate_bin_path (because digest is a gem on 2.5+) normalized = - if @repository =~ %r%^\w+://(\w+@)?% then + if @repository =~ %r%^\w+://(\w+@)?% uri = URI(@repository).normalize.to_s.sub %r%/$%,'' uri.sub(/\A(\w+)/) { $1.downcase } else @@ -239,4 +239,3 @@ class Gem::Source::Git < Gem::Source end end - diff --git a/lib/rubygems/source/installed.rb b/lib/rubygems/source/installed.rb index 300491e467..8e20cbd76d 100644 --- a/lib/rubygems/source/installed.rb +++ b/lib/rubygems/source/installed.rb @@ -11,7 +11,7 @@ class Gem::Source::Installed < Gem::Source ## # Installed sources sort before all other sources - def <=> other + def <=>(other) case other when Gem::Source::Git, Gem::Source::Lock, @@ -29,13 +29,12 @@ class Gem::Source::Installed < Gem::Source ## # We don't need to download an installed gem - def download spec, path + def download(spec, path) nil end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.text '[Installed]' end end - diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb index 5ab7a467b5..875e992d85 100644 --- a/lib/rubygems/source/local.rb +++ b/lib/rubygems/source/local.rb @@ -15,7 +15,7 @@ class Gem::Source::Local < Gem::Source ## # Local sorts before Gem::Source and after Gem::Source::Installed - def <=> other + def <=>(other) case other when Gem::Source::Installed, Gem::Source::Lock then @@ -34,7 +34,7 @@ class Gem::Source::Local < Gem::Source "#<%s specs: %p>" % [self.class, keys] end - def load_specs type # :nodoc: + def load_specs(type) # :nodoc: @load_specs_names[type] ||= begin names = [] @@ -78,8 +78,8 @@ class Gem::Source::Local < Gem::Source end end - def find_gem gem_name, version = Gem::Requirement.default, # :nodoc: - prerelease = false + def find_gem(gem_name, version = Gem::Requirement.default, # :nodoc: + prerelease = false) load_specs :complete found = [] @@ -101,7 +101,7 @@ class Gem::Source::Local < Gem::Source found.max_by { |s| s.version } end - def fetch_spec name # :nodoc: + def fetch_spec(name) # :nodoc: load_specs :complete if data = @specs[name] @@ -111,7 +111,7 @@ class Gem::Source::Local < Gem::Source end end - def download spec, cache_dir = nil # :nodoc: + def download(spec, cache_dir = nil) # :nodoc: load_specs :complete @specs.each do |name, data| @@ -121,7 +121,7 @@ class Gem::Source::Local < Gem::Source raise Gem::Exception, "Unable to find file for '#{spec.full_name}'" end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[Local gems:', ']' do q.breakable q.seplist @specs.keys do |v| diff --git a/lib/rubygems/source/lock.rb b/lib/rubygems/source/lock.rb index 59717be2c0..3b3f491750 100644 --- a/lib/rubygems/source/lock.rb +++ b/lib/rubygems/source/lock.rb @@ -15,11 +15,11 @@ class Gem::Source::Lock < Gem::Source # Creates a new Lock source that wraps +source+ and moves it earlier in the # sort list. - def initialize source + def initialize(source) @wrapped = source end - def <=> other # :nodoc: + def <=>(other) # :nodoc: case other when Gem::Source::Lock then @wrapped <=> other.wrapped @@ -30,7 +30,7 @@ class Gem::Source::Lock < Gem::Source end end - def == other # :nodoc: + def ==(other) # :nodoc: 0 == (self <=> other) end @@ -41,7 +41,7 @@ class Gem::Source::Lock < Gem::Source ## # Delegates to the wrapped source's fetch_spec method. - def fetch_spec name_tuple + def fetch_spec(name_tuple) @wrapped.fetch_spec name_tuple end diff --git a/lib/rubygems/source/specific_file.rb b/lib/rubygems/source/specific_file.rb index 459c803e1a..a22772b9c0 100644 --- a/lib/rubygems/source/specific_file.rb +++ b/lib/rubygems/source/specific_file.rb @@ -27,22 +27,22 @@ class Gem::Source::SpecificFile < Gem::Source attr_reader :spec - def load_specs *a # :nodoc: + def load_specs(*a) # :nodoc: [@name] end - def fetch_spec name # :nodoc: + def fetch_spec(name) # :nodoc: return @spec if name == @name raise Gem::Exception, "Unable to find '#{name}'" @spec end - def download spec, dir = nil # :nodoc: + def download(spec, dir = nil) # :nodoc: return @path if spec == @spec raise Gem::Exception, "Unable to download '#{spec.full_name}'" end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[SpecificFile:', ']' do q.breakable q.text @path @@ -59,7 +59,7 @@ class Gem::Source::SpecificFile < Gem::Source # # Otherwise Gem::Source#<=> is used. - def <=> other + def <=>(other) case other when Gem::Source::SpecificFile then return nil if @spec.name != other.spec.name diff --git a/lib/rubygems/source/vendor.rb b/lib/rubygems/source/vendor.rb index e1b3698607..a87fa63331 100644 --- a/lib/rubygems/source/vendor.rb +++ b/lib/rubygems/source/vendor.rb @@ -7,11 +7,11 @@ class Gem::Source::Vendor < Gem::Source::Installed ## # Creates a new Vendor source for a gem that was unpacked at +path+. - def initialize path + def initialize(path) @uri = path end - def <=> other + def <=>(other) case other when Gem::Source::Lock then -1 @@ -25,4 +25,3 @@ class Gem::Source::Vendor < Gem::Source::Installed end end - diff --git a/lib/rubygems/source_list.rb b/lib/rubygems/source_list.rb index 66ce4d57ed..83b689f78e 100644 --- a/lib/rubygems/source_list.rb +++ b/lib/rubygems/source_list.rb @@ -105,7 +105,7 @@ class Gem::SourceList @sources.empty? end - def == other # :nodoc: + def ==(other) # :nodoc: to_a == other end @@ -140,7 +140,7 @@ class Gem::SourceList ## # Deletes +source+ from the source list which may be a Gem::Source or a URI. - def delete source + def delete(source) if source.kind_of? Gem::Source @sources.delete source else diff --git a/lib/rubygems/source_local.rb b/lib/rubygems/source_local.rb index 9869158e7d..5107069fd0 100644 --- a/lib/rubygems/source_local.rb +++ b/lib/rubygems/source_local.rb @@ -5,4 +5,3 @@ require 'rubygems/source_local' unless Gem::Deprecate.skip Kernel.warn "#{Gem.location_of_caller(3).join(':')}: Warning: Requiring rubygems/source_local is deprecated; please use rubygems/source/local instead." end - diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index 7c77eeffdb..ca901cb8bf 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -54,7 +54,7 @@ class Gem::SpecFetcher # If you need to retrieve specifications from a different +source+, you can # send it as an argument. - def initialize sources = nil + def initialize(sources = nil) @sources = sources || Gem.sources @update_cache = @@ -271,4 +271,3 @@ class Gem::SpecFetcher end end - diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 7b2f031d27..4721bfc415 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -114,7 +114,7 @@ class Gem::Specification < Gem::BasicSpecification private_constant :LOAD_CACHE if defined? private_constant - VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/ # :nodoc: + VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/.freeze # :nodoc: # :startdoc: @@ -274,7 +274,7 @@ class Gem::Specification < Gem::BasicSpecification # # spec.authors = ['John Jones', 'Mary Smith'] - def authors= value + def authors=(value) @authors = Array(value).flatten.grep(String) end @@ -342,7 +342,7 @@ class Gem::Specification < Gem::BasicSpecification # Usage: # spec.license = 'MIT' - def license=o + def license=(o) self.licenses = [o] end @@ -359,7 +359,7 @@ class Gem::Specification < Gem::BasicSpecification # Usage: # spec.licenses = ['MIT', 'GPL-2.0'] - def licenses= licenses + def licenses=(licenses) @licenses = Array licenses end @@ -406,7 +406,7 @@ class Gem::Specification < Gem::BasicSpecification # # spec.author = 'John Jones' - def author= o + def author=(o) self.authors = [o] end @@ -457,9 +457,9 @@ class Gem::Specification < Gem::BasicSpecification # # spec.platform = Gem::Platform.local - def platform= platform + def platform=(platform) if @original_platform.nil? or - @original_platform == Gem::Platform::RUBY then + @original_platform == Gem::Platform::RUBY @original_platform = platform end @@ -625,7 +625,7 @@ class Gem::Specification < Gem::BasicSpecification # Sets the version of RubyGems that installed this gem. See also # #installed_by_version. - def installed_by_version= version # :nodoc: + def installed_by_version=(version) # :nodoc: @installed_by_version = Gem::Version.new version end @@ -650,9 +650,7 @@ class Gem::Specification < Gem::BasicSpecification # ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0] # # # - # Because patch-level is taken into account, be very careful specifying using - # `<=`: `<= 2.2.2` will not match any patch-level of 2.2.2 after the `p0` - # release. It is much safer to specify `< 2.2.3` instead + # Prereleases can also be specified. # # Usage: # @@ -662,17 +660,17 @@ class Gem::Specification < Gem::BasicSpecification # # Only with ruby 2.0.x # spec.required_ruby_version = '~> 2.0' # - # # Only with ruby between 2.2.0 and 2.2.2 - # spec.required_ruby_version = ['>= 2.2.0', '< 2.2.3'] + # # Only prereleases or final releases after 2.6.0.preview2 + # spec.required_ruby_version = '> 2.6.0.preview2' - def required_ruby_version= req + def required_ruby_version=(req) @required_ruby_version = Gem::Requirement.create req end ## # The RubyGems version required by this gem - def required_rubygems_version= req + def required_rubygems_version=(req) @required_rubygems_version = Gem::Requirement.create req end @@ -697,7 +695,7 @@ class Gem::Specification < Gem::BasicSpecification # spec.test_files = Dir.glob('test/tc_*.rb') # spec.test_files = ['tests/test-suite.rb'] - def test_files= files # :nodoc: + def test_files=(files) # :nodoc: @test_files = Array files end @@ -747,7 +745,7 @@ class Gem::Specification < Gem::BasicSpecification attr_accessor :specification_version def self._all # :nodoc: - unless defined?(@@all) && @@all then + unless defined?(@@all) && @@all @@all = stubs.map(&:to_spec) if @@all.any?(&:nil?) # TODO: remove once we're happy raise "pid: #{$$} nil spec! included in #{stubs.inspect}" @@ -774,12 +772,12 @@ class Gem::Specification < Gem::BasicSpecification end end - def self.gemspec_stubs_in dir, pattern + def self.gemspec_stubs_in(dir, pattern) Gem::Util.glob_files_in_dir(pattern, dir).map { |path| yield path }.select(&:valid?) end private_class_method :gemspec_stubs_in - def self.default_stubs pattern + def self.default_stubs(pattern) base_dir = Gem.default_dir gems_dir = File.join base_dir, "gems" gemspec_stubs_in(default_specifications_dir, pattern) do |path| @@ -788,7 +786,7 @@ class Gem::Specification < Gem::BasicSpecification end private_class_method :default_stubs - def self.installed_stubs dirs, pattern + def self.installed_stubs(dirs, pattern) map_stubs(dirs, pattern) do |path, base_dir, gems_dir| Gem::StubSpecification.gemspec_stub(path, base_dir, gems_dir) end @@ -809,7 +807,7 @@ class Gem::Specification < Gem::BasicSpecification end private_class_method :uniq_by - def self.sort_by! list, &block + def self.sort_by!(list, &block) list.sort_by!(&block) end private_class_method :sort_by! @@ -842,7 +840,7 @@ class Gem::Specification < Gem::BasicSpecification # Returns a Gem::StubSpecification for installed gem named +name+ # only returns stubs that match Gem.platforms - def self.stubs_for name + def self.stubs_for(name) if @@stubs @@stubs_by_name[name] || [] else @@ -880,7 +878,7 @@ class Gem::Specification < Gem::BasicSpecification # Adds +spec+ to the known specifications, keeping the collection # properly sorted. - def self.add_spec spec + def self.add_spec(spec) warn "Gem::Specification.add_spec is deprecated and will be removed in RubyGems 3.0" unless Gem::Deprecate.skip # TODO: find all extraneous adds # puts @@ -905,7 +903,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Adds multiple specs to the known specifications. - def self.add_specs *specs + def self.add_specs(*specs) warn "Gem::Specification.add_specs is deprecated and will be removed in RubyGems 3.0" unless Gem::Deprecate.skip raise "nil spec!" if specs.any?(&:nil?) # TODO: remove once we're happy @@ -943,7 +941,7 @@ class Gem::Specification < Gem::BasicSpecification # # -- wilsonb - def self.all= specs + def self.all=(specs) raise "nil spec!" if specs.any?(&:nil?) # TODO: remove once we're happy @@stubs_by_name = specs.group_by(&:name) @@all = @@stubs = specs @@ -987,7 +985,7 @@ class Gem::Specification < Gem::BasicSpecification # Set the directories that Specification uses to find specs. Setting # this resets the list of known specs. - def self.dirs= dirs + def self.dirs=(dirs) self.reset @@dirs = Array(dirs).map { |dir| File.join dir, "specifications" } @@ -1010,7 +1008,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Returns every spec that matches +name+ and optional +requirements+. - def self.find_all_by_name name, *requirements + def self.find_all_by_name(name, *requirements) requirements = Gem::Requirement.default if requirements.empty? # TODO: maybe try: find_all { |s| spec === dep } @@ -1029,7 +1027,7 @@ class Gem::Specification < Gem::BasicSpecification # Find the best specification matching a +name+ and +requirements+. Raises # if the dependency doesn't resolve to a valid specification. - def self.find_by_name name, *requirements + def self.find_by_name(name, *requirements) requirements = Gem::Requirement.default if requirements.empty? # TODO: maybe try: find { |s| spec === dep } @@ -1040,7 +1038,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Return the best specification that contains the file matching +path+. - def self.find_by_path path + def self.find_by_path(path) path = path.dup.freeze spec = @@spec_with_requirable_file[path] ||= (stubs.find { |s| next unless Gem::BundlerVersionFinder.compatible?(s) @@ -1053,7 +1051,7 @@ class Gem::Specification < Gem::BasicSpecification # Return the best specification that contains the file matching +path+ # amongst the specs that are not activated. - def self.find_inactive_by_path path + def self.find_inactive_by_path(path) stub = stubs.find { |s| next if s.activated? next unless Gem::BundlerVersionFinder.compatible?(s) @@ -1062,7 +1060,7 @@ class Gem::Specification < Gem::BasicSpecification stub && stub.to_spec end - def self.find_active_stub_by_path path + def self.find_active_stub_by_path(path) stub = @@active_stub_with_requirable_file[path] ||= (stubs.find { |s| s.activated? and s.contains_requirable_file? path } || NOT_FOUND) @@ -1072,7 +1070,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Return currently unresolved specs that contain the file matching +path+. - def self.find_in_unresolved path + def self.find_in_unresolved(path) # TODO: do we need these?? Kill it specs = unresolved_deps.values.map { |dep| dep.to_specs }.flatten @@ -1083,7 +1081,7 @@ class Gem::Specification < Gem::BasicSpecification # Search through all unresolved deps and sub-dependencies and return # specs that contain the file matching +path+. - def self.find_in_unresolved_tree path + def self.find_in_unresolved_tree(path) specs = unresolved_deps.values.map { |dep| dep.to_specs }.flatten specs.each do |spec| @@ -1113,11 +1111,11 @@ class Gem::Specification < Gem::BasicSpecification input = normalize_yaml_input input spec = Gem::SafeYAML.safe_load input - if spec && spec.class == FalseClass then + if spec && spec.class == FalseClass raise Gem::EndOfYAMLException end - unless Gem::Specification === spec then + unless Gem::Specification === spec raise Gem::Exception, "YAML data doesn't evaluate to gem specification" end @@ -1131,11 +1129,11 @@ class Gem::Specification < Gem::BasicSpecification # Return the latest specs, optionally including prerelease specs if # +prerelease+ is true. - def self.latest_specs prerelease = false + def self.latest_specs(prerelease = false) _latest_specs Gem::Specification._all, prerelease end - def self._latest_specs specs, prerelease = false # :nodoc: + def self._latest_specs(specs, prerelease = false) # :nodoc: result = Hash.new { |h,k| h[k] = {} } native = {} @@ -1155,7 +1153,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Loads Ruby format gemspec from +file+. - def self.load file + def self.load(file) return unless file _spec = LOAD_CACHE[file] @@ -1251,7 +1249,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Removes +spec+ from the known specs. - def self.remove_spec spec + def self.remove_spec(spec) warn "Gem::Specification.remove_spec is deprecated and will be removed in RubyGems 3.0" unless Gem::Deprecate.skip _all.delete spec stubs.delete_if { |s| s.full_name == spec.full_name } @@ -1287,7 +1285,7 @@ class Gem::Specification < Gem::BasicSpecification @@active_stub_with_requirable_file = {} _clear_load_cache unresolved = unresolved_deps - unless unresolved.empty? then + unless unresolved.empty? w = "W" + "ARN" warn "#{w}: Unresolved or ambigious specs during Gem::Specification.reset:" unresolved.values.each do |dep| @@ -1322,7 +1320,7 @@ class Gem::Specification < Gem::BasicSpecification current_version = CURRENT_SPECIFICATION_VERSION - field_count = if spec.specification_version > current_version then + field_count = if spec.specification_version > current_version spec.instance_variable_set :@specification_version, current_version MARSHAL_FIELDS[current_version] @@ -1330,7 +1328,7 @@ class Gem::Specification < Gem::BasicSpecification MARSHAL_FIELDS[spec.specification_version] end - if array.size < field_count then + if array.size < field_count raise TypeError, "invalid Gem::Specification format #{array.inspect}" end @@ -1369,7 +1367,7 @@ class Gem::Specification < Gem::BasicSpecification sort_obj <=> other.sort_obj end - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other && name == other.name && version == other.version && @@ -1414,7 +1412,7 @@ class Gem::Specification < Gem::BasicSpecification def activate other = Gem.loaded_specs[self.name] - if other then + if other check_version_conflict other return false end @@ -1452,7 +1450,7 @@ class Gem::Specification < Gem::BasicSpecification specs = spec_dep.to_specs - if specs.size == 1 then + if specs.size == 1 specs.first.activate else name = spec_dep.name @@ -1514,7 +1512,7 @@ class Gem::Specification < Gem::BasicSpecification def add_bindir(executables) return nil if executables.nil? - if @bindir then + if @bindir Array(executables).map { |e| File.join(@bindir, e) } else executables @@ -1529,7 +1527,7 @@ class Gem::Specification < Gem::BasicSpecification # :development. def add_dependency_with_type(dependency, type, requirements) - requirements = if requirements.empty? then + requirements = if requirements.empty? Gem::Requirement.default else requirements.flatten @@ -1558,7 +1556,7 @@ class Gem::Specification < Gem::BasicSpecification # gem directories must come after -I and ENV['RUBYLIB'] insert_index = Gem.load_path_insert_index - if insert_index then + if insert_index # gem directories must come after -I and ENV['RUBYLIB'] $LOAD_PATH.insert(insert_index, *paths) else @@ -1596,7 +1594,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Returns the full path to an executable named +name+ in this gem. - def bin_file name + def bin_file(name) File.join bin_dir, name end @@ -1719,7 +1717,7 @@ class Gem::Specification < Gem::BasicSpecification def has_conflicts? return true unless Gem.env_requirement(name).satisfied_by?(version) self.dependencies.any? { |dep| - if dep.runtime? then + if dep.runtime? spec = Gem.loaded_specs[dep.name] spec and not spec.satisfies_requirement? dep else @@ -1749,26 +1747,26 @@ class Gem::Specification < Gem::BasicSpecification /\A (\d{4})-(\d{2})-(\d{2}) (\s+ \d{2}:\d{2}:\d{2}\.\d+ \s* (Z | [-+]\d\d:\d\d) )? - \Z/x + \Z/x.freeze ## # The date this gem was created # # DO NOT set this, it is set automatically when the gem is packaged. - def date= date + def date=(date) # We want to end up with a Time object with one-day resolution. # This is the cleanest, most-readable, faster-than-using-Date # way to do it. @date = case date when String then - if DateTimeFormat =~ date then + if DateTimeFormat =~ date Time.utc($1.to_i, $2.to_i, $3.to_i) # Workaround for where the date format output from psych isn't # parsed as a Time object by syck and thus comes through as a # string. - elsif /\A(\d{4})-(\d{2})-(\d{2}) \d{2}:\d{2}:\d{2}\.\d+?Z\z/ =~ date then + elsif /\A(\d{4})-(\d{2})-(\d{2}) \d{2}:\d{2}:\d{2}\.\d+?Z\z/ =~ date Time.utc($1.to_i, $2.to_i, $3.to_i) else raise(Gem::InvalidSpecificationException, @@ -1802,7 +1800,7 @@ class Gem::Specification < Gem::BasicSpecification ## # The default value for specification attribute +name+ - def default_value name + def default_value(name) @@default_value[name] end @@ -1826,7 +1824,7 @@ class Gem::Specification < Gem::BasicSpecification out = [] Gem::Specification.each do |spec| spec.dependencies.each do |dep| - if self.satisfies_requirement?(dep) then + if self.satisfies_requirement?(dep) sats = [] find_all_satisfiers(dep) do |sat| sats << sat @@ -1848,7 +1846,7 @@ class Gem::Specification < Gem::BasicSpecification ## # A detailed description of this gem. See also #summary - def description= str + def description=(str) @description = str.to_s end @@ -1867,17 +1865,17 @@ class Gem::Specification < Gem::BasicSpecification # # spec.doc_dir 'ri' # => "/path/to/gem_repo/doc/a-1/ri" - def doc_dir type = nil + def doc_dir(type = nil) @doc_dir ||= File.join base_dir, 'doc', full_name - if type then + if type File.join @doc_dir, type else @doc_dir end end - def encode_with coder # :nodoc: + def encode_with(coder) # :nodoc: mark_version coder.add 'name', @name @@ -1898,7 +1896,7 @@ class Gem::Specification < Gem::BasicSpecification end end - def eql? other # :nodoc: + def eql?(other) # :nodoc: self.class === other && same_attributes?(other) end @@ -1912,7 +1910,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Singular accessor for #executables - def executable=o + def executable=(o) self.executables = [o] end @@ -1920,7 +1918,7 @@ class Gem::Specification < Gem::BasicSpecification # Sets executables to +value+, ensuring it is an array. Don't # use this, push onto the array instead. - def executables= value + def executables=(value) # TODO: warn about setting instead of pushing @executables = Array(value) end @@ -1929,7 +1927,7 @@ class Gem::Specification < Gem::BasicSpecification # Sets extensions to +extensions+, ensuring it is an array. Don't # use this, push onto the array instead. - def extensions= extensions + def extensions=(extensions) # TODO: warn about setting instead of pushing @extensions = Array extensions end @@ -1938,7 +1936,7 @@ class Gem::Specification < Gem::BasicSpecification # Sets extra_rdoc_files to +files+, ensuring it is an array. Don't # use this, push onto the array instead. - def extra_rdoc_files= files + def extra_rdoc_files=(files) # TODO: warn about setting instead of pushing @extra_rdoc_files = Array files end @@ -1955,14 +1953,14 @@ class Gem::Specification < Gem::BasicSpecification ## # Sets files to +files+, ensuring it is an array. - def files= files + def files=(files) @files = Array files end ## # Finds all gems that satisfy +dep+ - def find_all_satisfiers dep + def find_all_satisfiers(dep) Gem::Specification.each do |spec| yield spec if spec.satisfies_requirement? dep end @@ -2013,7 +2011,7 @@ class Gem::Specification < Gem::BasicSpecification # # Formerly used to indicate this gem was RDoc-capable. - def has_rdoc= ignored # :nodoc: + def has_rdoc=(ignored) # :nodoc: @has_rdoc = true end deprecate :has_rdoc=, :none, 2018, 12 @@ -2036,7 +2034,7 @@ class Gem::Specification < Gem::BasicSpecification name.hash ^ version.hash end - def init_with coder # :nodoc: + def init_with(coder) # :nodoc: @installed_by_version ||= nil yaml_initialize coder.tag, coder.map end @@ -2060,7 +2058,7 @@ class Gem::Specification < Gem::BasicSpecification # and yields itself for further initialization. Optionally takes +name+ and # +version+. - def initialize name = nil, version = nil + def initialize(name = nil, version = nil) super() @gems_dir = nil @base_dir = nil @@ -2084,14 +2082,14 @@ class Gem::Specification < Gem::BasicSpecification ## # Duplicates array_attributes from +other_spec+ so state isn't shared. - def initialize_copy other_spec + def initialize_copy(other_spec) self.class.array_attributes.each do |name| name = :"@#{name}" next unless other_spec.instance_variable_defined? name begin val = other_spec.instance_variable_get(name) - if val then + if val instance_variable_set name, val.dup elsif Gem.configuration.really_verbose warn "WARNING: #{full_name} has an invalid nil value for #{name}" @@ -2108,7 +2106,7 @@ class Gem::Specification < Gem::BasicSpecification def base_dir return Gem.dir unless loaded_from - @base_dir ||= if default_gem? then + @base_dir ||= if default_gem? File.dirname File.dirname File.dirname loaded_from else File.dirname File.dirname loaded_from @@ -2184,7 +2182,7 @@ class Gem::Specification < Gem::BasicSpecification def method_missing(sym, *a, &b) # :nodoc: if @specification_version > CURRENT_SPECIFICATION_VERSION and - sym.to_s =~ /=$/ then + sym.to_s =~ /=$/ warn "ignoring #{sym} loading #{full_name}" if $DEBUG else super @@ -2211,7 +2209,7 @@ class Gem::Specification < Gem::BasicSpecification # file list. def normalize - if defined?(@extra_rdoc_files) and @extra_rdoc_files then + if defined?(@extra_rdoc_files) and @extra_rdoc_files @extra_rdoc_files.uniq! @files ||= [] @files.concat(@extra_rdoc_files) @@ -2236,7 +2234,7 @@ class Gem::Specification < Gem::BasicSpecification # platform. For use with legacy gems. def original_name # :nodoc: - if platform == Gem::Platform::RUBY or platform.nil? then + if platform == Gem::Platform::RUBY or platform.nil? "#{@name}-#{@version}" else "#{@name}-#{@version}-#{@original_platform}" @@ -2269,11 +2267,11 @@ class Gem::Specification < Gem::BasicSpecification attributes.each do |attr_name| current_value = self.send attr_name if current_value != default_value(attr_name) or - self.class.required_attribute? attr_name then + self.class.required_attribute? attr_name q.text "s.#{attr_name} = " - if attr_name == :date then + if attr_name == :date current_value = current_value.utc q.text "Time.utc(#{current_value.year}, #{current_value.month}, #{current_value.day})" @@ -2291,7 +2289,7 @@ class Gem::Specification < Gem::BasicSpecification # Raise an exception if the version of this spec conflicts with the one # that is already loaded (+other+) - def check_version_conflict other # :nodoc: + def check_version_conflict(other) # :nodoc: return if self.version == other.version # This gem is already loaded. If the currently loaded gem is not in the @@ -2312,7 +2310,7 @@ class Gem::Specification < Gem::BasicSpecification # Check the spec for possible conflicts and freak out if there are any. def raise_if_conflicts # :nodoc: - if has_conflicts? then + if has_conflicts? raise Gem::ConflictError.new self, conflicts end end @@ -2321,7 +2319,7 @@ class Gem::Specification < Gem::BasicSpecification # Sets rdoc_options to +value+, ensuring it is an array. Don't # use this, push onto the array instead. - def rdoc_options= options + def rdoc_options=(options) # TODO: warn about setting instead of pushing @rdoc_options = Array options end @@ -2336,7 +2334,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Singular accessor for #require_paths - def require_path= path + def require_path=(path) self.require_paths = Array(path) end @@ -2344,12 +2342,12 @@ class Gem::Specification < Gem::BasicSpecification # Set requirements to +req+, ensuring it is an array. Don't # use this, push onto the array instead. - def requirements= req + def requirements=(req) # TODO: warn about setting instead of pushing @requirements = Array req end - def respond_to_missing? m, include_private = false # :nodoc: + def respond_to_missing?(m, include_private = false) # :nodoc: false end @@ -2396,7 +2394,7 @@ class Gem::Specification < Gem::BasicSpecification ## # True if this gem has the same attributes as +other+. - def same_attributes? spec + def same_attributes?(spec) @@attributes.all? { |name, default| self.send(name) == spec.send(name) } end @@ -2405,7 +2403,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Checks if this specification meets the requirement of +dependency+. - def satisfies_requirement? dependency + def satisfies_requirement?(dependency) return @name == dependency.name && dependency.requirement.satisfied_by?(@version) end @@ -2452,7 +2450,7 @@ class Gem::Specification < Gem::BasicSpecification ## # A short summary of this gem's description. - def summary= str + def summary=(str) @summary = str.to_s.strip. gsub(/(\w-)\n[ \t]*(\w)/, '\1\2').gsub(/\n[ \t]*/, " ") # so. weird. end @@ -2467,7 +2465,7 @@ class Gem::Specification < Gem::BasicSpecification ## # Singular mutator for #test_files - def test_file= file # :nodoc: + def test_file=(file) # :nodoc: self.test_files = [file] end @@ -2479,11 +2477,11 @@ class Gem::Specification < Gem::BasicSpecification # Handle the possibility that we have @test_suite_file but not # @test_files. This will happen when an old gem is loaded via # YAML. - if defined? @test_suite_file then + if defined? @test_suite_file @test_files = [@test_suite_file].flatten @test_suite_file = nil end - if defined?(@test_files) and @test_files then + if defined?(@test_files) and @test_files @test_files else @test_files = [] @@ -2507,7 +2505,7 @@ class Gem::Specification < Gem::BasicSpecification result << " s.name = #{ruby_code name}" result << " s.version = #{ruby_code version}" - unless platform.nil? or platform == Gem::Platform::RUBY then + unless platform.nil? or platform == Gem::Platform::RUBY result << " s.platform = #{ruby_code original_platform}" end result << "" @@ -2535,17 +2533,17 @@ class Gem::Specification < Gem::BasicSpecification next if handled.include? attr_name current_value = self.send(attr_name) if current_value != default_value(attr_name) or - self.class.required_attribute? attr_name then + self.class.required_attribute? attr_name result << " s.#{attr_name} = #{ruby_code current_value}" end end - if @installed_by_version then + if @installed_by_version result << nil result << " s.installed_by_version = \"#{Gem::VERSION}\" if s.respond_to? :installed_by_version" end - unless dependencies.empty? then + unless dependencies.empty? result << nil result << " if s.respond_to? :specification_version then" result << " s.specification_version = #{specification_version}" @@ -2627,7 +2625,7 @@ class Gem::Specification < Gem::BasicSpecification # Recursively walk dependencies of this spec, executing the +block+ for each # hop. - def traverse trail = [], visited = {}, &block + def traverse(trail = [], visited = {}, &block) trail.push(self) begin dependencies.each do |dep| @@ -2660,7 +2658,7 @@ class Gem::Specification < Gem::BasicSpecification # Raises InvalidSpecificationException if the spec does not pass the # checks.. - def validate packaging = true, strict = false + def validate(packaging = true, strict = false) require 'rubygems/user_interaction' extend Gem::UserInteraction normalize @@ -2701,7 +2699,7 @@ class Gem::Specification < Gem::BasicSpecification # required_rubygems_version if +version+ indicates it is a # prerelease. - def version= version + def version=(version) @version = Gem::Version.create(version) # skip to set required_ruby_version when pre-released rubygems. # It caused to raise CircularDependencyError diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index e28408a5a5..bc552f8287 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -2,11 +2,11 @@ require 'delegate' require 'uri' class Gem::SpecificationPolicy < SimpleDelegator - VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/ # :nodoc: + VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/.freeze # :nodoc: - SPECIAL_CHARACTERS = /\A[#{Regexp.escape('.-_')}]+/ # :nodoc: + SPECIAL_CHARACTERS = /\A[#{Regexp.escape('.-_')}]+/.freeze # :nodoc: - VALID_URI_PATTERN = %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z} # :nodoc: + VALID_URI_PATTERN = %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z}.freeze # :nodoc: METADATA_LINK_KEYS = %w[ bug_tracker_uri @@ -88,29 +88,29 @@ class Gem::SpecificationPolicy < SimpleDelegator # Implementation for Specification#validate_metadata def validate_metadata - unless Hash === metadata then + unless Hash === metadata error 'metadata must be a hash' end metadata.each do |key, value| - if !key.kind_of?(String) then + if !key.kind_of?(String) error "metadata keys must be a String" end - if key.size > 128 then + if key.size > 128 error "metadata key too large (#{key.size} > 128)" end - if !value.kind_of?(String) then + if !value.kind_of?(String) error "metadata values must be a String" end - if value.size > 1024 then + if value.size > 1024 error "metadata value too large (#{value.size} > 1024)" end - if METADATA_LINK_KEYS.include? key then - if value !~ VALID_URI_PATTERN then + if METADATA_LINK_KEYS.include? key + if value !~ VALID_URI_PATTERN error "metadata['#{key}'] has invalid link: #{value.inspect}" end end @@ -127,7 +127,7 @@ class Gem::SpecificationPolicy < SimpleDelegator error_messages = [] warning_messages = [] dependencies.each do |dep| - if prev = seen[dep.type][dep.name] then + if prev = seen[dep.type][dep.name] error_messages << <<-MESSAGE duplicate dependency on #{dep}, (#{prev.requirement}) use: add_#{dep.type}_dependency '#{dep.name}', '#{dep.requirement}', '#{prev.requirement}' @@ -147,14 +147,14 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: not version.prerelease? and (op == '>' or op == '>=') end - if open_ended then + if open_ended op, dep_version = dep.requirement.requirements.first base = dep_version.segments.first 2 - bugfix = if op == '>' then + bugfix = if op == '>' ", '> #{dep_version}'" - elsif op == '>=' and base != dep_version.segments then + elsif op == '>=' and base != dep_version.segments ", '>= #{dep_version}'" end @@ -165,10 +165,10 @@ open-ended dependency on #{dep} is not recommended WARNING end end - if error_messages.any? then + if error_messages.any? error error_messages.join end - if warning_messages.any? then + if warning_messages.any? warning_messages.each { |warning_message| warning warning_message } end end @@ -214,7 +214,7 @@ open-ended dependency on #{dep} is not recommended def validate_required_attributes Gem::Specification.required_attributes.each do |symbol| - unless send symbol then + unless send symbol error "missing value for attribute #{symbol}" end end @@ -242,7 +242,7 @@ open-ended dependency on #{dep} is not recommended return unless packaging non_files = files.reject {|x| File.file?(x) || File.symlink?(x)} - unless non_files.empty? then + unless non_files.empty? error "[\"#{non_files.join "\", \""}\"] are not files" end end @@ -261,7 +261,7 @@ open-ended dependency on #{dep} is not recommended def validate_platform case platform - when Gem::Platform, Gem::Platform::RUBY then # ok + when Gem::Platform, Gem::Platform::RUBY # ok else error "invalid platform #{platform.inspect}, see Gem::Platform" end @@ -282,7 +282,7 @@ open-ended dependency on #{dep} is not recommended String end - unless Array === val and val.all? {|x| x.kind_of?(klass)} then + unless Array === val and val.all? {|x| x.kind_of?(klass)} raise(Gem::InvalidSpecificationException, "#{field} must be an Array of #{klass}") end @@ -296,11 +296,11 @@ open-ended dependency on #{dep} is not recommended def validate_licenses licenses.each { |license| - if license.length > 64 then + if license.length > 64 error "each license must be 64 characters or less" end - if !Gem::Licenses.match?(license) then + if !Gem::Licenses.match?(license) suggestions = Gem::Licenses.suggestions(license) message = <<-warning license value '#{license}' is invalid. Use a license identifier from @@ -318,23 +318,23 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li end LAZY = '"FIxxxXME" or "TOxxxDO"'.gsub(/xxx/, '') - LAZY_PATTERN = /FI XME|TO DO/x - HOMEPAGE_URI_PATTERN = /\A[a-z][a-z\d+.-]*:/i + LAZY_PATTERN = /FI XME|TO DO/x.freeze + HOMEPAGE_URI_PATTERN = /\A[a-z][a-z\d+.-]*:/i.freeze def validate_lazy_metadata - unless authors.grep(LAZY_PATTERN).empty? then + unless authors.grep(LAZY_PATTERN).empty? error "#{LAZY} is not an author" end - unless Array(email).grep(LAZY_PATTERN).empty? then + unless Array(email).grep(LAZY_PATTERN).empty? error "#{LAZY} is not an email" end - if description =~ LAZY_PATTERN then + if description =~ LAZY_PATTERN error "#{LAZY} is not a description" end - if summary =~ LAZY_PATTERN then + if summary =~ LAZY_PATTERN error "#{LAZY} is not a summary" end @@ -356,7 +356,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li validate_attribute_present(attribute) end - if description == summary then + if description == summary warning "description and summary are identical" end @@ -384,13 +384,13 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li warning "#{executable_path} is missing #! line" end - def warning statement # :nodoc: + def warning(statement) # :nodoc: @warnings += 1 alert_warning statement end - def error statement # :nodoc: + def error(statement) # :nodoc: raise Gem::InvalidSpecificationException, statement ensure alert_warning help_text diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index 8dd6df17e3..022da9185d 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -32,7 +32,7 @@ class Gem::StubSpecification < Gem::BasicSpecification 'lib' => ['lib'].freeze }.freeze - def initialize data, extensions + def initialize(data, extensions) parts = data[PREFIX.length..-1].split(" ".freeze, 4) @name = parts[0].freeze @version = if Gem::Version.correct?(parts[1]) @@ -56,17 +56,17 @@ class Gem::StubSpecification < Gem::BasicSpecification end end - def self.default_gemspec_stub filename, base_dir, gems_dir + def self.default_gemspec_stub(filename, base_dir, gems_dir) new filename, base_dir, gems_dir, true end - def self.gemspec_stub filename, base_dir, gems_dir + def self.gemspec_stub(filename, base_dir, gems_dir) new filename, base_dir, gems_dir, false end attr_reader :base_dir, :gems_dir - def initialize filename, base_dir, gems_dir, default_gem + def initialize(filename, base_dir, gems_dir, default_gem) super() filename.untaint @@ -115,7 +115,7 @@ class Gem::StubSpecification < Gem::BasicSpecification begin file.readline # discard encoding line stubline = file.readline.chomp - if stubline.start_with?(PREFIX) then + if stubline.start_with?(PREFIX) extensions = if /\A#{PREFIX}/ =~ file.readline.chomp $'.split "\0" else @@ -185,7 +185,7 @@ class Gem::StubSpecification < Gem::BasicSpecification # The full Gem::Specification for this gem, loaded from evalling its gemspec def to_spec - @spec ||= if @data then + @spec ||= if @data loaded = Gem.loaded_specs[name] loaded if loaded && loaded.version == version end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index fc9456709f..7648ffdc84 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -84,7 +84,7 @@ module Gem # Allows setting path to Ruby. This method is available when requiring # 'rubygems/test_case' - def self.ruby= ruby + def self.ruby=(ruby) @ruby = ruby end @@ -115,7 +115,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni attr_accessor :uri # :nodoc: - def assert_activate expected, *specs + def assert_activate(expected, *specs) specs.each do |spec| case spec when String then @@ -133,7 +133,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end # TODO: move to minitest - def assert_path_exists path, msg = nil + def assert_path_exists(path, msg = nil) msg = message(msg) { "Expected path '#{path}' to exist" } assert File.exist?(path), msg end @@ -142,13 +142,13 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores # the original value when the block ends - def enable_shared value + def enable_shared(value) enable_shared = RbConfig::CONFIG['ENABLE_SHARED'] RbConfig::CONFIG['ENABLE_SHARED'] = value yield ensure - if enable_shared then + if enable_shared RbConfig::CONFIG['enable_shared'] = enable_shared else RbConfig::CONFIG.delete 'enable_shared' @@ -156,7 +156,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end # TODO: move to minitest - def refute_path_exists path, msg = nil + def refute_path_exists(path, msg = nil) msg = message(msg) { "Expected path '#{path}' to not exist" } refute File.exist?(path), msg end @@ -270,7 +270,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni tmpdir = File.expand_path Dir.tmpdir tmpdir.untaint - if ENV['KEEP_FILES'] then + if ENV['KEEP_FILES'] @tempdir = File.join(tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}") else @tempdir = File.join(tmpdir, "test_rubygems_#{$$}") @@ -304,7 +304,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni @userhome = File.join @tempdir, 'userhome' ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache' - @orig_ruby = if ENV['RUBY'] then + @orig_ruby = if ENV['RUBY'] ruby = Gem.ruby Gem.ruby = ENV['RUBY'] ruby @@ -426,7 +426,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end RbConfig::CONFIG['arch'] = @orig_arch - if defined? Gem::RemoteFetcher then + if defined? Gem::RemoteFetcher Gem::RemoteFetcher.fetcher = nil end @@ -449,7 +449,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem.ruby = @orig_ruby if @orig_ruby - if @orig_ENV_HOME then + if @orig_ENV_HOME ENV['HOME'] = @orig_ENV_HOME else ENV.delete 'HOME' @@ -513,7 +513,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # # Yields the +specification+ to the block, if given - def git_gem name = 'a', version = 1 + def git_gem(name = 'a', version = 1) have_git? directory = File.join 'git', name @@ -534,7 +534,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni head = nil Dir.chdir directory do - unless File.exist? '.git' then + unless File.exist? '.git' system @git, 'init', '--quiet' system @git, 'config', 'user.name', 'RubyGems Tests' system @git, 'config', 'user.email', 'rubygems@example' @@ -557,7 +557,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni skip 'cannot find git executable, use GIT environment variable to set' end - def in_path? executable # :nodoc: + def in_path?(executable) # :nodoc: return true if %r%\A([A-Z]:|/)% =~ executable and File.exist? executable ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory| @@ -568,12 +568,12 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ## # Builds and installs the Gem::Specification +spec+ - def install_gem spec, options = {} + def install_gem(spec, options = {}) require 'rubygems/installer' gem = File.join @tempdir, "gems", "#{spec.full_name}.gem" - unless File.exist? gem then + unless File.exist? gem use_ui Gem::MockGemUi.new do Dir.chdir @tempdir do Gem::Package.build spec @@ -589,17 +589,17 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ## # Builds and installs the Gem::Specification +spec+ into the user dir - def install_gem_user spec + def install_gem_user(spec) install_gem spec, :user_install => true end ## # Uninstalls the Gem::Specification +spec+ - def uninstall_gem spec + def uninstall_gem(spec) require 'rubygems/uninstaller' Class.new(Gem::Uninstaller) { - def ask_if_ok spec + def ask_if_ok(spec) true end }.new(spec.name, :executables => true, :user_install => true).uninstall @@ -704,7 +704,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ## # TODO: remove in RubyGems 4.0 - def quick_spec name, version = '2' # :nodoc: + def quick_spec(name, version = '2') # :nodoc: util_spec name, version end deprecate :quick_spec, :util_spec, 2018, 12 @@ -808,7 +808,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # # TODO: remove in RubyGems 4.0 - def new_spec name, version, deps = nil, *files # :nodoc: + def new_spec(name, version, deps = nil, *files) # :nodoc: require 'rubygems/specification' spec = Gem::Specification.new do |s| @@ -832,7 +832,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni spec.loaded_from = spec.spec_file - unless files.empty? then + unless files.empty? write_file spec.spec_file do |io| io.write spec.to_ruby_for_cache end @@ -872,7 +872,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # Creates a spec with +name+, +version+. +deps+ can specify the dependency # or a +block+ can be given for full customization of the specification. - def util_spec name, version = 2, deps = nil, *files # :yields: specification + def util_spec(name, version = 2, deps = nil, *files) # :yields: specification raise "deps or block, not both" if deps and block_given? spec = Gem::Specification.new do |s| @@ -890,7 +890,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni yield s if block_given? end - if deps then + if deps # Since Hash#each is unordered in 1.8, sort the keys and iterate that # way so the tests are deterministic on all implementations. deps.keys.sort.each do |n| @@ -898,7 +898,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end end - unless files.empty? then + unless files.empty? write_file spec.spec_file do |io| io.write spec.to_ruby_for_cache end @@ -926,7 +926,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # TODO: deprecate raise "deps or block, not both" if deps and block - if deps then + if deps block = proc do |s| # Since Hash#each is unordered in 1.8, sort # the keys and iterate that way so the tests are @@ -1122,7 +1122,7 @@ Also, a list: end # HACK for test_download_to_cache - unless Gem::RemoteFetcher === @fetcher then + unless Gem::RemoteFetcher === @fetcher v = Gem.marshal_version specs = all.map { |spec| spec.name_tuple } @@ -1161,35 +1161,51 @@ Also, a list: Zlib::Deflate.deflate data end - def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil) + def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil, description = nil, engine = "ruby", engine_version = nil) if Gem.instance_variables.include? :@ruby_version or - Gem.instance_variables.include? '@ruby_version' then + Gem.instance_variables.include? '@ruby_version' Gem.send :remove_instance_variable, :@ruby_version end - @RUBY_VERSION = RUBY_VERSION - @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) - @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION) + @RUBY_VERSION = RUBY_VERSION + @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) + @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION) + @RUBY_DESCRIPTION = RUBY_DESCRIPTION if defined?(RUBY_DESCRIPTION) + @RUBY_ENGINE = RUBY_ENGINE + @RUBY_ENGINE_VERSION = RUBY_ENGINE_VERSION if defined?(RUBY_ENGINE_VERSION) - Object.send :remove_const, :RUBY_VERSION - Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) - Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + util_clear_RUBY_VERSION - Object.const_set :RUBY_VERSION, version - Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel - Object.const_set :RUBY_REVISION, revision if revision + Object.const_set :RUBY_VERSION, version + Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel + Object.const_set :RUBY_REVISION, revision if revision + Object.const_set :RUBY_DESCRIPTION, description if description + Object.const_set :RUBY_ENGINE, engine + Object.const_set :RUBY_ENGINE_VERSION, engine_version if engine_version end def util_restore_RUBY_VERSION - Object.send :remove_const, :RUBY_VERSION - Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) - Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + util_clear_RUBY_VERSION - Object.const_set :RUBY_VERSION, @RUBY_VERSION - Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if + Object.const_set :RUBY_VERSION, @RUBY_VERSION + Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if defined?(@RUBY_PATCHLEVEL) - Object.const_set :RUBY_REVISION, @RUBY_REVISION if + Object.const_set :RUBY_REVISION, @RUBY_REVISION if defined?(@RUBY_REVISION) + Object.const_set :RUBY_DESCRIPTION, @RUBY_DESCRIPTION if + defined?(@RUBY_DESCRIPTION) + Object.const_set :RUBY_ENGINE, @RUBY_ENGINE + Object.const_set :RUBY_ENGINE_VERSION, @RUBY_ENGINE_VERSION if + defined?(@RUBY_ENGINE_VERSION) + end + + def util_clear_RUBY_VERSION + Object.send :remove_const, :RUBY_VERSION + Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) + Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + Object.send :remove_const, :RUBY_DESCRIPTION if defined?(RUBY_DESCRIPTION) + Object.send :remove_const, :RUBY_ENGINE + Object.send :remove_const, :RUBY_ENGINE_VERSION if defined?(RUBY_ENGINE_VERSION) end ## @@ -1343,7 +1359,7 @@ Also, a list: ## # Construct a new Gem::Dependency. - def dep name, *requirements + def dep(name, *requirements) Gem::Dependency.new name, *requirements end @@ -1352,10 +1368,10 @@ Also, a list: # Gem::Dependency +dep+, a +from_name+ and +from_version+ requesting the # dependency and a +parent+ DependencyRequest - def dependency_request dep, from_name, from_version, parent = nil + def dependency_request(dep, from_name, from_version, parent = nil) remote = Gem::Source.new @uri - unless parent then + unless parent parent_dep = dep from_name, from_version parent = Gem::Resolver::DependencyRequest.new parent_dep, nil end @@ -1370,7 +1386,7 @@ Also, a list: ## # Constructs a new Gem::Requirement. - def req *requirements + def req(*requirements) return requirements.first if Gem::Requirement === requirements.first Gem::Requirement.create requirements end @@ -1378,7 +1394,7 @@ Also, a list: ## # Constructs a new Gem::Specification. - def spec name, version, &block + def spec(name, version, &block) Gem::Specification.new name, v(version), &block end @@ -1402,7 +1418,7 @@ Also, a list: # end # end - def spec_fetcher repository = @gem_repo + def spec_fetcher(repository = @gem_repo) Gem::TestCase::SpecFetcherSetup.declare self, repository do |spec_fetcher_setup| yield spec_fetcher_setup if block_given? end @@ -1411,7 +1427,7 @@ Also, a list: ## # Construct a new Gem::Version. - def v string + def v(string) Gem::Version.create string end @@ -1421,7 +1437,7 @@ Also, a list: # # Yields the +specification+ to the block, if given - def vendor_gem name = 'a', version = 1 + def vendor_gem(name = 'a', version = 1) directory = File.join 'vendor', name FileUtils.mkdir_p directory @@ -1435,7 +1451,7 @@ Also, a list: # # Yields the +specification+ to the block, if given - def save_gemspec name = 'a', version = 1, directory = '.' + def save_gemspec(name = 'a', version = 1, directory = '.') vendor_spec = Gem::Specification.new name, version do |specification| yield specification if block_given? end @@ -1472,7 +1488,7 @@ Also, a list: ## # Adds +spec+ to this set. - def add spec + def add(spec) @specs << spec end @@ -1496,7 +1512,7 @@ Also, a list: # Loads a Gem::Specification from this set which has the given +name+, # version +ver+, +platform+. The +source+ is ignored. - def load_spec name, ver, platform, source + def load_spec(name, ver, platform, source) dep = Gem::Dependency.new name, ver spec = find_spec dep @@ -1505,14 +1521,14 @@ Also, a list: end end - def prefetch reqs # :nodoc: + def prefetch(reqs) # :nodoc: end end ## # Loads certificate named +cert_name+ from test/rubygems/. - def self.load_cert cert_name + def self.load_cert(cert_name) cert_file = cert_path cert_name cert = File.read cert_file @@ -1524,8 +1540,8 @@ Also, a list: # Returns the path to the certificate named +cert_name+ from # test/rubygems/. - def self.cert_path cert_name - if 32 == (Time.at(2**32) rescue 32) then + def self.cert_path(cert_name) + if 32 == (Time.at(2**32) rescue 32) cert_file = File.expand_path "../../../test/rubygems/#{cert_name}_cert_32.pem", __FILE__ @@ -1539,7 +1555,7 @@ Also, a list: ## # Loads an RSA private key named +key_name+ with +passphrase+ in test/rubygems/ - def self.load_key key_name, passphrase = nil + def self.load_key(key_name, passphrase = nil) key_file = key_path key_name key = File.read key_file @@ -1550,7 +1566,7 @@ Also, a list: ## # Returns the path to the key named +key_name+ from test/rubygems - def self.key_path key_name + def self.key_path(key_name) File.expand_path "../../../test/rubygems/#{key_name}_key.pem", __FILE__ end diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb index 1ec142937a..fe7eff8d8c 100644 --- a/lib/rubygems/test_utilities.rb +++ b/lib/rubygems/test_utilities.rb @@ -35,7 +35,7 @@ class Gem::FakeFetcher def find_data(path) return File.read path.path if URI === path and 'file' == path.scheme - if URI === path and "URI::#{path.scheme.upcase}" != path.class.name then + if URI === path and "URI::#{path.scheme.upcase}" != path.class.name raise ArgumentError, "mismatch for scheme #{path.scheme} and class #{path.class}" end @@ -44,20 +44,20 @@ class Gem::FakeFetcher @paths << path raise ArgumentError, 'need full URI' unless path =~ %r'^https?://' - unless @data.key? path then + unless @data.key? path raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path) end @data[path] end - def fetch_path path, mtime = nil, head = false + def fetch_path(path, mtime = nil, head = false) data = find_data(path) - if data.respond_to?(:call) then + if data.respond_to?(:call) data.call else - if path.to_s =~ /gz$/ and not data.nil? and not data.empty? then + if path.to_s =~ /gz$/ and not data.nil? and not data.empty? data = Gem::Util.gunzip data end @@ -65,7 +65,7 @@ class Gem::FakeFetcher end end - def cache_update_path uri, path = nil, update = true + def cache_update_path(uri, path = nil, update = true) if data = fetch_path(uri) open(path, 'wb') { |io| io.write data } if path and update data @@ -98,7 +98,7 @@ class Gem::FakeFetcher response end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[FakeFetcher', ']' do q.breakable q.text 'URIs:' @@ -114,7 +114,7 @@ class Gem::FakeFetcher raise ArgumentError, 'need full URI' unless path =~ %r'^http://' - unless @data.key? path then + unless @data.key? path raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path) end @@ -123,9 +123,9 @@ class Gem::FakeFetcher data.respond_to?(:call) ? data.call : data.length end - def download spec, source_uri, install_dir = Gem.dir + def download(spec, source_uri, install_dir = Gem.dir) name = File.basename spec.cache_file - path = if Dir.pwd == install_dir then # see fetch_command + path = if Dir.pwd == install_dir # see fetch_command install_dir else File.join install_dir, "cache" @@ -133,7 +133,7 @@ class Gem::FakeFetcher path = File.join path, name - if source_uri =~ /^http/ then + if source_uri =~ /^http/ File.open(path, "wb") do |f| f.write fetch_path(File.join(source_uri, "gems", name)) end @@ -144,7 +144,7 @@ class Gem::FakeFetcher path end - def download_to_cache dependency + def download_to_cache(dependency) found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dependency return if found.empty? @@ -187,7 +187,7 @@ class Gem::TestCase::SpecFetcherSetup # Executes a SpecFetcher setup block. Yields an instance then creates the # gems and specifications defined in the instance. - def self.declare test, repository + def self.declare(test, repository) setup = new test, repository yield setup @@ -195,7 +195,7 @@ class Gem::TestCase::SpecFetcherSetup setup.execute end - def initialize test, repository # :nodoc: + def initialize(test, repository) # :nodoc: @test = test @repository = repository @@ -263,7 +263,7 @@ class Gem::TestCase::SpecFetcherSetup # The specification will be yielded before gem creation for customization, # but only the block or the dependencies may be set, not both. - def gem name, version, dependencies = nil, &block + def gem(name, version, dependencies = nil, &block) @operations << [:gem, name, version, dependencies, block] end @@ -274,7 +274,7 @@ class Gem::TestCase::SpecFetcherSetup # The specification will be yielded before gem creation for customization, # but only the block or the dependencies may be set, not both. - def download name, version, dependencies = nil, &block + def download(name, version, dependencies = nil, &block) @operations << [:download, name, version, dependencies, block] end @@ -293,7 +293,7 @@ class Gem::TestCase::SpecFetcherSetup require 'socket' require 'rubygems/remote_fetcher' - unless @test.fetcher then + unless @test.fetcher @test.fetcher = Gem::FakeFetcher.new Gem::RemoteFetcher.fetcher = @test.fetcher end @@ -327,11 +327,11 @@ class Gem::TestCase::SpecFetcherSetup # The specification will be yielded before creation for customization, # but only the block or the dependencies may be set, not both. - def spec name, version, dependencies = nil, &block + def spec(name, version, dependencies = nil, &block) @operations << [:spec, name, version, dependencies, block] end - def write_spec spec # :nodoc: + def write_spec(spec) # :nodoc: File.open spec.spec_file, 'w' do |io| io.write spec.to_ruby_for_cache end @@ -367,4 +367,3 @@ class TempIO < Tempfile Gem.read_binary path end end - diff --git a/lib/rubygems/text.rb b/lib/rubygems/text.rb index 52580e780c..5d346b496b 100644 --- a/lib/rubygems/text.rb +++ b/lib/rubygems/text.rb @@ -28,7 +28,7 @@ module Gem::Text work = clean_text(text) while work.length > wrap do - if work =~ /^(.{0,#{wrap}})[ \n]/ then + if work =~ /^(.{0,#{wrap}})[ \n]/ result << $1.rstrip work.slice!(0, $&.length) else @@ -40,10 +40,10 @@ module Gem::Text result.join("\n").gsub(/^/, " " * indent) end - def min3 a, b, c # :nodoc: - if a < b && a < c then + def min3(a, b, c) # :nodoc: + if a < b && a < c a - elsif b < c then + elsif b < c b else c @@ -52,7 +52,7 @@ module Gem::Text # This code is based directly on the Text gem implementation # Returns a value representing the "cost" of transforming str1 into str2 - def levenshtein_distance str1, str2 + def levenshtein_distance(str1, str2) s = str1 t = str2 n = s.length diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index ee0467c7bf..c213cf656e 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -99,7 +99,7 @@ class Gem::Uninstaller list.sort! - if list.empty? then + if list.empty? if other_repo_specs.empty? if default_specs.empty? raise Gem::InstallError, "gem #{@gem.inspect} is not installed" @@ -119,19 +119,19 @@ class Gem::Uninstaller } raise Gem::InstallError, message.join("\n") - elsif @force_all then + elsif @force_all remove_all list - elsif list.size > 1 then + elsif list.size > 1 gem_names = list.map { |gem| gem.full_name } gem_names << "All versions" say _, index = choose_from_list "Select gem to uninstall:", gem_names - if index == list.size then + if index == list.size remove_all list - elsif index >= 0 && index < list.size then + elsif index >= 0 && index < list.size uninstall_gem list[index] else say "Error: must enter a number [1-#{list.size+1}]" @@ -194,7 +194,7 @@ class Gem::Uninstaller executables = executables.map { |exec| formatted_program_filename exec } - remove = if @force_executables.nil? then + remove = if @force_executables.nil? ask_yes_no("Remove executables:\n" + "\t#{executables.join ', '}\n\n" + "in addition to the gem?", @@ -203,7 +203,7 @@ class Gem::Uninstaller @force_executables end - if remove then + if remove bin_dir = @bin_dir || Gem.bindir(spec.base_dir) raise Gem::FilePermissionError, bin_dir unless File.writable? bin_dir @@ -239,7 +239,7 @@ class Gem::Uninstaller def remove(spec) unless path_ok?(@gem_home, spec) or - (@user_install and path_ok?(Gem.user_dir, spec)) then + (@user_install and path_ok?(Gem.user_dir, spec)) e = Gem::GemNotInHomeException.new \ "Gem '#{spec.full_name}' is not installed in directory #{@gem_home}" e.spec = spec @@ -265,7 +265,7 @@ class Gem::Uninstaller gemspec = spec.spec_file - unless File.exist? gemspec then + unless File.exist? gemspec gemspec = File.join(File.dirname(gemspec), "#{old_platform_name}.gemspec") end @@ -289,7 +289,7 @@ class Gem::Uninstaller # Returns true if it is OK to remove +spec+ or this is a forced # uninstallation. - def dependencies_ok? spec # :nodoc: + def dependencies_ok?(spec) # :nodoc: return true if @force_ignore deplist = Gem::DependencyList.from_specs @@ -308,7 +308,7 @@ class Gem::Uninstaller ## # Asks if it is OK to remove +spec+. Returns true if it is OK. - def ask_if_ok spec # :nodoc: + def ask_if_ok(spec) # :nodoc: msg = [''] msg << 'You have requested to uninstall the gem:' msg << "\t#{spec.full_name}" @@ -332,11 +332,11 @@ class Gem::Uninstaller ## # Returns the formatted version of the executable +filename+ - def formatted_program_filename filename # :nodoc: + def formatted_program_filename(filename) # :nodoc: # TODO perhaps the installer should leave a small manifest # of what it did for us to find rather than trying to recreate # it again. - if @format_executable then + if @format_executable require 'rubygems/installer' Gem::Installer.exec_format % File.basename(filename) else diff --git a/lib/rubygems/uri_formatter.rb b/lib/rubygems/uri_formatter.rb index bb128e4ef9..0a24dde24d 100644 --- a/lib/rubygems/uri_formatter.rb +++ b/lib/rubygems/uri_formatter.rb @@ -19,7 +19,7 @@ class Gem::UriFormatter ## # Creates a new URI formatter for +uri+. - def initialize uri + def initialize(uri) @uri = uri end @@ -47,4 +47,3 @@ class Gem::UriFormatter end end - diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 61e85549da..03eac76ea8 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -95,7 +95,7 @@ module Gem::UserInteraction ## # Displays an alert +statement+. Asks a +question+ if given. - def alert statement, question = nil + def alert(statement, question = nil) ui.alert statement, question end @@ -103,7 +103,7 @@ module Gem::UserInteraction # Displays an error +statement+ to the error output location. Asks a # +question+ if given. - def alert_error statement, question = nil + def alert_error(statement, question = nil) ui.alert_error statement, question end @@ -111,49 +111,49 @@ module Gem::UserInteraction # Displays a warning +statement+ to the warning output location. Asks a # +question+ if given. - def alert_warning statement, question = nil + def alert_warning(statement, question = nil) ui.alert_warning statement, question end ## # Asks a +question+ and returns the answer. - def ask question + def ask(question) ui.ask question end ## # Asks for a password with a +prompt+ - def ask_for_password prompt + def ask_for_password(prompt) ui.ask_for_password prompt end ## # Asks a yes or no +question+. Returns true for yes, false for no. - def ask_yes_no question, default = nil + def ask_yes_no(question, default = nil) ui.ask_yes_no question, default end ## # Asks the user to answer +question+ with an answer from the given +list+. - def choose_from_list question, list + def choose_from_list(question, list) ui.choose_from_list question, list end ## # Displays the given +statement+ on the standard output (or equivalent). - def say statement = '' + def say(statement = '') ui.say statement end ## # Terminates the RubyGems process with the given +exit_code+ - def terminate_interaction exit_code = 0 + def terminate_interaction(exit_code = 0) ui.terminate_interaction exit_code end @@ -161,7 +161,7 @@ module Gem::UserInteraction # Calls +say+ with +msg+ or the results of the block if really_verbose # is true. - def verbose msg = nil + def verbose(msg = nil) say(msg || yield) if Gem.configuration.really_verbose end end @@ -212,7 +212,7 @@ class Gem::StreamUI # Prints a formatted backtrace to the errors stream if backtraces are # enabled. - def backtrace exception + def backtrace(exception) return unless Gem.configuration.backtrace @errs.puts "\t#{exception.backtrace.join "\n\t"}" @@ -247,8 +247,8 @@ class Gem::StreamUI # default. def ask_yes_no(question, default=nil) - unless tty? then - if default.nil? then + unless tty? + if default.nil? raise Gem::OperationNotSupportedError, "Not connected to a tty and no default specified" else @@ -568,6 +568,7 @@ class Gem::StreamUI # +out_stream+. The other arguments are ignored. def initialize(out_stream, *args) + @file_name = nil @out = out_stream end diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb index 6dbcd4ba21..60d552ddb3 100644 --- a/lib/rubygems/util.rb +++ b/lib/rubygems/util.rb @@ -46,7 +46,7 @@ module Gem::Util # and implements an IO.popen-like behavior where it does not accept an array # for a command. - def self.popen *command + def self.popen(*command) IO.popen command, &:read rescue TypeError # ruby 1.8 only supports string command r, w = IO.pipe @@ -70,7 +70,7 @@ module Gem::Util ## # Invokes system, but silences all output. - def self.silent_system *command + def self.silent_system(*command) opt = {:out => IO::NULL, :err => [:child, :out]} if Hash === command.last opt.update(command.last) @@ -103,7 +103,7 @@ module Gem::Util ## # Enumerates the parents of +directory+. - def self.traverse_parents directory, &block + def self.traverse_parents(directory, &block) return enum_for __method__, directory unless block_given? here = File.expand_path directory diff --git a/lib/rubygems/util/list.rb b/lib/rubygems/util/list.rb index 9c25f6b6dc..33c40af4bb 100644 --- a/lib/rubygems/util/list.rb +++ b/lib/rubygems/util/list.rb @@ -25,7 +25,7 @@ module Gem List.new value, self end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.pp to_a end diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb index 6842e4fa9c..828497f700 100644 --- a/lib/rubygems/validator.rb +++ b/lib/rubygems/validator.rb @@ -62,7 +62,7 @@ class Gem::Validator # Describes a problem with a file in a gem. ErrorData = Struct.new :path, :problem do - def <=> other # :nodoc: + def <=>(other) # :nodoc: return nil unless self.class === other [path, problem] <=> [other.path, other.problem] @@ -94,13 +94,13 @@ class Gem::Validator spec_path = spec.spec_file gem_directory = spec.full_gem_path - unless File.directory? gem_directory then + unless File.directory? gem_directory errors[gem_name][spec.full_name] = "Gem registered but doesn't exist at #{gem_directory}" next end - unless File.exist? spec_path then + unless File.exist? spec_path errors[gem_name][spec_path] = "Spec file missing for installed gem" end @@ -135,7 +135,7 @@ class Gem::Validator source = File.join gem_directory, entry['path'] File.open source, Gem.binary_mode do |f| - unless f.read == data then + unless f.read == data errors[gem_name][entry['path']] = "Modified from original" end end @@ -163,4 +163,3 @@ class Gem::Validator errors end end - diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index d700aebd5d..fb7609c7c6 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -155,7 +155,7 @@ class Gem::Version include Comparable VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?'.freeze # :nodoc: - ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/ # :nodoc: + ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/.freeze # :nodoc: ## # A string representation of this Version. @@ -169,7 +169,7 @@ class Gem::Version ## # True if the +version+ string matches RubyGems' requirements. - def self.correct? version + def self.correct?(version) unless Gem::Deprecate.skip warn "nil versions are discouraged and will be deprecated in Rubygems 4" if version.nil? end @@ -185,10 +185,10 @@ class Gem::Version # ver2 = Version.create(ver1) # -> (ver1) # ver3 = Version.create(nil) # -> nil - def self.create input - if self === input then # check yourself before you wreck yourself + def self.create(input) + if self === input # check yourself before you wreck yourself input - elsif input.nil? then + elsif input.nil? nil else new input @@ -197,7 +197,7 @@ class Gem::Version @@all = {} - def self.new version # :nodoc: + def self.new(version) # :nodoc: return super unless Gem::Version == self @@all[version] ||= super @@ -207,7 +207,7 @@ class Gem::Version # Constructs a Version from the +version+ string. A version string is a # series of digits or ASCII letters separated by dots. - def initialize version + def initialize(version) unless self.class.correct?(version) raise ArgumentError, "Malformed version number string #{version}" end @@ -240,7 +240,7 @@ class Gem::Version # A Version is only eql? to another version if it's specified to the # same precision. Version "1.0" is not the same as version "1". - def eql? other + def eql?(other) self.class === other and @version == other._version end @@ -248,7 +248,7 @@ class Gem::Version canonical_segments.hash end - def init_with coder # :nodoc: + def init_with(coder) # :nodoc: yaml_initialize coder.tag, coder.map end @@ -268,7 +268,7 @@ class Gem::Version # Load custom marshal format. It's a string for backwards (RubyGems # 1.3.5 and earlier) compatibility. - def marshal_load array + def marshal_load(array) initialize array[0] end @@ -282,7 +282,7 @@ class Gem::Version ["@version"] end - def encode_with coder # :nodoc: + def encode_with(coder) # :nodoc: coder.add 'version', @version end @@ -296,7 +296,7 @@ class Gem::Version @prerelease end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.text "Gem::Version.new(#{version.inspect})" end @@ -339,7 +339,7 @@ class Gem::Version # one. Attempts to compare to something that's not a # Gem::Version return +nil+. - def <=> other + def <=>(other) return unless Gem::Version === other return 0 if @version == other._version || canonical_segments == other.canonical_segments diff --git a/lib/rubygems/version_option.rb b/lib/rubygems/version_option.rb index c4d3306652..458a7a6601 100644 --- a/lib/rubygems/version_option.rb +++ b/lib/rubygems/version_option.rb @@ -17,7 +17,7 @@ module Gem::VersionOption def add_platform_option(task = command, *wrap) OptionParser.accept Gem::Platform do |value| - if value == Gem::Platform::RUBY then + if value == Gem::Platform::RUBY value else Gem::Platform.new value @@ -27,7 +27,7 @@ module Gem::VersionOption add_option('--platform PLATFORM', Gem::Platform, "Specify the platform of gem to #{task}", *wrap) do |value, options| - unless options[:added_platform] then + unless options[:added_platform] Gem.platforms = [Gem::Platform::RUBY] options[:added_platform] = true end @@ -74,4 +74,3 @@ module Gem::VersionOption end end - -- cgit v1.2.3