diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-14 12:59:03 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-14 12:59:03 +0000 |
commit | 4ae3df42f723d25b0fe4ba6b2689d607b01c6f48 (patch) | |
tree | 26c5f5cf033f79373e63b10f684df07898b7cd8f /lib | |
parent | d1e6304a891fc5e9cc63e50520bdc798fb95b829 (diff) |
Merge RubyGems master@9be7858f7f17eae3058204f3c03e4b798ba18b9c
This version contains the some style changes by RuboCop.
* https://github.com/rubygems/rubygems/commit/9d810be0ede925fb2e3af535848582c3f8e0e72f
* https://github.com/rubygems/rubygems/commit/61ea98a727fb1b76b6fac52d74107ee4b02aaef2
* https://github.com/rubygems/rubygems/commit/795893dce3c5f8540804fc08144cc6a90f086b13
* https://github.com/rubygems/rubygems/commit/9be7858f7f17eae3058204f3c03e4b798ba18b9c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
88 files changed, 360 insertions, 184 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb index d31c216142..d0933e1b6c 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -271,9 +271,9 @@ module Gem specs = dep.matching_specs(true) - specs = specs.find_all { |spec| + specs = specs.find_all do |spec| spec.executables.include? exec_name - } if exec_name + end if exec_name unless spec = specs.first msg = "can't find gem #{dep} with executable #{exec_name}" @@ -521,9 +521,9 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.find_files_from_load_path(glob) # :nodoc: glob_with_suffixes = "#{glob}#{Gem.suffix_pattern}" - $LOAD_PATH.map { |load_path| + $LOAD_PATH.map do |load_path| Gem::Util.glob_files_in_dir(glob_with_suffixes, load_path) - }.flatten.select { |file| File.file? file.untaint } + end.flatten.select { |file| File.file? file.untaint } end ## @@ -593,8 +593,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + extend Gem::Deprecate deprecate :gunzip, "Gem::Util.gunzip", 2018, 12 + end ## @@ -605,8 +607,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + extend Gem::Deprecate deprecate :gzip, "Gem::Util.gzip", 2018, 12 + end ## @@ -617,8 +621,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + extend Gem::Deprecate deprecate :inflate, "Gem::Util.inflate", 2018, 12 + end ## @@ -1015,11 +1021,11 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.suffixes @suffixes ||= ['', '.rb', - *%w(DLEXT DLEXT2).map { |key| + *%w(DLEXT DLEXT2).map do |key| val = RbConfig::CONFIG[key] next unless val and not val.empty? ".#{val}" - } + end ].compact.uniq end @@ -1211,6 +1217,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + ## # TODO remove with RubyGems 4.0 @@ -1218,6 +1225,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} extend Gem::Deprecate deprecate :detect_gemdeps, "Gem.use_gemdeps", 2018, 12 + end # FIX: Almost everywhere else we use the `def self.` way of defining class @@ -1337,6 +1345,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # work attr_reader :pre_uninstall_hooks + end ## diff --git a/lib/rubygems/available_set.rb b/lib/rubygems/available_set.rb index 8334a73ecb..2e9d9496f6 100644 --- a/lib/rubygems/available_set.rb +++ b/lib/rubygems/available_set.rb @@ -162,4 +162,5 @@ class Gem::AvailableSet def inject_into_list(dep_list) @set.each { |t| dep_list.add t.spec } end + end diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index d1878021ba..edb38cb1c2 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -329,4 +329,5 @@ class Gem::BasicSpecification false end end + end diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 5b8868b0cd..a509b783dd 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -122,6 +122,7 @@ class Gem::Command @defaults = defaults @options = defaults.dup @option_groups = Hash.new { |h,k| h[k] = [] } + @deprecated_options = { command => {} } @parser = nil @when_invoked = nil end @@ -365,13 +366,34 @@ class Gem::Command end end + def deprecate_option(short_name: nil, long_name: nil, version: nil) + @deprecated_options[command].merge!({ short_name => { "rg_version_to_expire" => version } }) if short_name + @deprecated_options[command].merge!({ long_name => { "rg_version_to_expire" => version } }) if long_name + end + + def check_deprecated_options(options) + options.each do |option| + if option_is_deprecated?(option) + version_to_expire = @deprecated_options[command][option]["rg_version_to_expire"] + + deprecate_option_msg = if version_to_expire + "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}, its use is discouraged." + else + "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems, its use is discouraged." + end + + alert_warning(deprecate_option_msg) + end + end + end + ## # Merge a set of command options with the set of default options (without # modifying the default option hash). def merge_options(new_options) @options = @defaults.clone - new_options.each do |k,v| @options[k] = v end + new_options.each { |k,v| @options[k] = v } end ## @@ -392,6 +414,7 @@ class Gem::Command def handle_options(args) args = add_extra_args(args) + check_deprecated_options(args) @options = Marshal.load Marshal.dump @defaults # deep copy parser.parse!(args) @options[:args] = args @@ -420,6 +443,10 @@ class Gem::Command private + def option_is_deprecated?(option) + @deprecated_options[command].has_key?(option) + end + def add_parser_description # :nodoc: return unless description diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index 761b80ee94..9d318e6e8b 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -96,4 +96,5 @@ Gems can be saved to a specified filename with the output option: terminate_interaction 1 end end + end diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb index aeb4d82fae..fedaec8448 100644 --- a/lib/rubygems/commands/cleanup_command.rb +++ b/lib/rubygems/commands/cleanup_command.rb @@ -99,7 +99,7 @@ If no gems are named all gems in GEM_HOME are cleaned. @full = Gem::DependencyList.from_specs deplist = Gem::DependencyList.new - @gems_to_cleanup.each do |spec| deplist.add spec end + @gems_to_cleanup.each { |spec| deplist.add spec } deps = deplist.strongly_connected_components.flatten @@ -121,19 +121,19 @@ 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| + gems_to_cleanup = @candidate_gems.select do |spec| @primary_gems[spec.name].version != spec.version - } + end - default_gems, gems_to_cleanup = gems_to_cleanup.partition { |spec| + default_gems, gems_to_cleanup = gems_to_cleanup.partition do |spec| spec.default_gem? - } + end uninstall_from = options[:user_install] ? Gem.user_dir : @original_home - gems_to_cleanup = gems_to_cleanup.select { |spec| + gems_to_cleanup = gems_to_cleanup.select do |spec| spec.base_dir == uninstall_from - } + end @default_gems += default_gems @default_gems.uniq! diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb index 6da89a136e..26d6828fe6 100644 --- a/lib/rubygems/commands/contents_command.rb +++ b/lib/rubygems/commands/contents_command.rb @@ -14,7 +14,7 @@ class Gem::Commands::ContentsCommand < Gem::Command add_version_option - add_option( '--all', + add_option('--all', "Contents for all gems") do |all, options| options[:all] = all end @@ -29,12 +29,12 @@ class Gem::Commands::ContentsCommand < Gem::Command options[:lib_only] = lib_only end - add_option( '--[no-]prefix', + add_option('--[no-]prefix', "Don't include installed path prefix") do |prefix, options| options[:prefix] = prefix end - add_option( '--[no-]show-install-dir', + add_option('--[no-]show-install-dir', 'Show only the gem install dir') do |show, options| options[:show_install_dir] = show end diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb index 9e88b04ea5..8e198ac93a 100644 --- a/lib/rubygems/commands/dependency_command.rb +++ b/lib/rubygems/commands/dependency_command.rb @@ -80,9 +80,9 @@ use with other commands. end def gem_dependency(pattern, version, prerelease) # :nodoc: - dependency = Gem::Deprecate.skip_during { + dependency = Gem::Deprecate.skip_during do Gem::Dependency.new pattern, version - } + end dependency.prerelease = prerelease @@ -215,4 +215,5 @@ use with other commands. /\A#{Regexp.union(*args)}/ end end + end diff --git a/lib/rubygems/commands/info_command.rb b/lib/rubygems/commands/info_command.rb index 8d9611a957..6a737b178b 100644 --- a/lib/rubygems/commands/info_command.rb +++ b/lib/rubygems/commands/info_command.rb @@ -4,6 +4,7 @@ require 'rubygems/command' require 'rubygems/commands/query_command' class Gem::Commands::InfoCommand < Gem::Commands::QueryCommand + def initialize super "info", "Show information for the given gem" @@ -30,4 +31,5 @@ class Gem::Commands::InfoCommand < Gem::Commands::QueryCommand def defaults_str "--local" end + end diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index 776b58651f..82631b1ffd 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -201,10 +201,13 @@ You can use `i` command instead of `install`. request_set = inst.resolve_dependencies name, req if options[:explain] - puts "Gems to install:" + say "Gems to install:" request_set.sorted_requests.each do |s| - puts " #{s.full_name}" + # shows platform specific gems if used + say (plat = s.spec.platform) == Gem::Platform::RUBY ? + " #{s.full_name}" : + " #{s.full_name}-#{plat}" end return diff --git a/lib/rubygems/commands/lock_command.rb b/lib/rubygems/commands/lock_command.rb index 7f02e9feda..ebb402a8bd 100644 --- a/lib/rubygems/commands/lock_command.rb +++ b/lib/rubygems/commands/lock_command.rb @@ -100,9 +100,9 @@ lock it down to the exact version. end def spec_path(gem_full_name) - gemspecs = Gem.path.map { |path| + gemspecs = Gem.path.map do |path| File.join path, "specifications", "#{gem_full_name}.gemspec" - } + end gemspecs.find { |path| File.exist? path } end diff --git a/lib/rubygems/commands/mirror_command.rb b/lib/rubygems/commands/mirror_command.rb index 801c9c8927..4e2a41fa33 100644 --- a/lib/rubygems/commands/mirror_command.rb +++ b/lib/rubygems/commands/mirror_command.rb @@ -3,6 +3,7 @@ require 'rubygems/command' unless defined? Gem::Commands::MirrorCommand class Gem::Commands::MirrorCommand < Gem::Command + def initialize super('mirror', 'Mirror all gem files (requires rubygems-mirror)') begin diff --git a/lib/rubygems/commands/open_command.rb b/lib/rubygems/commands/open_command.rb index 2794fe05e6..8eaeb64ba9 100644 --- a/lib/rubygems/commands/open_command.rb +++ b/lib/rubygems/commands/open_command.rb @@ -17,7 +17,7 @@ class Gem::Commands::OpenCommand < Gem::Command end add_option('-v', '--version VERSION', String, "Opens specific gem version") do |version| - options[:version] = version + options[:version] = version end end @@ -84,4 +84,5 @@ class Gem::Commands::OpenCommand < Gem::Command say "Unable to find gem '#{name}'" end + end diff --git a/lib/rubygems/commands/outdated_command.rb b/lib/rubygems/commands/outdated_command.rb index 70f6c02801..035eaffcbc 100644 --- a/lib/rubygems/commands/outdated_command.rb +++ b/lib/rubygems/commands/outdated_command.rb @@ -30,4 +30,5 @@ update the gems with the update or install commands. say "#{spec.name} (#{spec.version} < #{remote_version})" end end + end diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb index 799f31704a..9fcabaa9f8 100644 --- a/lib/rubygems/commands/owner_command.rb +++ b/lib/rubygems/commands/owner_command.rb @@ -4,6 +4,7 @@ require 'rubygems/local_remote_options' require 'rubygems/gemcutter_utilities' class Gem::Commands::OwnerCommand < Gem::Command + include Gem::LocalRemoteOptions include Gem::GemcutterUtilities @@ -60,6 +61,8 @@ permission to. end def show_owners(name) + Gem.load_yaml + response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request| request.add_field "Authorization", api_key end diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index 41decde856..1d0eb61700 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -183,4 +183,5 @@ extensions will be restored. say "Restored #{spec.full_name}" end end + end diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 55ee3ae73f..7fd1119ff9 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -5,6 +5,7 @@ require 'rubygems/gemcutter_utilities' require 'rubygems/package' class Gem::Commands::PushCommand < Gem::Command + include Gem::LocalRemoteOptions include Gem::GemcutterUtilities @@ -145,4 +146,5 @@ You can upgrade or downgrade to the latest release version with: gem_metadata["allowed_push_host"] ] end + end diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index d947d588ef..5a42d45249 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -39,7 +39,7 @@ class Gem::Commands::QueryCommand < Gem::Command options[:details] = value end - add_option( '--[no-]versions', + add_option('--[no-]versions', 'Display only gem names') do |value, options| options[:versions] = value options[:details] = false unless value @@ -56,7 +56,7 @@ class Gem::Commands::QueryCommand < Gem::Command options[:exact] = value end - add_option( '--[no-]prerelease', + add_option('--[no-]prerelease', 'Display prerelease versions') do |value, options| options[:prerelease] = value end @@ -141,9 +141,9 @@ is too hard to use. display_header 'LOCAL' - specs = Gem::Specification.find_all { |s| + specs = Gem::Specification.find_all do |s| s.name =~ name and req =~ s.version - } + end spec_tuples = specs.map do |spec| [spec.name_tuple, spec] diff --git a/lib/rubygems/commands/rdoc_command.rb b/lib/rubygems/commands/rdoc_command.rb index 5f8b72eb7a..ff9e1ffcfa 100644 --- a/lib/rubygems/commands/rdoc_command.rb +++ b/lib/rubygems/commands/rdoc_command.rb @@ -5,6 +5,7 @@ require 'rubygems/rdoc' require 'fileutils' class Gem::Commands::RdocCommand < Gem::Command + include Gem::VersionOption def initialize diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index c9c00b5be4..975eca593d 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -6,6 +6,7 @@ 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*$/.freeze VERSION_MATCHER = /^===\s*([\d.a-zA-Z]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/.freeze diff --git a/lib/rubygems/commands/signin_command.rb b/lib/rubygems/commands/signin_command.rb index 0d527fc339..7c4b5ceb69 100644 --- a/lib/rubygems/commands/signin_command.rb +++ b/lib/rubygems/commands/signin_command.rb @@ -3,6 +3,7 @@ require 'rubygems/command' require 'rubygems/gemcutter_utilities' class Gem::Commands::SigninCommand < Gem::Command + include Gem::GemcutterUtilities def initialize diff --git a/lib/rubygems/commands/specification_command.rb b/lib/rubygems/commands/specification_command.rb index 56b9371686..7326822ad7 100644 --- a/lib/rubygems/commands/specification_command.rb +++ b/lib/rubygems/commands/specification_command.rb @@ -143,4 +143,5 @@ Specific fields in the specification can be extracted in YAML format: say "\n" end end + end diff --git a/lib/rubygems/commands/stale_command.rb b/lib/rubygems/commands/stale_command.rb index 0524ee1e2b..89bafeae98 100644 --- a/lib/rubygems/commands/stale_command.rb +++ b/lib/rubygems/commands/stale_command.rb @@ -2,6 +2,7 @@ require 'rubygems/command' class Gem::Commands::StaleCommand < Gem::Command + def initialize super('stale', 'List gems along with access times') end @@ -36,4 +37,5 @@ longer using. say "#{name} at #{atime.strftime '%c'}" end end + end diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 9de0ea722b..698ff4b555 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -185,4 +185,5 @@ that is a dependency of an existing gem. You can use the def uninstall(gem_name) Gem::Uninstaller.new(gem_name, options).uninstall end + end diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 9ab3b80e96..c44dcf0bd8 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -194,7 +194,7 @@ command to remove old versions. } gems_to_update = which_to_update hig, options[:args], :system - _, up_ver = gems_to_update.first + _, up_ver = gems_to_update.first target = if update_latest up_ver diff --git a/lib/rubygems/commands/which_command.rb b/lib/rubygems/commands/which_command.rb index 5c51ed72dd..334bde2622 100644 --- a/lib/rubygems/commands/which_command.rb +++ b/lib/rubygems/commands/which_command.rb @@ -2,6 +2,7 @@ require 'rubygems/command' class Gem::Commands::WhichCommand < Gem::Command + def initialize super 'which', 'Find the location of a library file you can require', :search_gems_first => false, :show_all => false diff --git a/lib/rubygems/commands/yank_command.rb b/lib/rubygems/commands/yank_command.rb index d13b674b48..be675fa460 100644 --- a/lib/rubygems/commands/yank_command.rb +++ b/lib/rubygems/commands/yank_command.rb @@ -5,6 +5,7 @@ require 'rubygems/version_option' require 'rubygems/gemcutter_utilities' class Gem::Commands::YankCommand < Gem::Command + include Gem::LocalRemoteOptions include Gem::VersionOption include Gem::GemcutterUtilities diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index e02655fc51..a5c552dc9f 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -484,4 +484,5 @@ if you believe they were disclosed to a third party. attr_reader :hash protected :hash + end diff --git a/lib/rubygems/core_ext/kernel_gem.rb b/lib/rubygems/core_ext/kernel_gem.rb index b0dd69bfcc..39b00387ea 100644 --- a/lib/rubygems/core_ext/kernel_gem.rb +++ b/lib/rubygems/core_ext/kernel_gem.rb @@ -64,9 +64,9 @@ module Kernel spec = dep.to_spec - Gem::LOADED_SPECS_MUTEX.synchronize { + Gem::LOADED_SPECS_MUTEX.synchronize do spec.activate - } if spec + end if spec end private :gem diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 50f46b32a2..7aa0480b80 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -2,8 +2,8 @@ module Gem DEFAULT_HOST = "https://rubygems.org".freeze - @post_install_hooks ||= [] - @done_installing_hooks ||= [] + @post_install_hooks ||= [] + @done_installing_hooks ||= [] @post_uninstall_hooks ||= [] @pre_uninstall_hooks ||= [] @pre_install_hooks ||= [] diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index 33ba1968d1..3c91392cdd 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -277,16 +277,16 @@ class Gem::Dependency def matching_specs(platform_only = false) env_req = Gem.env_requirement(name) - matches = Gem::Specification.stubs_for(name).find_all { |spec| + matches = Gem::Specification.stubs_for(name).find_all do |spec| requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version) - }.map(&:to_spec) + end.map(&:to_spec) Gem::BundlerVersionFinder.filter!(matches) if name == "bundler".freeze if platform_only - matches.reject! { |spec| + matches.reject! do |spec| spec.nil? || !Gem::Platform.match(spec.platform) - } + end end matches @@ -333,4 +333,5 @@ class Gem::Dependency matches.first end + end diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 346208603c..7f4f914591 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -29,7 +29,7 @@ class Gem::DependencyInstaller :wrappers => true, :build_args => nil, :build_docs_in_background => false, - :install_as_default => false + :install_as_default => false }.freeze ## @@ -336,15 +336,15 @@ class Gem::DependencyInstaller # REFACTOR maybe abstract away using Gem::Specification.include? so # that this isn't dependent only on the currently installed gems - dependency_list.specs.reject! { |spec| + dependency_list.specs.reject! do |spec| not keep_names.include?(spec.full_name) and Gem::Specification.include?(spec) - } + end unless dependency_list.ok? or @ignore_dependencies or @force - reason = dependency_list.why_not_ok?.map { |k,v| + reason = dependency_list.why_not_ok?.map do |k,v| "#{k} requires #{v.join(", ")}" - }.join("; ") + end.join("; ") raise Gem::DependencyError, "Unable to resolve dependencies: #{reason}" end diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb index ee2e4c7343..eec2223077 100644 --- a/lib/rubygems/dependency_list.rb +++ b/lib/rubygems/dependency_list.rb @@ -17,6 +17,7 @@ require 'rubygems/deprecate' # this class necessary anymore? Especially #ok?, #why_not_ok? class Gem::DependencyList + attr_reader :specs include Enumerable @@ -118,10 +119,10 @@ class Gem::DependencyList unsatisfied = Hash.new { |h,k| h[k] = [] } each do |spec| spec.runtime_dependencies.each do |dep| - inst = Gem::Specification.any? { |installed_spec| + inst = Gem::Specification.any? do |installed_spec| dep.name == installed_spec.name and dep.requirement.satisfied_by? installed_spec.version - } + end unless inst or @specs.find { |s| s.satisfies_requirement? dep } unsatisfied[spec.name] << dep @@ -145,10 +146,10 @@ class Gem::DependencyList # If the state is inconsistent, at least don't crash return true unless gem_to_remove - siblings = @specs.find_all { |s| + siblings = @specs.find_all do |s| s.name == gem_to_remove.name && s.full_name != gem_to_remove.full_name - } + end deps = [] @@ -160,11 +161,11 @@ class Gem::DependencyList end end - deps.all? { |dep| - siblings.any? { |s| + deps.all? do |dep| + siblings.any? do |s| s.satisfies_requirement? dep - } - } + end + end end ## @@ -173,10 +174,10 @@ class Gem::DependencyList # dependencies). def remove_specs_unsatisfied_by(dependencies) - specs.reject! { |spec| + specs.reject! do |spec| dep = dependencies[spec.name] dep and not dep.requirement.satisfied_by? spec.version - } + end end ## diff --git a/lib/rubygems/deprecate.rb b/lib/rubygems/deprecate.rb index 815f42ae8c..b5591e6ac1 100644 --- a/lib/rubygems/deprecate.rb +++ b/lib/rubygems/deprecate.rb @@ -48,7 +48,7 @@ module Gem::Deprecate # year/month that it is planned to go away. def deprecate(name, repl, year, month) - class_eval { + class_eval do old = "_deprecated_#{name}" alias_method old, name define_method name do |*args, &block| @@ -62,7 +62,7 @@ module Gem::Deprecate warn "#{msg.join}." unless Gem::Deprecate.skip send old, *args, &block end - } + end end module_function :deprecate, :skip_during diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb index 6773bbcd26..2cd18e2e20 100644 --- a/lib/rubygems/errors.rb +++ b/lib/rubygems/errors.rb @@ -13,11 +13,13 @@ module Gem # already activated gems or that RubyGems is otherwise unable to activate. class LoadError < ::LoadError + # Name of gem attr_accessor :name # Version requirement of gem attr_accessor :requirement + end ## @@ -25,6 +27,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) @name = name @requirement = requirement @@ -41,6 +44,7 @@ module Gem total = Gem::Specification.stubs.size "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n" end + end ## @@ -48,6 +52,7 @@ module Gem # not the requested version. Instead of rescuing from this class, make sure to # rescue from the superclass Gem::LoadError to catch all types of load errors. class MissingSpecVersionError < MissingSpecError + attr_reader :specs def initialize(name, requirement, specs) @@ -64,6 +69,7 @@ module Gem names = specs.map(&:full_name) "Could not find '#{name}' (#{requirement}) - did find: [#{names.join ','}]\n" end + end # Raised when there are conflicting gem specs loaded @@ -86,14 +92,15 @@ module Gem @conflicts = conflicts @name = target.name - reason = conflicts.map { |act, dependencies| + reason = conflicts.map do |act, dependencies| "#{act.full_name} conflicts with #{dependencies.join(", ")}" - }.join ", " + end.join ", " # TODO: improve message by saying who activated `con` super("Unable to activate #{target.full_name}, because #{reason}") end + end class ErrorReason; end @@ -143,6 +150,7 @@ module Gem @platforms.size == 1 ? '' : 's', @platforms.join(' ,')] end + end ## @@ -181,5 +189,6 @@ module Gem # The "exception" alias allows you to call raise on a SourceFetchProblem. alias exception error + end end diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index a387cd390f..28ae3aa24e 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -19,6 +19,7 @@ class Gem::Exception < RuntimeError extend Gem::Deprecate deprecate :source_exception, :none, 2018, 12 + end class Gem::CommandLineError < Gem::Exception; end @@ -53,14 +54,18 @@ end # Raised when attempting to uninstall a gem that isn't in GEM_HOME. class Gem::GemNotInHomeException < Gem::Exception + attr_accessor :spec + end ### # Raised when removing a gem with the uninstall command fails class Gem::UninstallError < Gem::Exception + attr_accessor :spec + end class Gem::DocumentError < Gem::Exception; end @@ -88,7 +93,9 @@ end ## # Used to raise parsing and loading errors class Gem::FormatException < Gem::Exception + attr_accessor :file_path + end class Gem::GemNotFoundException < Gem::Exception; end @@ -166,10 +173,12 @@ end class Gem::InstallError < Gem::Exception; end class Gem::RuntimeRequirementNotMetError < Gem::InstallError + attr_accessor :suggestion def message [suggestion, super].compact.join("\n\t") end + end ## diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index f578e7feee..8276dd769a 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -240,7 +240,9 @@ EOF FileUtils.mkdir_p @spec.extension_dir - File.open destination, 'wb' do |io| io.puts output end + File.open destination, 'wb' do |io| + io.puts output + end destination end diff --git a/lib/rubygems/ext/cmake_builder.rb b/lib/rubygems/ext/cmake_builder.rb index ab226733d9..829b88d1bb 100644 --- a/lib/rubygems/ext/cmake_builder.rb +++ b/lib/rubygems/ext/cmake_builder.rb @@ -2,6 +2,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') cmd = "cmake . -DCMAKE_INSTALL_PREFIX=#{dest_path}" @@ -14,4 +15,5 @@ class Gem::Ext::CmakeBuilder < Gem::Ext::Builder results end + end diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index 5a2b3eb533..169da438ba 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -10,6 +10,7 @@ require 'tempfile' require 'shellwords' class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder + FileEntry = FileUtils::Entry_ # :nodoc: def self.build(extension, dest_path, results, args=[], lib_dir=nil) @@ -88,7 +89,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder private def self.get_relative_path(path) - path[0..Dir.pwd.length-1] = '.' if path.start_with?(Dir.pwd) + path[0..Dir.pwd.length - 1] = '.' if path.start_with?(Dir.pwd) path end diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index c6ccc209c8..877205b619 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -63,7 +63,7 @@ module Gem::GemcutterUtilities env_rubygems_host = nil if env_rubygems_host and env_rubygems_host.empty? - env_rubygems_host|| configured_host + env_rubygems_host || configured_host end end @@ -116,7 +116,7 @@ module Gem::GemcutterUtilities say "Don't have an account yet? " + "Create one at #{sign_in_host}/sign_up" - email = ask " Email: " + email = ask " Email: " password = ask_for_password "Password: " say "\n" diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb index b97347177d..4d199868fb 100644 --- a/lib/rubygems/indexer.rb +++ b/lib/rubygems/indexer.rb @@ -131,7 +131,10 @@ class Gem::Indexer marshal_name = File.join @quick_marshal_dir, spec_file_name marshal_zipped = Gem.deflate Marshal.dump(spec) - File.open marshal_name, 'wb' do |io| io.write marshal_zipped end + + File.open marshal_name, 'wb' do |io| + io.write marshal_zipped + end files << marshal_name @@ -180,9 +183,9 @@ class Gem::Indexer # Builds indices for RubyGems 1.2 and newer. Handles full, latest, prerelease def build_modern_indices(specs) - prerelease, released = specs.partition { |s| + prerelease, released = specs.partition do |s| s.version.prerelease? - } + end latest_specs = Gem::Specification._latest_specs specs @@ -200,7 +203,7 @@ class Gem::Indexer end def map_gems_to_specs(gems) - gems.map { |gemfile| + gems.map do |gemfile| if File.size(gemfile) == 0 alert_warning "Skipping zero-length gem: #{gemfile}" next @@ -223,7 +226,7 @@ class Gem::Indexer "\t#{e.backtrace.join "\n\t"}"].join("\n") alert_error msg end - }.compact + end.compact end ## @@ -439,4 +442,5 @@ class Gem::Indexer Marshal.dump specs_index, io end end + end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 6cd073e11d..b64ba17be6 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -108,6 +108,7 @@ class Gem::Installer end class FakePackage + attr_accessor :spec attr_accessor :dir_mode @@ -125,12 +126,15 @@ class Gem::Installer file = File.join destination_dir, file next if File.exist? file FileUtils.mkdir_p File.dirname(file) - File.open file, 'w' do |fp| fp.puts "# #{file}" end + File.open file, 'w' do |fp| + fp.puts "# #{file}" + end end end def copy_to(path) end + end ## @@ -467,7 +471,7 @@ class Gem::Installer def generate_windows_script(filename, bindir) if Gem.win_platform? - script_name = filename + ".bat" + script_name = formatted_program_filename(filename) + ".bat" script_path = File.join bindir, File.basename(script_name) File.open script_path, 'w' do |file| file.puts windows_stub_script(bindir, filename) diff --git a/lib/rubygems/installer_test_case.rb b/lib/rubygems/installer_test_case.rb index d6d16a9194..6fdc2d6337 100644 --- a/lib/rubygems/installer_test_case.rb +++ b/lib/rubygems/installer_test_case.rb @@ -58,6 +58,7 @@ class Gem::Installer # Available through requiring rubygems/installer_test_case attr_writer :wrappers + end ## @@ -150,10 +151,15 @@ class Gem::InstallerTestCase < Gem::TestCase FileUtils.mkdir_p 'bin' FileUtils.mkdir_p 'lib' FileUtils.mkdir_p File.join('ext', 'a') + File.open File.join('bin', 'executable'), 'w' do |f| f.puts "raise 'ran executable'" end - File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end + + File.open File.join('lib', 'code.rb'), 'w' do |f| + f.puts '1' + end + File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f| f << <<-EOF File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end diff --git a/lib/rubygems/local_remote_options.rb b/lib/rubygems/local_remote_options.rb index 9fa256b08a..c940f50ad6 100644 --- a/lib/rubygems/local_remote_options.rb +++ b/lib/rubygems/local_remote_options.rb @@ -26,7 +26,7 @@ module Gem::LocalRemoteOptions valid_uri_schemes = ["http", "https", "file", "s3"] unless valid_uri_schemes.include?(uri.scheme) - msg = "Invalid uri scheme for #{value}\nPreface URLs with one of #{valid_uri_schemes.map{|s| "#{s}://"}}" + msg = "Invalid uri scheme for #{value}\nPreface URLs with one of #{valid_uri_schemes.map{|s| "#{s}://"}}" raise ArgumentError, msg end diff --git a/lib/rubygems/mock_gem_ui.rb b/lib/rubygems/mock_gem_ui.rb index 92ec85625c..e6105d9d49 100644 --- a/lib/rubygems/mock_gem_ui.rb +++ b/lib/rubygems/mock_gem_ui.rb @@ -7,6 +7,7 @@ require 'rubygems/user_interaction' # retrieval during tests. class Gem::MockGemUi < Gem::StreamUI + ## # Raised when you haven't provided enough input to your MockGemUi @@ -19,12 +20,14 @@ class Gem::MockGemUi < Gem::StreamUI end class TermError < RuntimeError + attr_reader :exit_code def initialize(exit_code) super @exit_code = exit_code end + end class SystemExitException < RuntimeError; end diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb index e948fb3d86..7cb38233eb 100644 --- a/lib/rubygems/name_tuple.rb +++ b/lib/rubygems/name_tuple.rb @@ -7,6 +7,7 @@ require 'rubygems/platform' class Gem::NameTuple + def initialize(name, version, platform="ruby") @name = name @version = version diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 8695b85fec..278ada8514 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -53,6 +53,7 @@ class Gem::Package class Error < Gem::Exception; end class FormatError < Error + attr_reader :path def initialize(message, source = nil) @@ -68,10 +69,12 @@ class Gem::Package end class PathError < Error + def initialize(destination, destination_dir) super "installing into parent path %s of %s is not allowed" % [destination, destination_dir] end + end class NonSeekableIO < Error; end diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index ed680d6553..2187766c41 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -5,6 +5,7 @@ # to the rest of RubyGems. # class Gem::PathSupport + ## # The default system path for managing Gems. attr_reader :home @@ -87,4 +88,5 @@ class Gem::PathSupport path end end + end diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index f8fe4dad54..603d8ae8b8 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -202,4 +202,5 @@ class Gem::Platform # This will be replaced with Gem::Platform::local. CURRENT = 'current'.freeze + end diff --git a/lib/rubygems/psych_tree.rb b/lib/rubygems/psych_tree.rb index 6f399a289e..b4eebf1dcc 100644 --- a/lib/rubygems/psych_tree.rb +++ b/lib/rubygems/psych_tree.rb @@ -2,6 +2,7 @@ module Gem if defined? ::Psych::Visitors class NoAliasYAMLTree < Psych::Visitors::YAMLTree + def self.create new({}) end unless respond_to? :create @@ -27,6 +28,7 @@ module Gem end private :format_time + end end end diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 69879df67c..32c65eada8 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -402,4 +402,5 @@ class Gem::RemoteFetcher [id, secret] end + end diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb index d442f6534b..1ed2b8ad50 100644 --- a/lib/rubygems/request.rb +++ b/lib/rubygems/request.rb @@ -13,7 +13,7 @@ class Gem::Request 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 + pool = ConnectionPools.new proxy_uri(proxy), cert_files new(uri, request_class, last_modified, pool.pool_for(uri)) end @@ -168,9 +168,10 @@ class Gem::Request no_env_proxy = env_proxy.nil? || env_proxy.empty? - return :no_proxy if scheme == 'https' && no_env_proxy - return get_proxy_from_env 'http' if no_env_proxy and _scheme != 'http' - return :no_proxy if no_env_proxy + if no_env_proxy + return (_scheme == 'https' || _scheme == 'http') ? + :no_proxy : get_proxy_from_env('http') + end uri = URI(Gem::UriFormatter.new(env_proxy).normalize) diff --git a/lib/rubygems/request/connection_pools.rb b/lib/rubygems/request/connection_pools.rb index c02f083b63..7c273d5465 100644 --- a/lib/rubygems/request/connection_pools.rb +++ b/lib/rubygems/request/connection_pools.rb @@ -5,7 +5,9 @@ class Gem::Request::ConnectionPools # :nodoc: @client = Net::HTTP class << self + attr_accessor :client + end def initialize(proxy_uri, cert_files) @@ -40,7 +42,7 @@ class Gem::Request::ConnectionPools # :nodoc: def get_no_proxy_from_env env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY'] - return [] if env_no_proxy.nil? or env_no_proxy.empty? + return [] if env_no_proxy.nil? or env_no_proxy.empty? env_no_proxy.split(/\s*,\s*/) end diff --git a/lib/rubygems/request/http_pool.rb b/lib/rubygems/request/http_pool.rb index a85fc2bdf6..058094a209 100644 --- a/lib/rubygems/request/http_pool.rb +++ b/lib/rubygems/request/http_pool.rb @@ -6,6 +6,7 @@ # use it. class Gem::Request::HTTPPool # :nodoc: + attr_reader :cert_files, :proxy_uri def initialize(http_args, cert_files, proxy_uri) diff --git a/lib/rubygems/request/https_pool.rb b/lib/rubygems/request/https_pool.rb index 50f42d9e0d..1236079b7d 100644 --- a/lib/rubygems/request/https_pool.rb +++ b/lib/rubygems/request/https_pool.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true class Gem::Request::HTTPSPool < Gem::Request::HTTPPool # :nodoc: + private 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 6017d15d13..4ac6ce0293 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -457,9 +457,9 @@ class Gem::RequestSet node.spec.dependencies.each do |dep| next if dep.type == :development and not @development - match = @requests.find { |r| + match = @requests.find do |r| dep.match? r.spec.name, r.spec.version, @prerelease - } + end unless match next if dep.type == :development and @development_shallow diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb index 3892e7aa5f..a4d803f915 100644 --- a/lib/rubygems/request_set/gem_dependency_api.rb +++ b/lib/rubygems/request_set/gem_dependency_api.rb @@ -43,11 +43,12 @@ class Gem::RequestSet::GemDependencyAPI :mri_20 => %w[ruby], :mri_21 => %w[ruby], :rbx => %w[rbx], - :ruby => %w[ruby rbx maglev], - :ruby_18 => %w[ruby rbx maglev], - :ruby_19 => %w[ruby rbx maglev], - :ruby_20 => %w[ruby rbx maglev], - :ruby_21 => %w[ruby rbx maglev], + :truffleruby => %w[truffleruby], + :ruby => %w[ruby rbx maglev truffleruby], + :ruby_18 => %w[ruby rbx maglev truffleruby], + :ruby_19 => %w[ruby rbx maglev truffleruby], + :ruby_20 => %w[ruby rbx maglev truffleruby], + :ruby_21 => %w[ruby rbx maglev truffleruby], }.freeze mswin = Gem::Platform.new 'x86-mswin32' @@ -85,6 +86,7 @@ class Gem::RequestSet::GemDependencyAPI :ruby_19 => Gem::Platform::RUBY, :ruby_20 => Gem::Platform::RUBY, :ruby_21 => Gem::Platform::RUBY, + :truffleruby => Gem::Platform::RUBY, :x64_mingw => x64_mingw, :x64_mingw_20 => x64_mingw, :x64_mingw_21 => x64_mingw @@ -126,6 +128,7 @@ class Gem::RequestSet::GemDependencyAPI :ruby_19 => tilde_gt_1_9_0, :ruby_20 => tilde_gt_2_0_0, :ruby_21 => tilde_gt_2_1_0, + :truffleruby => gt_eq_0, :x64_mingw => gt_eq_0, :x64_mingw_20 => tilde_gt_2_0_0, :x64_mingw_21 => tilde_gt_2_1_0, @@ -440,7 +443,7 @@ Gem dependencies file #{@path} requires #{name} more than once. Gem dependencies file #{@path} includes git reference for both ref and branch but only ref is used. WARNING end - if (ref||branch) && tag + if (ref || branch) && tag warn <<-WARNING Gem dependencies file #{@path} includes git reference for both ref/branch and tag but only ref/branch is used. WARNING @@ -480,7 +483,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta def gem_group(name, options) # :nodoc: g = options.delete :group - all_groups = g ? Array(g) : [] + all_groups = g ? Array(g) : [] groups = options.delete :groups all_groups |= groups if groups diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb index 1b374660f0..0776cf82e3 100644 --- a/lib/rubygems/request_set/lockfile.rb +++ b/lib/rubygems/request_set/lockfile.rb @@ -5,6 +5,7 @@ # constructed. class Gem::RequestSet::Lockfile + ## # Raised when a lockfile cannot be parsed @@ -35,6 +36,7 @@ class Gem::RequestSet::Lockfile @path = path super "#{message} (at line #{line} column #{column})" end + end ## @@ -79,7 +81,7 @@ class Gem::RequestSet::Lockfile @gem_deps_file.untaint unless gem_deps_file.tainted? - @platforms = [] + @platforms = [] end def add_DEPENDENCIES(out) # :nodoc: @@ -153,7 +155,7 @@ class Gem::RequestSet::Lockfile base = File.expand_path(base) if dest.index(base) == 0 - offset = dest[base.size+1..-1] + offset = dest[base.size + 1..-1] return '.' unless offset @@ -233,6 +235,7 @@ class Gem::RequestSet::Lockfile def requests @set.sorted_requests end + end require 'rubygems/request_set/lockfile/tokenizer' diff --git a/lib/rubygems/request_set/lockfile/parser.rb b/lib/rubygems/request_set/lockfile/parser.rb index 0fe0405e32..1e9d2b12de 100644 --- a/lib/rubygems/request_set/lockfile/parser.rb +++ b/lib/rubygems/request_set/lockfile/parser.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true class Gem::RequestSet::Lockfile::Parser + ### # Parses lockfiles @@ -327,9 +328,9 @@ class Gem::RequestSet::Lockfile::Parser def pinned_requirement(name) # :nodoc: requirement = Gem::Dependency.new name - specification = @set.sets.flat_map { |set| + specification = @set.sets.flat_map do |set| set.find_all(requirement) - }.compact.first + end.compact.first specification && specification.version end @@ -340,4 +341,5 @@ class Gem::RequestSet::Lockfile::Parser 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 bb69c85fb4..97396ec199 100644 --- a/lib/rubygems/request_set/lockfile/tokenizer.rb +++ b/lib/rubygems/request_set/lockfile/tokenizer.rb @@ -2,6 +2,7 @@ require 'rubygems/request_set/lockfile/parser' class Gem::RequestSet::Lockfile::Tokenizer + Token = Struct.new :type, :value, :column, :line EOF = Token.new :EOF @@ -109,4 +110,5 @@ class Gem::RequestSet::Lockfile::Tokenizer @tokens end + end diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb index 48f4b00d63..918404f2cd 100644 --- a/lib/rubygems/requirement.rb +++ b/lib/rubygems/requirement.rb @@ -2,10 +2,6 @@ require "rubygems/version" require "rubygems/deprecate" -# If we're being loaded after yaml was already required, then -# load our yaml + workarounds now. -Gem.load_yaml if defined? ::YAML - ## # A Requirement is a set of one or more version restrictions. It supports a # few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators. @@ -14,6 +10,7 @@ Gem.load_yaml if defined? ::YAML # together in RubyGems. class Gem::Requirement + OPS = { #:nodoc: "=" => lambda { |v, r| v == r }, "!=" => lambda { |v, r| v != r }, @@ -26,7 +23,7 @@ class Gem::Requirement SOURCE_SET_REQUIREMENT = Struct.new(:for_lockfile).new "!" # :nodoc: - quoted = OPS.keys.map { |k| Regexp.quote k }.join "|" + quoted = OPS.keys.map { |k| Regexp.quote k }.join "|" PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*".freeze # :nodoc: ## @@ -156,11 +153,11 @@ class Gem::Requirement def for_lockfile # :nodoc: return if [DefaultRequirement] == @requirements - list = requirements.sort_by { |_, version| + list = requirements.sort_by do |_, version| version - }.map { |op, version| + end.map do |op, version| "#{op} #{version}" - }.uniq + end.uniq " (#{list.join ', '})" end @@ -305,11 +302,14 @@ class Gem::Requirement l.first <=> r.first # then, sort by the operator (for stability) end end + end class Gem::Version + # This is needed for compatibility with older yaml # gemspecs. Requirement = Gem::Requirement # :nodoc: + end diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 8a72006ea8..d308f68f21 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -11,6 +11,7 @@ require 'rubygems/util/list' # all the requirements. class Gem::Resolver + require 'rubygems/resolver/molinillo' ## @@ -234,11 +235,11 @@ class Gem::Resolver groups = Hash.new { |hash, key| hash[key] = [] } # create groups & sources in the same loop - sources = possibles.map { |spec| + sources = possibles.map do |spec| source = spec.source groups[source] << spec source - }.uniq.reverse + end.uniq.reverse activation_requests = [] diff --git a/lib/rubygems/resolver/activation_request.rb b/lib/rubygems/resolver/activation_request.rb index b28e1bef32..78e8a46674 100644 --- a/lib/rubygems/resolver/activation_request.rb +++ b/lib/rubygems/resolver/activation_request.rb @@ -54,12 +54,12 @@ class Gem::Resolver::ActivationRequest if @spec.respond_to? :sources exception = nil - path = @spec.sources.find{ |source| + path = @spec.sources.find do |source| begin source.download full_spec, path rescue exception end - } + end return path if path raise exception if exception diff --git a/lib/rubygems/resolver/best_set.rb b/lib/rubygems/resolver/best_set.rb index cc91b65c0b..8a8c15d9a4 100644 --- a/lib/rubygems/resolver/best_set.rb +++ b/lib/rubygems/resolver/best_set.rb @@ -63,9 +63,9 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet uri = URI uri unless URI === uri uri.query = nil - raise error unless api_set = @sets.find { |set| + raise error unless api_set = @sets.find do |set| Gem::Resolver::APISet === set and set.dep_uri == uri - } + end index_set = Gem::Resolver::IndexSet.new api_set.source diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb index f3827ad4e9..ba14ee945d 100644 --- a/lib/rubygems/resolver/installer_set.rb +++ b/lib/rubygems/resolver/installer_set.rb @@ -55,9 +55,9 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set found = find_all request - found.delete_if { |s| + found.delete_if do |s| s.version.prerelease? and not s.local? - } unless dependency.prerelease? + end unless dependency.prerelease? found = found.select do |s| Gem::Source::SpecificFile === s.source or @@ -115,7 +115,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set def find_all(req) res = [] - dep = req.dependency + dep = req.dependency return res if @ignore_dependencies and @always_install.none? { |spec| dep.match? spec } diff --git a/lib/rubygems/resolver/lock_set.rb b/lib/rubygems/resolver/lock_set.rb index 4002a963a4..4134b4dcaf 100644 --- a/lib/rubygems/resolver/lock_set.rb +++ b/lib/rubygems/resolver/lock_set.rb @@ -16,7 +16,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set Gem::Source::Lock.new source end - @specs = [] + @specs = [] end ## diff --git a/lib/rubygems/resolver/lock_specification.rb b/lib/rubygems/resolver/lock_specification.rb index e29b567de4..5954507dba 100644 --- a/lib/rubygems/resolver/lock_specification.rb +++ b/lib/rubygems/resolver/lock_specification.rb @@ -71,9 +71,9 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification # A specification constructed from the lockfile is returned def spec - @spec ||= Gem::Specification.find { |spec| + @spec ||= Gem::Specification.find do |spec| spec.name == @name and spec.version == @version - } + end @spec ||= Gem::Specification.new do |s| s.name = @name diff --git a/lib/rubygems/resolver/requirement_list.rb b/lib/rubygems/resolver/requirement_list.rb index 98d086e63c..cf0014b0bb 100644 --- a/lib/rubygems/resolver/requirement_list.rb +++ b/lib/rubygems/resolver/requirement_list.rb @@ -79,4 +79,5 @@ class Gem::Resolver::RequirementList x = @exact[0,5] x + @list[0,5 - x.size] end + end diff --git a/lib/rubygems/resolver/specification.rb b/lib/rubygems/resolver/specification.rb index 7c1e9be702..e859d6659a 100644 --- a/lib/rubygems/resolver/specification.rb +++ b/lib/rubygems/resolver/specification.rb @@ -111,4 +111,5 @@ class Gem::Resolver::Specification def local? # :nodoc: false end + end diff --git a/lib/rubygems/resolver/stats.rb b/lib/rubygems/resolver/stats.rb index 64b458f504..5f41940b1e 100644 --- a/lib/rubygems/resolver/stats.rb +++ b/lib/rubygems/resolver/stats.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true class Gem::Resolver::Stats + def initialize @max_depth = 0 @max_requirements = 0 @@ -42,4 +43,5 @@ class Gem::Resolver::Stats $stdout.printf PATTERN, "Backtracking #", @backtracking $stdout.printf PATTERN, "Iteration #", @iterations end + end diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb index 34e86e921a..4e835e5b80 100644 --- a/lib/rubygems/security/signer.rb +++ b/lib/rubygems/security/signer.rb @@ -72,7 +72,7 @@ class Gem::Security::Signer @options = DEFAULT_OPTIONS.merge(options) unless @key - default_key = File.join Gem.default_key_path + default_key = File.join Gem.default_key_path @key = default_key if File.exist? default_key end diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb index 1453bf2323..97923ef698 100644 --- a/lib/rubygems/server.rb +++ b/lib/rubygems/server.rb @@ -607,13 +607,13 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } Gem::Specification.each do |spec| total_file_count += spec.files.size - deps = spec.dependencies.map { |dep| + deps = spec.dependencies.map do |dep| { "name" => dep.name, "type" => dep.type, "version" => dep.requirement.to_s, } - } + end deps = deps.sort_by { |dep| [dep["name"].downcase, dep["version"]] } deps.last["is_last"] = true unless deps.empty? @@ -754,9 +754,9 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } # documentation - just put it underneath the main doc folder. def show_rdoc_for_pattern(pattern, res) - found_gems = Dir.glob("{#{@gem_dirs.join ','}}/doc/#{pattern}").select {|path| + found_gems = Dir.glob("{#{@gem_dirs.join ','}}/doc/#{pattern}").select do |path| File.exist? File.join(path, 'rdoc/index.html') - } + end case found_gems.length when 0 return false @@ -875,4 +875,5 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } system("#{@launch} http://#{host}:#{@port}") end + end diff --git a/lib/rubygems/source_list.rb b/lib/rubygems/source_list.rb index 83b689f78e..0622bfa17b 100644 --- a/lib/rubygems/source_list.rb +++ b/lib/rubygems/source_list.rb @@ -147,4 +147,5 @@ class Gem::SourceList @sources.delete_if { |x| x.uri.to_s == source.to_s } end end + end diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index ca901cb8bf..4e62d7dd81 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -189,7 +189,7 @@ class Gem::SpecFetcher max = gem_name.size / 2 names = available_specs(type).first.values.flatten(1) - matches = names.map { |n| + matches = names.map do |n| next unless n.match_platform? distance = levenshtein_distance gem_name, n.name.downcase.tr('_-', '') @@ -199,7 +199,7 @@ class Gem::SpecFetcher return [n.name] if distance == 0 [n.name, distance] - }.compact + end.compact matches = if matches.empty? && type != :prerelease suggest_gems_from_name gem_name, :prerelease diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 0215f4aa66..6e1246c920 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -85,14 +85,14 @@ class Gem::Specification < Gem::BasicSpecification 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"', '"test_file=x" is a shortcut for "test_files=[x]"' ], - 2 => [ + 2 => [ 'Added "required_rubygems_version"', 'Now forward-compatible with future versions', ], - 3 => [ + 3 => [ 'Added Fixnum validation to the specification_version' ], - 4 => [ + 4 => [ 'Added sandboxed freeform metadata to the specification version.' ] }.freeze @@ -183,9 +183,9 @@ class Gem::Specification < Gem::BasicSpecification @@attributes = @@default_value.keys.sort_by { |s| s.to_s } @@array_attributes = @@default_value.reject { |k,v| v != [] }.keys - @@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition { |k| + @@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition do |k| @@default_value[k].nil? - } + end @@stubs_by_name = {} @@ -792,11 +792,11 @@ class Gem::Specification < Gem::BasicSpecification private_class_method :installed_stubs def self.map_stubs(dirs, pattern) # :nodoc: - dirs.flat_map { |dir| + dirs.flat_map do |dir| base_dir = File.dirname dir gems_dir = File.join base_dir, "gems" gemspec_stubs_in(dir, pattern) { |path| yield path, base_dir, gems_dir } - } + end end private_class_method :map_stubs @@ -854,11 +854,11 @@ class Gem::Specification < Gem::BasicSpecification end def self._resort!(specs) # :nodoc: - specs.sort! { |a, b| + specs.sort! do |a, b| names = a.name <=> b.name next names if names.nonzero? b.version <=> a.version - } + end end ## @@ -974,9 +974,9 @@ class Gem::Specification < Gem::BasicSpecification # Return the directories that Specification uses to find specs. def self.dirs - @@dirs ||= Gem.path.collect { |dir| + @@dirs ||= Gem.path.collect do |dir| File.join dir.dup.untaint, "specifications" - } + end end ## @@ -1038,10 +1038,10 @@ class Gem::Specification < Gem::BasicSpecification def self.find_by_path(path) path = path.dup.freeze - spec = @@spec_with_requirable_file[path] ||= (stubs.find { |s| + spec = @@spec_with_requirable_file[path] ||= (stubs.find do |s| next unless Gem::BundlerVersionFinder.compatible?(s) s.contains_requirable_file? path - } || NOT_FOUND) + end || NOT_FOUND) spec.to_spec end @@ -1050,18 +1050,18 @@ class Gem::Specification < Gem::BasicSpecification # amongst the specs that are not activated. def self.find_inactive_by_path(path) - stub = stubs.find { |s| + stub = stubs.find do |s| next if s.activated? next unless Gem::BundlerVersionFinder.compatible?(s) s.contains_requirable_file? path - } + end stub && stub.to_spec end def self.find_active_stub_by_path(path) - stub = @@active_stub_with_requirable_file[path] ||= (stubs.find { |s| + stub = @@active_stub_with_requirable_file[path] ||= (stubs.find do |s| s.activated? and s.contains_requirable_file? path - } || NOT_FOUND) + end || NOT_FOUND) stub.this end @@ -1142,10 +1142,10 @@ class Gem::Specification < Gem::BasicSpecification result[spec.name][spec.platform] = spec end - result.map(&:last).map(&:values).flatten.reject { |spec| + result.map(&:last).map(&:values).flatten.reject do |spec| minimum = native[spec.name] minimum && spec.version < minimum - }.sort_by{ |tup| tup.name } + end.sort_by{ |tup| tup.name } end ## @@ -1311,6 +1311,8 @@ class Gem::Specification < Gem::BasicSpecification # Load custom marshal format, re-initializing defaults as needed def self._load(str) + Gem.load_yaml + array = Marshal.load str spec = Gem::Specification.new @@ -1678,12 +1680,12 @@ class Gem::Specification < Gem::BasicSpecification def conflicts conflicts = {} - self.runtime_dependencies.each { |dep| + self.runtime_dependencies.each do |dep| spec = Gem.loaded_specs[dep.name] if spec and not spec.satisfies_requirement? dep (conflicts[spec] ||= []) << dep end - } + end env_req = Gem.env_requirement(name) (conflicts[self] ||= []) << env_req unless env_req.satisfied_by? version conflicts @@ -1693,9 +1695,9 @@ class Gem::Specification < Gem::BasicSpecification # return true if there will be conflict when spec if loaded together with the list of specs. def conficts_when_loaded_with?(list_of_specs) # :nodoc: - result = list_of_specs.any? { |spec| + result = list_of_specs.any? do |spec| spec.dependencies.any? { |dep| dep.runtime? && (dep.name == name) && !satisfies_requirement?(dep) } - } + end result end @@ -1704,14 +1706,14 @@ class Gem::Specification < Gem::BasicSpecification def has_conflicts? return true unless Gem.env_requirement(name).satisfied_by?(version) - self.dependencies.any? { |dep| + self.dependencies.any? do |dep| if dep.runtime? spec = Gem.loaded_specs[dep.name] spec and not spec.satisfies_requirement? dep else false end - } + end end # The date this gem was created. @@ -2591,6 +2593,8 @@ class Gem::Specification < Gem::BasicSpecification end def to_yaml(opts = {}) # :nodoc: + Gem.load_yaml + # Because the user can switch the YAML engine behind our # back, we have to check again here to make sure that our # psych code was properly loaded, and load it if not. diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index 4b79c1ac61..a4c6888cd1 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -2,6 +2,7 @@ require 'delegate' require 'uri' class Gem::SpecificationPolicy < SimpleDelegator + VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/.freeze # :nodoc: SPECIAL_CHARACTERS = /\A[#{Regexp.escape('.-_')}]+/.freeze # :nodoc: @@ -300,7 +301,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: end def validate_licenses - licenses.each { |license| + licenses.each do |license| if license.length > 64 error "each license must be 64 characters or less" end @@ -314,7 +315,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li message += "Did you mean #{suggestions.map { |s| "'#{s}'"}.join(', ')}?\n" unless suggestions.nil? warning(message) end - } + end warning <<-warning if licenses.empty? licenses is empty, but is recommended. Use a license identifier from @@ -404,4 +405,5 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li def help_text # :nodoc: "See http://guides.rubygems.org/specification-reference/ for help" end + end diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index 022da9185d..e2f6e245e7 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -5,6 +5,7 @@ # information. class Gem::StubSpecification < Gem::BasicSpecification + # :nodoc: PREFIX = "# stub: ".freeze @@ -12,6 +13,7 @@ class Gem::StubSpecification < Gem::BasicSpecification OPEN_MODE = 'r:UTF-8:-'.freeze class StubLine # :nodoc: all + attr_reader :name, :version, :platform, :require_paths, :extensions, :full_name @@ -50,10 +52,11 @@ class Gem::StubSpecification < Gem::BasicSpecification end path_list = parts.last - @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0".freeze).map! { |x| + @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0".freeze).map! do |x| REQUIRE_PATHS[x] || x - } + end end + end def self.default_gemspec_stub(filename, base_dir, gems_dir) diff --git a/lib/rubygems/syck_hack.rb b/lib/rubygems/syck_hack.rb index 051483eac8..0d87c71df4 100644 --- a/lib/rubygems/syck_hack.rb +++ b/lib/rubygems/syck_hack.rb @@ -40,11 +40,13 @@ module YAML # :nodoc: # should. module Syck class DefaultKey + remove_method :to_s rescue nil def to_s '=' end + end end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 783e8956a1..5f2bbd7b86 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -1,12 +1,6 @@ # frozen_string_literal: true # TODO: $SAFE = 1 -begin - gem 'minitest', '~> 5.0' -rescue NoMethodError, Gem::LoadError - # for ruby tests -end - if defined? Gem::QuickLoader Gem::QuickLoader.load_full_rubygems_library else @@ -23,7 +17,7 @@ if File.exist?(bundler_gemspec) end begin - gem 'minitest' + gem 'minitest', '~> 5.0' rescue Gem::LoadError end @@ -115,6 +109,8 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni attr_accessor :uri # :nodoc: + TEST_PATH = ENV.fetch('RUBYGEMS_TEST_PATH', File.expand_path('../../../test/rubygems', __FILE__)) + def assert_activate(expected, *specs) specs.each do |spec| case spec @@ -191,19 +187,19 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni def assert_contains_make_command(target, output, msg = nil) if output.match(/\n/) - msg = message(msg) { + msg = message(msg) do 'Expected output containing make command "%s": %s' % [ ('%s %s' % [make_command, target]).rstrip, output.inspect ] - } + end else - msg = message(msg) { + msg = message(msg) do 'Expected make command "%s": %s' % [ ('%s %s' % [make_command, target]).rstrip, output.inspect ] - } + end end assert scan_make_command_lines(output).any? { |line| @@ -260,7 +256,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni @fetcher = nil if Gem::USE_BUNDLER_FOR_GEMDEPS - Bundler.ui = Bundler::UI::Silent.new + Bundler.ui = Bundler::UI::Silent.new end @back_ui = Gem::DefaultUserInteraction.ui @ui = Gem::MockGemUi.new @@ -316,7 +312,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem.ensure_gem_subdirectories @gemhome @orig_LOAD_PATH = $LOAD_PATH.dup - $LOAD_PATH.map! { |s| + $LOAD_PATH.map! do |s| expand_path = File.expand_path(s) if expand_path != s expand_path.untaint @@ -327,7 +323,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni s = expand_path end s - } + end Dir.chdir @tempdir @@ -599,11 +595,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni def uninstall_gem(spec) require 'rubygems/uninstaller' - Class.new(Gem::Uninstaller) { + Class.new(Gem::Uninstaller) do def ask_if_ok(spec) true end - }.new(spec.name, :executables => true, :user_install => true).uninstall + end.new(spec.name, :executables => true, :user_install => true).uninstall end ## @@ -612,7 +608,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni def create_tmpdir tmpdir = nil - Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp + + Dir.chdir Dir.tmpdir do + tmpdir = Dir.pwd + end # HACK OSX /private/tmp + tmpdir = File.join tmpdir, "test_rubygems_#{$$}" FileUtils.mkdir_p tmpdir return tmpdir @@ -723,7 +723,10 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni spec.files.each do |file| next if File.exist? file FileUtils.mkdir_p File.dirname(file) - File.open file, 'w' do |fp| fp.puts "# #{file}" end + + File.open file, 'w' do |fp| + fp.puts "# #{file}" + end end use_ui Gem::MockGemUi.new do @@ -751,6 +754,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem::Specification.reset end + def util_clear_default_gems + FileUtils.rm_rf @default_spec_dir + FileUtils.mkdir @default_spec_dir + end + ## # Install the provided specs @@ -1017,7 +1025,7 @@ Also, a list: s.add_dependency 'x', '>= 1' end - @pl1 = quick_gem 'pl', '1' do |s| # l for legacy + @pl1 = quick_gem 'pl', '1' do |s| # l for legacy s.files = %w[lib/code.rb] s.require_paths = %w[lib] s.platform = Gem::Platform.new 'i386-linux' @@ -1339,6 +1347,7 @@ Also, a list: end class << self + # :nodoc: ## # Return the join path, with escaping backticks, dollars, and @@ -1352,12 +1361,12 @@ Also, a list: "\"#{path.gsub(/[`$"]/, '\\&')}\"" end end + end @@ruby = rubybin - gempath = File.expand_path('../../../test/rubygems', __FILE__) - @@good_rake = "#{rubybin} #{escape_path(gempath, 'good_rake.rb')}" - @@bad_rake = "#{rubybin} #{escape_path(gempath, 'bad_rake.rb')}" + @@good_rake = "#{rubybin} #{escape_path(TEST_PATH, 'good_rake.rb')}" + @@bad_rake = "#{rubybin} #{escape_path(TEST_PATH, 'bad_rake.rb')}" ## # Construct a new Gem::Dependency. @@ -1526,6 +1535,7 @@ Also, a list: def prefetch(reqs) # :nodoc: end + end ## @@ -1545,14 +1555,12 @@ Also, a list: 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__ + cert_file = "#{TEST_PATH}/#{cert_name}_cert_32.pem" return cert_file if File.exist? cert_file end - File.expand_path "../../../test/rubygems/#{cert_name}_cert.pem", __FILE__ + "#{TEST_PATH}/#{cert_name}_cert.pem" end ## @@ -1570,13 +1578,13 @@ Also, a list: # Returns the path to the key named +key_name+ from <tt>test/rubygems</tt> def self.key_path(key_name) - File.expand_path "../../../test/rubygems/#{key_name}_key.pem", __FILE__ + "#{TEST_PATH}/#{key_name}_key.pem" end # :stopdoc: # only available in RubyGems tests - PRIVATE_KEY_PASSPHRASE = 'Foo bar'.freeze + PRIVATE_KEY_PASSPHRASE = 'Foo bar'.freeze begin PRIVATE_KEY = load_key 'private' diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb index d531239812..069ecccabe 100644 --- a/lib/rubygems/test_utilities.rb +++ b/lib/rubygems/test_utilities.rb @@ -366,4 +366,5 @@ class TempIO < Tempfile flush Gem.read_binary path end + end diff --git a/lib/rubygems/text.rb b/lib/rubygems/text.rb index 5d346b496b..f6817c06a2 100644 --- a/lib/rubygems/text.rb +++ b/lib/rubygems/text.rb @@ -65,12 +65,12 @@ module Gem::Text x = nil str1.each_char.each_with_index do |char1,i| - e = i+1 + e = i + 1 str2.each_char.each_with_index do |char2,j| cost = (char1 == char2) ? 0 : 1 x = min3( - d[j+1] + 1, # insertion + d[j + 1] + 1, # insertion e + 1, # deletion d[j] + cost # substitution ) diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index c213cf656e..fe423a7ebd 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -57,7 +57,7 @@ class Gem::Uninstaller # Indicate if development dependencies should be checked when # uninstalling. (default: false) # - @check_dev = options[:check_dev] + @check_dev = options[:check_dev] if options[:force] @force_all = true @@ -134,7 +134,7 @@ class Gem::Uninstaller elsif index >= 0 && index < list.size uninstall_gem list[index] else - say "Error: must enter a number [1-#{list.size+1}]" + say "Error: must enter a number [1-#{list.size + 1}]" end else uninstall_gem list.first @@ -180,9 +180,9 @@ class Gem::Uninstaller # Leave any executables created by other installed versions # of this gem installed. - list = Gem::Specification.find_all { |s| + list = Gem::Specification.find_all do |s| s.name == spec.name && s.version != spec.version - } + end list.each do |s| s.executables.each do |exe_name| @@ -354,4 +354,5 @@ class Gem::Uninstaller raise e end + end diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 03eac76ea8..ecd1454e2d 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -227,7 +227,7 @@ class Gem::StreamUI @outs.puts question list.each_with_index do |item, index| - @outs.puts " #{index+1}. #{item}" + @outs.puts " #{index + 1}. #{item}" end @outs.print "> " @@ -418,6 +418,7 @@ class Gem::StreamUI def done end + end ## @@ -506,6 +507,7 @@ class Gem::StreamUI def done @out.puts @terminal_message end + end ## @@ -549,6 +551,7 @@ class Gem::StreamUI def done end + end ## @@ -603,7 +606,9 @@ class Gem::StreamUI @out.puts message end end + end + end ## @@ -619,6 +624,7 @@ class Gem::ConsoleUI < Gem::StreamUI def initialize super STDIN, STDOUT, STDERR, true end + end ## @@ -651,4 +657,5 @@ class Gem::SilentUI < Gem::StreamUI def progress_reporter(*args) # :nodoc: SilentProgressReporter.new(@outs, *args) end + end diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb index b9e5dfc8c7..401e5609f7 100644 --- a/lib/rubygems/util.rb +++ b/lib/rubygems/util.rb @@ -28,7 +28,9 @@ module Gem::Util zipped = StringIO.new(String.new, 'w') zipped.set_encoding Encoding::BINARY - Zlib::GzipWriter.wrap zipped do |io| io.write data end + Zlib::GzipWriter.wrap zipped do |io| + io.write data + end zipped.string end diff --git a/lib/rubygems/util/licenses.rb b/lib/rubygems/util/licenses.rb index 2a536575c0..ac0d3bb44e 100644 --- a/lib/rubygems/util/licenses.rb +++ b/lib/rubygems/util/licenses.rb @@ -2,6 +2,7 @@ require 'rubygems/text' class Gem::Licenses + extend Gem::Text NONSTANDARD = 'Nonstandard'.freeze @@ -434,4 +435,5 @@ class Gem::Licenses return unless lowest < license.size by_distance[lowest] end + end diff --git a/lib/rubygems/util/list.rb b/lib/rubygems/util/list.rb index 33c40af4bb..7e4d6b5de6 100644 --- a/lib/rubygems/util/list.rb +++ b/lib/rubygems/util/list.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module Gem class List + include Enumerable attr_accessor :value, :tail @@ -33,5 +34,6 @@ module Gem return List.new(value) unless list List.new value, list end + end end diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb index f00021daa9..7ed0a1f80f 100644 --- a/lib/rubygems/validator.rb +++ b/lib/rubygems/validator.rb @@ -25,7 +25,7 @@ class Gem::Validator installed_files = [] Find.find gem_directory do |file_name| - fn = file_name[gem_directory.size..file_name.size-1].sub(/^\//, "") + fn = file_name[gem_directory.size..file_name.size - 1].sub(/^\//, "") installed_files << fn unless fn =~ /CVS/ || fn.empty? || File.directory?(file_name) end @@ -91,17 +91,17 @@ class Gem::Validator File.open gem_path, Gem.binary_mode do |file| package = Gem::Package.new gem_path - good, gone = package.contents.partition { |file_name| + good, gone = package.contents.partition do |file_name| File.exist? File.join(gem_directory, file_name) - } + end gone.sort.each do |path| errors[gem_name][path] = "Missing file" end - good, unreadable = good.partition { |file_name| + good, unreadable = good.partition do |file_name| File.readable? File.join(gem_directory, file_name) - } + end unreadable.sort.each do |path| errors[gem_name][path] = "Unreadable file" @@ -141,4 +141,5 @@ class Gem::Validator errors end + end diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index f2f10569e8..c23b157708 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -150,6 +150,7 @@ # a zero to give a sensible result. class Gem::Version + autoload :Requirement, 'rubygems/requirement' include Comparable @@ -395,4 +396,5 @@ class Gem::Version numeric_segments = string_segments.slice!(0, string_start || string_segments.size) return numeric_segments, string_segments end + end |