diff options
author | David RodrÃguez <[email protected]> | 2020-06-10 19:46:05 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2020-06-15 21:20:37 +0900 |
commit | 955f1837a180d8936f90ab6cf039ccb8f751be72 () | |
tree | 0d48749501febfccefda3b1376511c421d4118e4 /lib/rubygems | |
parent | ef481c120c55bf0351a586739f9b5d704f3f7a7d (diff) |
Use space inside block braces everywhere
To make rubygems code style consistent with bundler.
Notes: Merged: https://.com/ruby/ruby/pull/3229
64 files changed, 223 insertions, 223 deletions
@@ -70,11 +70,11 @@ class Gem::AvailableSet end def all_specs - @set.map { |t| t.spec } end def match_platform! - @set.reject! { |t| !Gem::Platform.match(t.spec.platform) } @sorted = nil self end @@ -91,7 +91,7 @@ class Gem::AvailableSet end def source_for(spec) - f = @set.find { |t| t.spec == spec } f.source end @@ -160,7 +160,7 @@ class Gem::AvailableSet end def inject_into_list(dep_list) - @set.each { |t| dep_list.add t.spec } end end @@ -276,7 +276,7 @@ class Gem::BasicSpecification def matches_for_glob(glob) # TODO: rename? glob = File.join(self.lib_dirs_glob, glob) - Dir[glob].map { |f| f.tap(&Gem::UNTAINT) } # FIX our tests are broken, run w/ SAFE=1 end ## @@ -335,12 +335,12 @@ class Gem::BasicSpecification def have_file?(file, suffixes) return true if raw_require_paths.any? do |path| base = File.join(gems_dir, full_name, path.tap(&Gem::UNTAINT), file).tap(&Gem::UNTAINT) - suffixes.any? { |suf| File.file? base + suf } end if have_extensions? base = File.join extension_dir, file - suffixes.any? { |suf| File.file? base + suf } else false end @@ -44,9 +44,9 @@ To install the missing version, run `gem install bundler:#{vr.first}` def self.filter!(specs) return unless bundler_version = self.bundler_version - specs.reject! { |spec| spec.version.segments.first != bundler_version.segments.first } - exact_match_index = specs.find_index { |spec| spec.version == bundler_version } return unless exact_match_index specs.unshift(specs.delete_at(exact_match_index)) @@ -86,7 +86,7 @@ To install the missing version, run `gem install bundler:#{vr.first}` unless gemfile begin Gem::Util.traverse_parents(Dir.pwd) do |directory| - next unless gemfile = Gem::GEM_DEP_FILES.find { |f| File.file?(f.tap(&Gem::UNTAINT)) } gemfile = File.join directory, gemfile break @@ -125,7 +125,7 @@ class Gem::Command @program_name = "gem #{command}" @defaults = defaults @options = defaults.dup - @option_groups = Hash.new { |h,k| h[k] = [] } @deprecated_options = { command => {} } @parser = nil @when_invoked = nil @@ -162,7 +162,7 @@ class Gem::Command if errors and !errors.empty? msg << ", here is why:\n" - errors.each { |x| msg << " #{x.wordy}\n" } else if required_by and gem != required_by msg << " (required by #{required_by}) in any repository" @@ -192,7 +192,7 @@ class Gem::Command "Please specify at least one gem name (e.g. gem build GEMNAME)" end - args.select { |arg| arg !~ /^-/ } end ## @@ -364,7 +364,7 @@ class Gem::Command def remove_option(name) @option_groups.each do |_, option_list| - option_list.reject! { |args, _| args.any? { |x| x.is_a?(String) && x =~ /^#{name}/ } } end end @@ -417,7 +417,7 @@ class Gem::Command def merge_options(new_options) @options = @defaults.clone - new_options.each { |k,v| @options[k] = v } end ## @@ -496,7 +496,7 @@ class Gem::Command configure_options "", regular_options - @option_groups.sort_by { |n,_| n.to_s }.each do |group_name, option_list| @parser.separator nil configure_options group_name, option_list end @@ -138,7 +138,7 @@ class Gem::CommandManager # Return a sorted list of all command names as strings. def command_names - @commands.keys.collect {|key| key.to_s}.sort end ## @@ -203,9 +203,9 @@ class Gem::CommandManager def find_command_possibilities(cmd_name) len = cmd_name.length - found = command_names.select { |name| cmd_name == name[0, len] } - exact = found.find { |name| name == cmd_name } exact ? [exact] : found end @@ -186,7 +186,7 @@ class Gem::Commands::CertCommand < Gem::Command subject = certificate.subject.to_s subject.downcase.index filter end.sort_by do |certificate, _| - certificate.subject.to_a.map { |name, data,| [name, data] } end.each do |certificate, path| yield certificate, path end @@ -69,7 +69,7 @@ If no gems are named all gems in GEM_HOME are cleaned. until done do clean_gems - this_set = @gems_to_cleanup.map { |spec| spec.full_name }.sort done = this_set.empty? || last_set == this_set @@ -82,7 +82,7 @@ If no gems are named all gems in GEM_HOME are cleaned. say "Clean up complete" verbose do - skipped = @default_gems.map { |spec| spec.full_name } "Skipped default gems: #{skipped.join ', '}" end @@ -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 { |spec| deplist.add spec } deps = deplist.strongly_connected_components.flatten @@ -175,7 +175,7 @@ prefix or only the files that are requireable. if Gem.configuration.verbose say "\nDirectories searched:" - @spec_dirs.sort.each { |dir| say dir } end return nil @@ -59,14 +59,14 @@ use with other commands. ss, = fetcher.spec_for_dependency dependency - ss.map { |spec, _| spec } end def fetch_specs(name_pattern, dependency) # :nodoc: specs = [] if local? - specs.concat Gem::Specification.stubs.find_all { |spec| name_pattern =~ spec.name and dependency.requirement.satisfied_by? spec.version }.map(&:to_spec) @@ -92,7 +92,7 @@ use with other commands. def display_pipe(specs) # :nodoc: specs.each do |spec| unless spec.dependencies.empty? - spec.dependencies.sort_by { |dep| dep.name }.each do |dep| say "#{dep.name} --version '#{dep.requirement}'" end end @@ -156,7 +156,7 @@ use with other commands. response = String.new response << ' ' * level + "Gem #{spec.full_name}\n" unless spec.dependencies.empty? - spec.dependencies.sort_by { |dep| dep.name }.each do |dep| response << ' ' * level + " #{dep}\n" end end @@ -168,11 +168,11 @@ use with other commands. ss, _ = fetcher.spec_for_dependency dependency - ss.map { |s,o| s } end def reverse_dependencies(specs) # :nodoc: - reverse = Hash.new { |h, k| h[k] = [] } return reverse unless options[:reverse_dependencies] @@ -57,11 +57,11 @@ then repackaging it. Gem::SpecFetcher.fetcher.spec_for_dependency dep 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? show_lookup_failure gem_name, version, errors, options[:domain] @@ -324,7 +324,7 @@ platform. margin_width = 4 - desc_width = @command_manager.command_names.map { |n| n.size }.max + 4 summary_width = 80 - margin_width - desc_width wrap_indent = ' ' * (margin_width + desc_width) @@ -104,7 +104,7 @@ lock it down to the exact version. File.join path, "specifications", "#{gem_full_name}.gemspec" end - gemspecs.find { |path| File.exist? path } end end @@ -217,7 +217,7 @@ By default, this RubyGems will install gem as: say say "RubyGems installed the following executables:" - say bin_file_names.map { |name| "\t#{name}\n" } say unless bin_file_names.grep(/#{File::SEPARATOR}gem$/) @@ -548,7 +548,7 @@ By default, this RubyGems will install gem as: def bundler_template_files Dir.chdir "bundler/lib" do Dir.glob(File.join('bundler', 'templates', '**', '*'), File::FNM_DOTMATCH). - select{|f| !File.directory?(f)} end end @@ -556,7 +556,7 @@ By default, this RubyGems will install gem as: def template_files_in(dir) Dir.chdir dir do Dir.glob(File.join('templates', '**', '*'), File::FNM_DOTMATCH). - select{|f| !File.directory?(f)} end end @@ -119,7 +119,7 @@ Specific fields in the specification can be extracted in YAML format: dep.prerelease = options[:prerelease] found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep - specs.push(*found.map { |spec,| spec }) end if specs.empty? @@ -128,7 +128,7 @@ Specific fields in the specification can be extracted in YAML format: end unless options[:all] - specs = [specs.max_by { |s| s.version }] end specs.each do |s| @@ -33,7 +33,7 @@ longer using. end end - gem_to_atime.sort_by { |_, atime| atime }.each do |name, atime| say "#{name} at #{atime.strftime '%c'}" end end @@ -136,7 +136,7 @@ that is a dependency of an existing gem. You can use the end def uninstall_all - specs = Gem::Specification.reject { |spec| spec.default_gem? } specs.each do |spec| options[:version] = spec.version @@ -157,7 +157,7 @@ command help for an example. specs = dependency.matching_specs - selected = specs.max_by { |s| s.version } return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless selected @@ -107,7 +107,7 @@ command to remove old versions. updated = update_gems gems_to_update - updated_names = updated.map { |spec| spec.name } not_updated_names = options[:args].uniq - updated_names if updated.empty? @@ -126,7 +126,7 @@ command to remove old versions. spec_tuples, errors = fetcher.search_for_dependency dependency - error = errors.find { |e| e.respond_to? :exception } raise error if error @@ -231,7 +231,7 @@ command to remove old versions. end def update_gem(name, version = Gem::Requirement.default) - return if @updated.any? { |spec| spec.name == name } update_options = options.dup update_options[:prerelease] = version.prerelease? @@ -292,7 +292,7 @@ command to remove old versions. highest_installed_gems.each do |l_name, l_spec| next if not gem_names.empty? and - gem_names.none? { |name| name == l_spec.name } highest_remote_tup = highest_remote_name_tuple l_spec highest_remote_ver = highest_remote_tup.version @@ -434,7 +434,7 @@ if you believe they were disclosed to a third party. yaml_hash[:ssl_client_cert] = @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert - keys = yaml_hash.keys.map { |key| key.to_s } keys << 'debug' re = Regexp.union(*keys) @@ -130,7 +130,7 @@ module Kernel # Ok, now find a gem that has no conflicts, starting # at the highest version. - valid = found_specs.find { |s| !s.has_conflicts? } unless valid le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate" @@ -322,13 +322,13 @@ class Gem::Dependency def to_spec matches = self.to_specs.compact - active = matches.find { |spec| spec.activated? } return active if active return matches.first if prerelease? # Move prereleases to the end of the list for >= 0 requirements - pre, matches = matches.partition { |spec| spec.version.prerelease? } matches += pre if requirement == Gem::Requirement.default matches.first @@ -101,11 +101,11 @@ class Gem::DependencyList end def find_name(full_name) - @specs.find { |spec| spec.full_name == full_name } end def inspect # :nodoc: - "%s %p>" % [super[0..-2], map { |s| s.full_name }] end ## @@ -116,7 +116,7 @@ class Gem::DependencyList end def why_not_ok?(quick = false) - unsatisfied = Hash.new { |h,k| h[k] = [] } each do |spec| spec.runtime_dependencies.each do |dep| inst = Gem::Specification.any? do |installed_spec| @@ -124,7 +124,7 @@ class Gem::DependencyList dep.requirement.satisfied_by? installed_spec.version end - unless inst or @specs.find { |s| s.satisfies_requirement? dep } unsatisfied[spec.name] << dep return unsatisfied if quick end @@ -184,7 +184,7 @@ class Gem::DependencyList # Removes the gemspec matching +full_name+ from the dependency list def remove_by_name(full_name) - @specs.delete_if { |spec| spec.full_name == full_name } end ## @@ -192,7 +192,7 @@ class Gem::DependencyList # gemspecs that have a dependency satisfied by the named gemspec. def spec_predecessors - result = Hash.new { |h,k| h[k] = [] } specs = @specs.sort.reverse @@ -238,7 +238,7 @@ class Gem::DependencyList # +ignored+. def active_count(specs, ignored) - specs.count { |spec| ignored[spec.full_name].nil? } end end @@ -31,7 +31,7 @@ class Gem::Doctor missing = Gem::REPOSITORY_SUBDIRECTORIES.sort - - REPOSITORY_EXTENSION_MAP.map { |(k,_)| k }.sort raise "Update REPOSITORY_EXTENSION_MAP, missing: #{missing.join ', '}" unless missing.empty? @@ -53,7 +53,7 @@ class Gem::Doctor # Specs installed in this gem repository def installed_specs # :nodoc: - @installed_specs ||= Gem::Specification.map { |s| s.full_name } end ## @@ -245,7 +245,7 @@ class Gem::UnsatisfiableDependencyError < Gem::DependencyError 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(', ')}" else if dep.explicit? @@ -66,7 +66,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder 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 } FileUtils.cp_r entries, lib_dir, :remove_destination => true end @@ -365,7 +365,7 @@ class Gem::Indexer end specs = map_gems_to_specs updated_gems - prerelease, released = specs.partition { |s| s.version.prerelease? } files = build_marshal_gemspecs specs @@ -154,7 +154,7 @@ module Gem::InstallUpdateOptions 'Omit the named groups (comma separated)', 'when installing from a gem dependencies', 'file') do |v,o| - options[:without_groups].concat v.map { |without| without.intern } end add_option(:"Install/Update", '--default', @@ -410,7 +410,7 @@ class Gem::Installer def installation_satisfies_dependency?(dependency) return true if @options[:development] and dependency.type == :development - return true if installed_specs.detect { |s| dependency.matches_spec? s } return false if @only_install_dir not dependency.matching_specs.empty? end @@ -584,7 +584,7 @@ class Gem::Installer def shebang(bin_file_name) ruby_name = RbConfig::CONFIG['ruby_install_name'] if @env_shebang path = File.join gem_dir, spec.bindir, bin_file_name - first_line = File.open(path, "rb") {|file| file.gets} || "" if first_line.start_with?("#!") # Preserve extra words on shebang line, like "-w". Thanks RPA. @@ -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}://"}}" raise ArgumentError, msg end @@ -26,7 +26,7 @@ class Gem::NameTuple # NameTuple objects. def self.from_list(list) - list.map { |t| new(*t) } end ## @@ -34,7 +34,7 @@ class Gem::NameTuple # [name, version, platform] tuples. def self.to_basic(list) - list.map { |t| t.to_a } end ## @@ -198,7 +198,7 @@ class Gem::Package @build_time = Gem.source_date_epoch @checksums = {} @contents = nil - @digests = Hash.new { |h, algorithm| h[algorithm] = {} } @files = nil @security_policy = security_policy @signatures = {} @@ -219,7 +219,7 @@ class Gem::Package def add_checksums(tar) Gem.load_yaml - checksums_by_algorithm = Hash.new { |h, algorithm| h[algorithm] = {} } @checksums.each do |name, digests| digests.each do |algorithm, digest| @@ -582,10 +582,10 @@ EOM ) @spec.signing_key = nil - @spec.cert_chain = @signer.cert_chain.map { |cert| cert.to_s } else @signer = Gem::Security::Signer.new nil, nil, passphrase - @spec.cert_chain = @signer.cert_chain.map { |cert| cert.to_pem } if @signer.cert_chain end end @@ -42,7 +42,7 @@ class Gem::Package::Old < Gem::Package read_until_dashes io # spec header = file_list io - @contents = header.map { |file| file['path'] } end end @@ -210,7 +210,7 @@ class Gem::Package::TarHeader private def calculate_checksum(header) - header.unpack("C*").inject { |a, b| a + b } end def header(checksum = @checksum) @@ -68,7 +68,7 @@ class Gem::Package::TarTestCase < Gem::TestCase end def calc_checksum(header) - sum = header.unpack("C*").inject{|s,a| s + a} SP(Z(to_oct(sum, 6))) end @@ -68,7 +68,7 @@ class Gem::PathSupport gem_path = default_path end - gem_path.map { |path| expand(path) }.uniq end # Return the default Gem path @@ -75,7 +75,7 @@ is too hard to use. terminate_interaction(check_installed_gems(gem_names)) if check_installed_gems? - gem_names.each { |n| show_gems(n) } end private @@ -187,12 +187,12 @@ is too hard to use. # Check if gem +name+ version +version+ is installed. def installed?(name, req = Gem::Requirement.default) - Gem::Specification.any? { |s| s.name =~ name and req =~ s.version } end def output_query_results(spec_tuples) output = [] - versions = Hash.new { |h,name| h[name] = [] } spec_tuples.each do |spec_tuple, source| versions[spec_tuple.name] << [spec_tuple, source] @@ -209,9 +209,9 @@ is too hard to use. def output_versions(output, versions) versions.each do |gem_name, matching_tuples| - matching_tuples = matching_tuples.sort_by { |n,_| n.version }.reverse - platforms = Hash.new { |h,version| h[version] = [] } matching_tuples.each do |n, _| platforms[n.version] << n.platform if n.platform @@ -254,7 +254,7 @@ is too hard to use. list = if platforms.empty? or options[:details] - name_tuples.map { |n| n.version }.uniq else platforms.sort.reverse.map do |version, pls| out = version.to_s @@ -332,7 +332,7 @@ is too hard to use. def spec_platforms(entry, platforms) non_ruby = platforms.any? do |_, pls| - pls.any? { |pl| pl != Gem::Platform::RUBY } end return unless non_ruby @@ -343,7 +343,7 @@ is too hard to use. else entry << " Platforms:\n" - sorted_platforms = platforms.sort_by { |version,| version } sorted_platforms.each do |version, pls| label = " #{version}: " @@ -106,7 +106,7 @@ class Gem::RemoteFetcher return if found.empty? - spec, source = found.max_by { |(s,_)| s.version } download spec, source.uri end @@ -212,7 +212,7 @@ class Gem::RemoteFetcher 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) } end case response @@ -327,7 +327,7 @@ class Gem::RemoteFetcher end def close_all - @pools.each_value {|pool| pool.close_all} end private @@ -31,7 +31,7 @@ class Gem::Request::ConnectionPools # :nodoc: end def close_all - @pools.each_value {|pool| pool.close_all} end private @@ -184,7 +184,7 @@ class Gem::RequestSet if req.installed? req.spec.spec.build_extensions - if @always_install.none? { |spec| spec == req.spec.spec } yield req, nil if block_given? next end @@ -269,7 +269,7 @@ class Gem::RequestSet gem_home, ENV['GEM_HOME'] = ENV['GEM_HOME'], dir existing = force ? [] : specs_in(dir) - existing.delete_if { |s| @always_install.include? s } dir = File.expand_path 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 } yield request, nil if block_given? next end @@ -386,7 +386,7 @@ class Gem::RequestSet q.text 'sets:' q.breakable - q.pp @sets.map { |set| set.class } end end @@ -440,7 +440,7 @@ class Gem::RequestSet end def specs - @specs ||= @requests.map { |r| r.full_spec } end def specs_in(dir) @@ -206,7 +206,7 @@ class Gem::RequestSet::GemDependencyAPI @git_set = @set.git_set @git_sources = {} @installing = false - @requires = Hash.new { |h, name| h[name] = [] } @vendor_set = @set.vendor_set @source_set = @set.source_set @gem_sources = {} @@ -89,7 +89,7 @@ class Gem::RequestSet::Lockfile def add_DEPENDENCIES(out) # :nodoc: out << "DEPENDENCIES" - out.concat @dependencies.sort_by { |name,| name }.map { |name, requirement| " #{name}#{requirement.for_lockfile}" } @@ -103,12 +103,12 @@ class Gem::RequestSet::Lockfile request.spec.source.uri end - source_groups.sort_by { |group,| group.to_s }.map do |group, requests| out << "GEM" out << " remote: #{group}" out << " specs:" - requests.sort_by { |request| request.name }.each do |request| next if request.spec.name == 'bundler' platform = "-#{request.spec.platform}" unless Gem::Platform::RUBY == request.spec.platform @@ -140,10 +140,10 @@ class Gem::RequestSet::Lockfile out << " revision: #{revision}" out << " specs:" - requests.sort_by { |request| request.name }.each do |request| out << " #{request.name} (#{request.version})" - dependencies = request.spec.dependencies.sort_by { |dep| dep.name } dependencies.each do |dep| out << " #{dep.name}#{dep.requirement.for_lockfile}" end @@ -185,9 +185,9 @@ class Gem::RequestSet::Lockfile def add_PLATFORMS(out) # :nodoc: out << "PLATFORMS" - platforms = requests.map { |request| request.spec.platform }.uniq - platforms = platforms.sort_by { |platform| platform.to_s } platforms.each do |platform| out << " #{platform}" @@ -197,7 +197,7 @@ class Gem::RequestSet::Lockfile end def spec_groups - requests.group_by { |request| request.spec.class } end ## @@ -23,7 +23,7 @@ class Gem::RequestSet::Lockfile::Tokenizer end def to_a - @tokens.map { |token| [token.type, token.value, token.column, token.line] } end def skip(type) @@ -12,18 +12,18 @@ require "rubygems/deprecate" class Gem::Requirement OPS = { #:nodoc: - "=" => lambda { |v, r| v == r }, - "!=" => lambda { |v, r| v != r }, - ">" => lambda { |v, r| v > r }, - "<" => lambda { |v, r| v < r }, - ">=" => lambda { |v, r| v >= r }, - "<=" => lambda { |v, r| v <= r }, - "~>" => lambda { |v, r| v >= r && v.release < r.bump } }.freeze SOURCE_SET_REQUIREMENT = Struct.new(:for_lockfile).new "!" # :nodoc: - quoted = OPS.keys.map { |k| Regexp.quote k }.join "|" PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*".freeze # :nodoc: ## @@ -137,7 +137,7 @@ class Gem::Requirement if requirements.empty? @requirements = [DefaultRequirement] else - @requirements = requirements.map! { |r| self.class.parse r } end end @@ -148,7 +148,7 @@ class Gem::Requirement new = new.flatten new.compact! new.uniq! - new = new.map { |r| self.class.parse r } @requirements.concat new end @@ -188,7 +188,7 @@ class Gem::Requirement end def as_list # :nodoc: - requirements.map { |op, version| "#{op} #{version}" } end def hash # :nodoc: @@ -233,7 +233,7 @@ class Gem::Requirement # are prereleases def prerelease? - requirements.any? { |r| r.last.prerelease? } end def pretty_print(q) # :nodoc: @@ -249,7 +249,7 @@ class Gem::Requirement raise ArgumentError, "Need a Gem::Version: #{version.inspect}" unless Gem::Version === version # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey - requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv } end alias :=== :satisfied_by? @@ -285,7 +285,7 @@ class Gem::Requirement protected def _tilde_requirements - requirements.select { |r| r.first == "~>" } end private @@ -116,7 +116,7 @@ class Gem::Resolver 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 @@ -189,7 +189,7 @@ class Gem::Resolver def resolve locking_dg = Molinillo::DependencyGraph.new - Molinillo::Resolver.new(self, self).resolve(@needed.map { |d| DependencyRequest.new d, nil }, locking_dg).tsort.map(&:payload).compact rescue Molinillo::VersionConflict => e conflict = e.conflicts.values.first raise Gem::DependencyResolutionError, Conflict.new(conflict.requirement_trees.first.first, conflict.existing, conflict.requirement) @@ -206,7 +206,7 @@ class Gem::Resolver if (skip_dep_gems = skip_gems[dependency.name]) && !skip_dep_gems.empty? matching = all.select do |api_spec| - skip_dep_gems.any? { |s| api_spec.version == s.version } end all = matching unless matching.empty? @@ -235,7 +235,7 @@ class Gem::Resolver raise exc end - groups = Hash.new { |hash, key| hash[key] = [] } # create groups & sources in the same loop sources = possibles.map do |spec| @@ -248,9 +248,9 @@ class Gem::Resolver sources.each do |source| groups[source]. - sort_by { |spec| [spec.version, Gem::Platform.local =~ spec.platform ? 1 : 0] }. - map { |spec| ActivationRequest.new spec, dependency }. - each { |activation_request| activation_requests << activation_request } end activation_requests @@ -33,7 +33,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set @dep_uri = dep_uri @uri = dep_uri + '../..' - @data = Hash.new { |h,k| h[k] = [] } @source = Gem::Source.new @uri @to_fetch = [] @@ -67,7 +67,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set def prefetch(reqs) return unless @remote - names = reqs.map { |r| r.dependency.name } needed = names - @data.keys - @to_fetch @to_fetch += needed @@ -40,11 +40,11 @@ class Gem::Resolver::ComposedSet < Gem::Resolver::Set def remote=(remote) super - @sets.each { |set| set.remote = remote } end def errors - @errors + @sets.map { |set| set.errors }.flatten end ## @@ -60,7 +60,7 @@ class Gem::Resolver::ComposedSet < Gem::Resolver::Set # Prefetches +reqs+ in all sets. def prefetch(reqs) - @sets.each { |s| s.prefetch(reqs) } end end @@ -55,7 +55,7 @@ class Gem::Resolver::Conflict activated = @activated.spec.full_name dependency = @failed_dep.dependency requirement = dependency.requirement - alternates = dependency.matching_specs.map { |spec| spec.full_name } unless alternates.empty? matching = <<-MATCHING.chomp @@ -17,7 +17,7 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set Gem::SpecFetcher.fetcher end - @all = Hash.new { |h,k| h[k] = [] } list, errors = @f.available_specs :complete @@ -118,12 +118,12 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set dep = req.dependency return res if @ignore_dependencies and - @always_install.none? { |spec| dep.match? spec } name = dep.name dep.matching_specs.each do |gemspec| - next if @always_install.any? { |spec| spec.name == gemspec.name } res << Gem::Resolver::InstalledSpecification.new(self, gemspec) end unless @ignore_installed @@ -168,7 +168,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set end def inspect # :nodoc: - always_install = @always_install.map { |s| s.full_name } '#<%s domain: %s specs: %p always install: %p>' % [ self.class, @domain, @specs.keys, always_install, @@ -75,7 +75,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set q.text 'specs:' q.breakable - q.pp @specs.map { |spec| spec.full_name } end end @@ -485,7 +485,7 @@ module Gem::Security dcs = dcs.split '.' - name = "CN=#{cn}/#{dcs.map { |dc| "DC=#{dc}" }.join '/'}" OpenSSL::X509::Name.parse name end @@ -106,7 +106,7 @@ class Gem::Security::Signer # this value is preferred, otherwise the subject is used. def extract_name(cert) # :nodoc: - subject_alt_name = cert.extensions.find { |e| 'subjectAltName' == e.oid } if subject_alt_name /\Aemail:/ =~ subject_alt_name.value # rubocop:disable Performance/StartWith @@ -442,8 +442,8 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } logger = WEBrick::Log.new nil, WEBrick::BasicLog::FATAL @server = WEBrick::HTTPServer.new :DoNotListen => true, :Logger => logger - @spec_dirs = @gem_dirs.map { |gem_dir| File.join gem_dir, 'specifications' } - @spec_dirs.reject! { |spec_dir| !File.directory? spec_dir } reset_gems @@ -458,7 +458,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } def uri_encode(str) str.gsub(URI::UNSAFE) do |match| - match.each_byte.map { |c| sprintf('%%%02X', c.ord) }.join end end @@ -615,11 +615,11 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } } end - deps = deps.sort_by { |dep| [dep["name"].downcase, dep["version"]] } deps.last["is_last"] = true unless deps.empty? # executables - executables = spec.executables.sort.collect { |exec| {"executable" => exec} } executables = nil if executables.empty? executables.last["is_last"] = true if executables @@ -668,7 +668,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } "version" => Gem::VERSION, } - specs = specs.sort_by { |spec| [spec["name"].downcase, spec["version"]] } specs.last["is_last"] = true # tag all specs with first_name_entry @@ -869,7 +869,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } listeners = @server.listeners.map{|l| l.addr[2] } # TODO: 0.0.0.0 == any, not localhost. - host = listeners.any?{|l| l == '0.0.0.0'} ? 'localhost' : listeners.first say "Launching browser to http://#{host}:#{@port}" @@ -61,7 +61,7 @@ class Gem::Source::Local < Gem::Source when :latest tup = pkg.spec.name_tuple - cur = names.find { |x| x.name == tup.name } if !cur names << tup elsif cur.version < tup.version @@ -98,7 +98,7 @@ class Gem::Source::Local < Gem::Source end end - found.max_by { |s| s.version } end def fetch_spec(name) # :nodoc: @@ -90,7 +90,7 @@ class Gem::SourceList # Yields each source URI in the list. def each - @sources.each { |s| yield s.uri.to_s } end ## @@ -115,7 +115,7 @@ class Gem::SourceList # Returns an Array of source URI Strings. def to_a - @sources.map { |x| x.uri.to_s } end alias_method :to_ary, :to_a @@ -135,7 +135,7 @@ class Gem::SourceList if other.kind_of? Gem::Source @sources.include? other else - @sources.find { |x| x.uri.to_s == other.to_s } end end @@ -146,7 +146,7 @@ class Gem::SourceList if source.kind_of? Gem::Source @sources.delete source else - @sources.delete_if { |x| x.uri.to_s == source.to_s } end end @@ -92,8 +92,8 @@ class Gem::SpecFetcher list.each do |source, specs| if dependency.name.is_a?(String) && specs.respond_to?(:bsearch) - start_index = (0 ... specs.length).bsearch{ |i| specs[i].name >= dependency.name } - end_index = (0 ... specs.length).bsearch{ |i| specs[i].name > dependency.name } specs = specs[start_index ... end_index] if start_index && end_index end @@ -122,7 +122,7 @@ class Gem::SpecFetcher end end - tuples = tuples.sort_by { |x| x[0] } return [tuples, errors] end @@ -194,10 +194,10 @@ class Gem::SpecFetcher matches = if matches.empty? && type != :prerelease suggest_gems_from_name gem_name, :prerelease else - matches.uniq.sort_by { |name, dist| dist } end - matches.map { |name, dist| name }.uniq.first(num_results) end ## @@ -254,7 +254,7 @@ class Gem::SpecFetcher def tuples_for(source, type, gracefully_ignore=false) # :nodoc: @caches[type][source.uri] ||= - source.load_specs(type).sort_by { |tup| tup.name } rescue Gem::RemoteFetcher::FetchError raise unless gracefully_ignore [] @@ -180,8 +180,8 @@ class Gem::Specification < Gem::BasicSpecification end end - @@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 do |k| @@default_value[k].nil? end @@ -747,8 +747,8 @@ class Gem::Specification < Gem::BasicSpecification # After a reset, make sure already loaded specs # are still marked as activated. specs = {} - Gem.loaded_specs.each_value{|s| specs[s] = true} - @@all.each{|s| s.activated = true if specs[s]} end @@all end @@ -768,7 +768,7 @@ class Gem::Specification < Gem::BasicSpecification end 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 @@ -783,7 +783,7 @@ class Gem::Specification < Gem::BasicSpecification 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 @@ -802,10 +802,10 @@ class Gem::Specification < Gem::BasicSpecification @@stubs ||= begin pattern = "*.gemspec" stubs = installed_stubs(dirs, pattern) + default_stubs(pattern) - stubs = stubs.uniq { |stub| stub.full_name } _resort!(stubs) - @@stubs_by_name = stubs.select { |s| Gem::Platform.match s.platform }.group_by(&:name) stubs end end @@ -832,9 +832,9 @@ class Gem::Specification < Gem::BasicSpecification @@stubs_by_name[name] else pattern = "#{name}-*.gemspec" - stubs = installed_stubs(dirs, pattern).select { |s| Gem::Platform.match s.platform } + default_stubs(pattern) - stubs = stubs.uniq { |stub| stub.full_name }.group_by(&:name) - stubs.each_value { |v| _resort!(v) } @@stubs_by_name.merge! stubs @@stubs_by_name[name] ||= EMPTY @@ -928,7 +928,7 @@ class Gem::Specification < Gem::BasicSpecification def self.dirs=(dirs) self.reset - @@dirs = Array(dirs).map { |dir| File.join dir, "specifications" } end extend Enumerable @@ -1012,9 +1012,9 @@ class Gem::Specification < Gem::BasicSpecification def self.find_in_unresolved(path) # TODO: do we need these?? Kill it - specs = unresolved_deps.values.map { |dep| dep.to_specs }.flatten - specs.find_all { |spec| spec.contains_requirable_file? path } end ## @@ -1022,7 +1022,7 @@ class Gem::Specification < Gem::BasicSpecification # specs that contain the file matching +path+. def self.find_in_unresolved_tree(path) - specs = unresolved_deps.values.map { |dep| dep.to_specs }.flatten specs.each do |spec| spec.traverse do |from_spec, dep, to_spec, trail| @@ -1077,11 +1077,11 @@ class Gem::Specification < Gem::BasicSpecification # Return the latest installed spec for gem +name+. def self.latest_spec_for(name) - latest_specs(true).find { |installed_spec| installed_spec.name == name } end def self._latest_specs(specs, prerelease = false) # :nodoc: - result = Hash.new { |h,k| h[k] = {} } native = {} specs.reverse_each do |spec| @@ -1094,7 +1094,7 @@ class Gem::Specification < Gem::BasicSpecification result.map(&:last).map(&:values).flatten.reject do |spec| minimum = native[spec.name] minimum && spec.version < minimum - end.sort_by{ |tup| tup.name } end ## @@ -1168,7 +1168,7 @@ class Gem::Specification < Gem::BasicSpecification # version as well. def self.outdated - outdated_and_latest_version.map { |local, _| local.name } end ## @@ -1189,7 +1189,7 @@ class Gem::Specification < Gem::BasicSpecification Gem::Dependency.new local_spec.name, ">= #{local_spec.version}" remotes, = fetcher.search_for_dependency dependency - remotes = remotes.map { |n, _| n.version } latest_remote = remotes.sort.last @@ -1220,7 +1220,7 @@ class Gem::Specification < Gem::BasicSpecification def self.reset @@dirs = nil - Gem.pre_reset_hooks.each { |hook| hook.call } @@all = nil @@stubs = nil @@stubs_by_name = {} @@ -1237,19 +1237,19 @@ class Gem::Specification < Gem::BasicSpecification versions = find_all_by_name(dep.name) unless versions.empty? warn " Available/installed versions of this gem:" - versions.each { |s| warn " - #{s.version}" } end end warn "#{w}: Clearing out unresolved specs. Try 'gem cleanup <gem>'" warn "Please report a bug if this causes problems." unresolved.clear end - Gem.post_reset_hooks.each { |hook| hook.call } end # DOC: This method needs documented or nodoc'd def self.unresolved_deps - @unresolved_deps ||= Hash.new { |h, n| h[n] = Gem::Dependency.new n } end ## @@ -1280,7 +1280,7 @@ class Gem::Specification < Gem::BasicSpecification # Cleanup any YAML::PrivateType. They only show up for an old bug # where nil => null, so just convert them to nil based on the type. - array.map! { |e| e.kind_of?(YAML::PrivateType) ? nil : e } spec.instance_variable_set :@rubygems_version, array[0] # spec version @@ -1433,7 +1433,7 @@ class Gem::Specification < Gem::BasicSpecification self.summary = sanitize_string(summary) self.description = sanitize_string(description) self.post_install_message = sanitize_string(post_install_message) - self.authors = authors.collect { |a| sanitize_string(a) } end ## @@ -1456,7 +1456,7 @@ class Gem::Specification < Gem::BasicSpecification return nil if executables.nil? if @bindir - Array(executables).map { |e| File.join(@bindir, e) } else executables end @@ -1538,7 +1538,7 @@ class Gem::Specification < Gem::BasicSpecification def build_args if File.exist? build_info_file build_info = File.readlines build_info_file - build_info = build_info.map { |x| x.strip } build_info.delete "" build_info else @@ -1630,7 +1630,7 @@ class Gem::Specification < Gem::BasicSpecification def conficts_when_loaded_with?(list_of_specs) # :nodoc: result = list_of_specs.any? do |spec| - spec.dependencies.any? { |dep| dep.runtime? && (dep.name == name) && !satisfies_requirement?(dep) } end result end @@ -1765,7 +1765,7 @@ class Gem::Specification < Gem::BasicSpecification # Returns all specs that matches this spec's runtime dependencies. def dependent_specs - runtime_dependencies.map { |dep| dep.to_specs }.flatten end ## @@ -1779,7 +1779,7 @@ class Gem::Specification < Gem::BasicSpecification # List of dependencies that are used for development def development_dependencies - dependencies.select { |d| d.type == :development } end ## @@ -2283,9 +2283,9 @@ class Gem::Specification < Gem::BasicSpecification def ruby_code(obj) case obj when String then obj.dump + ".freeze" - when Array then '[' + obj.map { |x| ruby_code x }.join(", ") + ']' when Hash then - seg = obj.keys.sort.map { |k| "#{k.to_s.dump} => #{obj[k].to_s.dump}" } "{ #{seg.join(', ')} }" when Gem::Version then obj.to_s.dump when DateLike then obj.strftime('%Y-%m-%d').dump @@ -2313,7 +2313,7 @@ class Gem::Specification < Gem::BasicSpecification # True if this gem has the same attributes as +other+. def same_attributes?(spec) - @@attributes.all? { |name, default| self.send(name) == spec.send(name) } end private :same_attributes? @@ -2555,7 +2555,7 @@ class Gem::Specification < Gem::BasicSpecification unless result == :next spec_name = dep_spec.name dep_spec.traverse(trail, visited, &block) unless - trail.any? { |s| s.name == spec_name } end end end @@ -2580,11 +2580,11 @@ class Gem::Specification < Gem::BasicSpecification end def keep_only_files_and_directories - @executables.delete_if { |x| File.directory?(File.join(@bindir, x)) } - @extensions.delete_if { |x| File.directory?(x) && !File.symlink?(x) } - @extra_rdoc_files.delete_if { |x| File.directory?(x) && !File.symlink?(x) } - @files.delete_if { |x| File.directory?(x) && !File.symlink?(x) } - @test_files.delete_if { |x| File.directory?(x) && !File.symlink?(x) } end def validate_metadata @@ -154,7 +154,7 @@ class Gem::SpecificationPolicy def validate_duplicate_dependencies # :nodoc: # NOTE: see REFACTOR note in Gem::Dependency about types - this might be brittle - seen = Gem::Dependency::TYPES.inject({}) { |types, type| types.merge({ type => {}}) } error_messages = [] @specification.dependencies.each do |dep| @@ -215,7 +215,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: end end if warning_messages.any? - warning_messages.each { |warning_message| warning warning_message } end end @@ -292,7 +292,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: def validate_non_files return unless packaging - non_files = @specification.files.reject {|x| File.file?(x) || File.symlink?(x)} unless non_files.empty? error "[\"#{non_files.join "\", \""}\"] are not files" @@ -338,7 +338,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: String end - unless Array === val and val.all? {|x| x.kind_of?(klass)} error "#{field} must be an Array of #{klass}" end end @@ -369,7 +369,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: license value '#{license}' is invalid. Use a license identifier from http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license. WARNING - message += "Did you mean #{suggestions.map { |s| "'#{s}'"}.join(', ')}?\n" unless suggestions.nil? warning(message) end end @@ -433,7 +433,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li validate_shebang_line_in(executable) end - @specification.files.select { |f| File.symlink?(f) }.each do |file| warning "#{file} is a symlink, which is not supported on all platforms" end end @@ -461,7 +461,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li builder = Gem::Ext::Builder.new(@specification) rake_extension = @specification.extensions.any? {|s| builder.builder_for(s) == Gem::Ext::RakeBuilder } - rake_dependency = @specification.dependencies.any? {|d| d.name == 'rake'} warning <<-WARNING if rake_extension && !rake_dependency You have specified rake based extension, but rake is not added as dependency. It is recommended to add rake as a dependency in gemspec since there's no guarantee rake will be already installed. @@ -269,7 +269,7 @@ class Gem::TestCase < Minitest::Test end end - assert scan_make_command_lines(output).any? { |line| make = parse_make_command_line(line) if make[:targets].include?(target) @@ -425,9 +425,9 @@ class Gem::TestCase < Minitest::Test $LOAD_PATH.replace @orig_LOAD_PATH if @orig_LOAD_PATH if @orig_LOADED_FEATURES if @orig_LOAD_PATH - paths = @orig_LOAD_PATH.map {|path| File.join(File.expand_path(path), "/")} ($LOADED_FEATURES - @orig_LOADED_FEATURES).each do |feat| - unless paths.any? {|path| feat.start_with?(path)} $LOADED_FEATURES.delete(feat) end end @@ -791,7 +791,7 @@ class Gem::TestCase < Minitest::Test ensure prefix = File.dirname(__FILE__) + "/" new_features = ($LOADED_FEATURES - old_loaded_features) - old_loaded_features.concat(new_features.select {|f| f.rindex(prefix, 0)}) $LOADED_FEATURES.replace old_loaded_features end @@ -1014,7 +1014,7 @@ Also, a list: spec_fetcher = Gem::SpecFetcher.fetcher - prerelease, all = all_specs.partition { |spec| spec.version.prerelease? } latest = Gem::Specification._latest_specs all_specs spec_fetcher.specs[@uri] = [] @@ -1036,7 +1036,7 @@ Also, a list: unless Gem::RemoteFetcher === @fetcher v = Gem.marshal_version - specs = all.map { |spec| spec.name_tuple } s_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic specs latest_specs = latest.map do |spec| @@ -1045,7 +1045,7 @@ Also, a list: l_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic latest_specs - prerelease_specs = prerelease.map { |spec| spec.name_tuple } p_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic prerelease_specs @fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip @@ -1441,7 +1441,7 @@ Also, a list: # Finds all gems matching +dep+ in this set. def find_all(dep) - @specs.find_all { |s| dep.match? s, @prerelease } end ## @@ -76,7 +76,7 @@ class Gem::FakeFetcher 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 else Gem.read_binary(path) if path @@ -114,10 +114,10 @@ class Gem::Uninstaller if list.empty? return unless other_repo_specs.any? - other_repos = other_repo_specs.map { |spec| spec.base_dir }.uniq message = ["#{@gem} is not installed in GEM_HOME, try:"] - message.concat other_repos.map { |repo| "\tgem uninstall -i #{repo} #{@gem}" } @@ -126,7 +126,7 @@ class Gem::Uninstaller remove_all list elsif list.size > 1 - gem_names = list.map { |gem| gem.full_name } gem_names << "All versions" say @@ -197,7 +197,7 @@ class Gem::Uninstaller return if executables.empty? - executables = executables.map { |exec| formatted_program_filename exec } remove = if @force_executables.nil? ask_yes_no("Remove executables:\n" + @@ -232,7 +232,7 @@ class Gem::Uninstaller # NOTE: removes uninstalled gems from +list+. def remove_all(list) - list.each { |spec| uninstall_gem spec } end ## @@ -339,7 +339,7 @@ class Gem::Uninstaller end spec.dependent_gems(@check_dev).each do |dep_spec, dep, satlist| - unless siblings.any? { |s| s.satisfies_requirement? dep } msg << "#{dep_spec.name}-#{dep_spec.version} depends on #{dep}" end end @@ -323,7 +323,7 @@ class Gem::StreamUI def _gets_noecho require_io_console - @ins.noecho {@ins.gets} end ## @@ -60,7 +60,7 @@ class Gem::Validator # TODO needs further cleanup def alien(gems=[]) - errors = Hash.new { |h,k| h[k] = {} } Gem::Specification.each do |spec| next unless gems.include? spec.name unless gems.empty? @@ -231,7 +231,7 @@ class Gem::Version def bump @@bump[self] ||= begin segments = self.segments - segments.pop while segments.any? { |s| String === s } segments.pop if segments.size > 1 segments[-1] = segments[-1].succ @@ -310,7 +310,7 @@ class Gem::Version def release @@release[self] ||= if prerelease? segments = self.segments - segments.pop while segments.any? { |s| String === s } self.class.new segments.join('.') else self @@ -327,7 +327,7 @@ class Gem::Version def approximate_recommendation segments = self.segments - segments.pop while segments.any? { |s| String === s } segments.pop while segments.size > 2 segments.push 0 while segments.size < 2 |