lib/yard/rubygems/backports/source_index.rb in yard-0.9.5 vs lib/yard/rubygems/backports/source_index.rb in yard-0.9.6
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++
@@ -39,13 +40,11 @@
class << self
# Undef old methods
%w(from_installed_gems installed_spec_directories
from_gems_in load_specification).each do |meth|
- if instance_methods(true).find {|m| m.to_s == meth }
- undef_method(meth)
- end
+ undef_method(meth) if instance_methods(true).find {|m| m.to_s == meth }
end
##
# Factory method to construct a source index instance for a given
# path.
@@ -61,19 +60,19 @@
def from_installed_gems(*deprecated)
if deprecated.empty?
from_gems_in(*installed_spec_directories)
else
- from_gems_in(*deprecated) # HACK warn
+ from_gems_in(*deprecated) # HACK: warn
end
end
##
# Returns a list of directories from Gem.path that contain specifications.
def installed_spec_directories
- Gem.path.collect { |dir| File.join(dir, "specifications") }
+ Gem.path.collect {|dir| File.join(dir, "specifications") }
end
##
# Creates a new SourceIndex from the ruby format gem specifications in
# +spec_dirs+.
@@ -89,37 +88,36 @@
# loaded spec.
def load_specification(file_name)
Gem::Specification.load file_name
end
-
end
##
# Constructs a source index instance from the provided specifications, which
# is a Hash of gem full names and Gem::Specifications.
#--
# TODO merge @gems and @prerelease_gems and provide a separate method
# #prerelease_gems
- def initialize(specifications={})
+ def initialize(specifications = {})
@gems = {}
- specifications.each{ |full_name, spec| add_spec spec }
+ specifications.each {|_full_name, spec| add_spec spec }
@spec_dirs = nil
end
# TODO: remove method
def all_gems
@gems
end
def prerelease_gems
- @gems.reject{ |name, gem| !gem.version.prerelease? }
+ @gems.reject {|_name, gem| !gem.version.prerelease? }
end
def released_gems
- @gems.reject{ |name, gem| gem.version.prerelease? }
+ @gems.reject {|_name, gem| gem.version.prerelease? }
end
##
# Reconstruct the source index from the specifications in +spec_dirs+.
@@ -140,30 +138,30 @@
##
# Returns an Array specifications for the latest released versions
# of each gem in this index.
- def latest_specs(include_prerelease=false)
- result = Hash.new { |h,k| h[k] = [] }
+ def latest_specs(include_prerelease = false)
+ result = Hash.new {|h, k| h[k] = [] }
latest = {}
sort.each do |_, spec|
name = spec.name
curr_ver = spec.version
prev_ver = latest.key?(name) ? latest[name].version : nil
next if !include_prerelease && curr_ver.prerelease?
- next unless prev_ver.nil? or curr_ver >= prev_ver or
+ next unless prev_ver.nil? || curr_ver >= prev_ver ||
latest[name].platform != Gem::Platform::RUBY
- if prev_ver.nil? or
- (curr_ver > prev_ver and spec.platform == Gem::Platform::RUBY) then
+ if prev_ver.nil? ||
+ (curr_ver > prev_ver && spec.platform == Gem::Platform::RUBY)
result[name].clear
latest[name] = spec
end
- if spec.platform != Gem::Platform::RUBY then
+ if spec.platform != Gem::Platform::RUBY
result[name].delete_if do |result_spec|
result_spec.platform == spec.platform
end
end
@@ -271,11 +269,11 @@
def search(gem_pattern, platform_only = false)
requirement = nil
only_platform = false
- # TODO - Remove support and warning for legacy arguments after 2008/11
+ # TODO: Remove support and warning for legacy arguments after 2008/11
unless Gem::Dependency === gem_pattern
warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
end
case gem_pattern
@@ -283,38 +281,38 @@
requirement = platform_only || Gem::Requirement.default
when Gem::Dependency then
only_platform = platform_only
requirement = gem_pattern.requirement
- gem_pattern = if Regexp === gem_pattern.name then
+ gem_pattern = if Regexp === gem_pattern.name
gem_pattern.name
- elsif gem_pattern.name.empty? then
+ elsif gem_pattern.name.empty?
//
else
/^#{Regexp.escape gem_pattern.name}$/
end
else
requirement = platform_only || Gem::Requirement.default
gem_pattern = /#{gem_pattern}/i
end
- unless Gem::Requirement === requirement then
+ unless Gem::Requirement === requirement
requirement = Gem::Requirement.create requirement
end
specs = all_gems.values.select do |spec|
- spec.name =~ gem_pattern and
- requirement.satisfied_by? spec.version
+ spec.name =~ gem_pattern &&
+ requirement.satisfied_by?(spec.version)
end
- if only_platform then
+ if only_platform
specs = specs.select do |spec|
Gem::Platform.match spec.platform
end
end
- specs.sort_by { |s| s.sort_obj }
+ specs.sort_by(&:sort_obj)
end
##
# Replaces the gems in the source index from specifications in the
# directories this source index was created from. Raises an exception if
@@ -335,36 +333,33 @@
latest_specs.each do |local|
dependency = Gem::Dependency.new local.name, ">= #{local.version}"
fetcher = Gem::SpecFetcher.fetcher
remotes = fetcher.find_matching dependency
- remotes = remotes.map { |(_, version, _), _| version }
+ remotes = remotes.map {|(_, version, _), _| version }
latest = remotes.sort.last
- outdateds << local.name if latest and local.version < latest
+ outdateds << local.name if latest && local.version < latest
end
outdateds
end
def ==(other) # :nodoc:
- self.class === other and @gems == other.gems
+ self.class === other && @gems == other.gems
end
def dump
Marshal.dump(self)
end
-
end
# :stopdoc:
module Gem
-
##
# Cache is an alias for SourceIndex to allow older YAMLized source index
# objects to load properly.
Cache = SourceIndex unless defined?(Cache)
-
end
# :startdoc: