util/rubocop -A --only Style/RedundantSelf

This commit is contained in:
Hiroshi SHIBATA 2023-03-16 13:12:38 +09:00
parent 5211900d37
commit 1ca67f13cd
10 changed files with 43 additions and 43 deletions

View File

@ -1136,7 +1136,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
# This is used throughout RubyGems for enabling reproducible builds. # This is used throughout RubyGems for enabling reproducible builds.
def self.source_date_epoch def self.source_date_epoch
Time.at(self.source_date_epoch_string.to_i).utc.freeze Time.at(source_date_epoch_string.to_i).utc.freeze
end end
# FIX: Almost everywhere else we use the `def self.` way of defining class # FIX: Almost everywhere else we use the `def self.` way of defining class

View File

@ -269,7 +269,7 @@ class Gem::BasicSpecification
# Return all files in this gem that match for +glob+. # Return all files in this gem that match for +glob+.
def matches_for_glob(glob) # TODO: rename? def matches_for_glob(glob) # TODO: rename?
glob = File.join(self.lib_dirs_glob, glob) glob = File.join(lib_dirs_glob, glob)
Dir[glob].map {|f| f.tap(&Gem::UNTAINT) } # FIX our tests are broken, run w/ SAFE=1 Dir[glob].map {|f| f.tap(&Gem::UNTAINT) } # FIX our tests are broken, run w/ SAFE=1
end end
@ -286,17 +286,17 @@ class Gem::BasicSpecification
# for this spec. # for this spec.
def lib_dirs_glob def lib_dirs_glob
dirs = if self.raw_require_paths dirs = if raw_require_paths
if self.raw_require_paths.size > 1 if raw_require_paths.size > 1
"{#{self.raw_require_paths.join(",")}}" "{#{raw_require_paths.join(",")}}"
else else
self.raw_require_paths.first raw_require_paths.first
end end
else else
"lib" # default value for require_paths for bundler/inline "lib" # default value for require_paths for bundler/inline
end end
"#{self.full_gem_path}/#{dirs}".dup.tap(&Gem::UNTAINT) "#{full_gem_path}/#{dirs}".dup.tap(&Gem::UNTAINT)
end end
## ##

View File

@ -313,7 +313,7 @@ class Gem::Command
options[:build_args] = build_args options[:build_args] = build_args
if options[:silent] if options[:silent]
old_ui = self.ui old_ui = ui
self.ui = ui = Gem::SilentUI.new self.ui = ui = Gem::SilentUI.new
end end

View File

@ -29,7 +29,7 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo
end end
def initialize def initialize
super "push", "Push a gem up to the gem server", :host => self.host super "push", "Push a gem up to the gem server", :host => host
@user_defined_host = false @user_defined_host = false

View File

@ -61,7 +61,7 @@ data you will need to change them immediately and yank your gem.
end end
def yank_gem(version, platform) def yank_gem(version, platform)
say "Yanking gem from #{self.host}..." say "Yanking gem from #{host}..."
args = [:delete, version, platform, "api/v1/gems/yank"] args = [:delete, version, platform, "api/v1/gems/yank"]
response = yank_api_request(*args) response = yank_api_request(*args)

View File

@ -74,10 +74,10 @@ class Gem::Dependency
def inspect # :nodoc: def inspect # :nodoc:
if prerelease? if prerelease?
"<%s type=%p name=%p requirements=%p prerelease=ok>" % "<%s type=%p name=%p requirements=%p prerelease=ok>" %
[self.class, self.type, self.name, requirement.to_s] [self.class, type, name, requirement.to_s]
else else
"<%s type=%p name=%p requirements=%p>" % "<%s type=%p name=%p requirements=%p>" %
[self.class, self.type, self.name, requirement.to_s] [self.class, type, name, requirement.to_s]
end end
end end
@ -168,16 +168,16 @@ class Gem::Dependency
def ==(other) # :nodoc: def ==(other) # :nodoc:
Gem::Dependency === other && Gem::Dependency === other &&
self.name == other.name && name == other.name &&
self.type == other.type && type == other.type &&
self.requirement == other.requirement requirement == other.requirement
end end
## ##
# Dependencies are ordered by name. # Dependencies are ordered by name.
def <=>(other) def <=>(other)
self.name <=> other.name name <=> other.name
end end
## ##
@ -262,7 +262,7 @@ class Gem::Dependency
end end
default = Gem::Requirement.default default = Gem::Requirement.default
self_req = self.requirement self_req = requirement
other_req = other.requirement other_req = other.requirement
return self.class.new name, self_req if other_req == default return self.class.new name, self_req if other_req == default
@ -323,7 +323,7 @@ class Gem::Dependency
end end
def to_spec def to_spec
matches = self.to_specs.compact matches = to_specs.compact
active = matches.find(&:activated?) active = matches.find(&:activated?)
return active if active return active if active

View File

@ -103,7 +103,7 @@ module Gem::Deprecate
old = "_deprecated_#{name}" old = "_deprecated_#{name}"
alias_method old, name alias_method old, name
define_method name do |*args, &block| define_method name do |*args, &block|
klass = self.is_a? Module klass = is_a? Module
target = klass ? "#{self}." : "#{self.class}#" target = klass ? "#{self}." : "#{self.class}#"
msg = [ msg = [
"NOTE: #{target}#{name} is deprecated", "NOTE: #{target}#{name} is deprecated",
@ -129,7 +129,7 @@ module Gem::Deprecate
old = "_deprecated_#{name}" old = "_deprecated_#{name}"
alias_method old, name alias_method old, name
define_method name do |*args, &block| define_method name do |*args, &block|
klass = self.is_a? Module klass = is_a? Module
target = klass ? "#{self}." : "#{self.class}#" target = klass ? "#{self}." : "#{self.class}#"
msg = [ msg = [
"NOTE: #{target}#{name} is deprecated", "NOTE: #{target}#{name} is deprecated",
@ -153,7 +153,7 @@ module Gem::Deprecate
define_method "deprecation_warning" do define_method "deprecation_warning" do
msg = [ msg = [
"#{self.command} command is deprecated", "#{command} command is deprecated",
". It will be removed in Rubygems #{version}.\n", ". It will be removed in Rubygems #{version}.\n",
] ]

View File

@ -120,7 +120,7 @@ module Gem::GemcutterUtilities
end end
def update_scope(scope) def update_scope(scope)
sign_in_host = self.host sign_in_host = host
pretty_host = pretty_host(sign_in_host) pretty_host = pretty_host(sign_in_host)
update_scope_params = { scope => true } update_scope_params = { scope => true }
@ -146,7 +146,7 @@ module Gem::GemcutterUtilities
# key. # key.
def sign_in(sign_in_host = nil, scope: nil) def sign_in(sign_in_host = nil, scope: nil)
sign_in_host ||= self.host sign_in_host ||= host
return if api_key return if api_key
pretty_host = pretty_host(sign_in_host) pretty_host = pretty_host(sign_in_host)
@ -279,7 +279,7 @@ module Gem::GemcutterUtilities
end end
def default_host? def default_host?
self.host == Gem::DEFAULT_HOST host == Gem::DEFAULT_HOST
end end
def get_user_profile(email, password) def get_user_profile(email, password)

View File

@ -52,7 +52,7 @@ class Gem::RemoteFetcher
# Cached RemoteFetcher instance. # Cached RemoteFetcher instance.
def self.fetcher def self.fetcher
@fetcher ||= self.new Gem.configuration[:http_proxy] @fetcher ||= new Gem.configuration[:http_proxy]
end end
attr_accessor :headers attr_accessor :headers
@ -147,7 +147,7 @@ class Gem::RemoteFetcher
remote_gem_path = source_uri + "gems/#{gem_file_name}" remote_gem_path = source_uri + "gems/#{gem_file_name}"
self.cache_update_path remote_gem_path, local_gem_path cache_update_path remote_gem_path, local_gem_path
rescue FetchError rescue FetchError
raise if spec.original_platform == spec.platform raise if spec.original_platform == spec.platform
@ -157,7 +157,7 @@ class Gem::RemoteFetcher
remote_gem_path = source_uri + "gems/#{alternate_name}" remote_gem_path = source_uri + "gems/#{alternate_name}"
self.cache_update_path remote_gem_path, local_gem_path cache_update_path remote_gem_path, local_gem_path
end end
end end
when "file" then when "file" then

View File

@ -938,7 +938,7 @@ class Gem::Specification < Gem::BasicSpecification
# Return full names of all specs in sorted order. # Return full names of all specs in sorted order.
def self.all_names def self.all_names
self._all.map(&:full_name) _all.map(&:full_name)
end end
## ##
@ -973,7 +973,7 @@ class Gem::Specification < Gem::BasicSpecification
# this resets the list of known specs. # this resets the list of known specs.
def self.dirs=(dirs) def self.dirs=(dirs)
self.reset reset
@@dirs = Array(dirs).map {|dir| File.join dir, "specifications" } @@dirs = Array(dirs).map {|dir| File.join dir, "specifications" }
end end
@ -987,7 +987,7 @@ class Gem::Specification < Gem::BasicSpecification
def self.each def self.each
return enum_for(:each) unless block_given? return enum_for(:each) unless block_given?
self._all.each do |x| _all.each do |x|
yield x yield x
end end
end end
@ -1418,7 +1418,7 @@ class Gem::Specification < Gem::BasicSpecification
# there are conflicts upon activation. # there are conflicts upon activation.
def activate def activate
other = Gem.loaded_specs[self.name] other = Gem.loaded_specs[name]
if other if other
check_version_conflict other check_version_conflict other
return false return false
@ -1429,7 +1429,7 @@ class Gem::Specification < Gem::BasicSpecification
activate_dependencies activate_dependencies
add_self_to_load_path add_self_to_load_path
Gem.loaded_specs[self.name] = self Gem.loaded_specs[name] = self
@activated = true @activated = true
@loaded = true @loaded = true
@ -1444,7 +1444,7 @@ class Gem::Specification < Gem::BasicSpecification
def activate_dependencies def activate_dependencies
unresolved = Gem::Specification.unresolved_deps unresolved = Gem::Specification.unresolved_deps
self.runtime_dependencies.each do |spec_dep| runtime_dependencies.each do |spec_dep|
if loaded = Gem.loaded_specs[spec_dep.name] if loaded = Gem.loaded_specs[spec_dep.name]
next if spec_dep.matches_spec? loaded next if spec_dep.matches_spec? loaded
@ -1458,7 +1458,7 @@ class Gem::Specification < Gem::BasicSpecification
begin begin
specs = spec_dep.to_specs specs = spec_dep.to_specs
rescue Gem::MissingSpecError => e rescue Gem::MissingSpecError => e
raise Gem::MissingSpecError.new(e.name, e.requirement, "at: #{self.spec_file}") raise Gem::MissingSpecError.new(e.name, e.requirement, "at: #{spec_file}")
end end
if specs.size == 1 if specs.size == 1
@ -1677,7 +1677,7 @@ class Gem::Specification < Gem::BasicSpecification
def conflicts def conflicts
conflicts = {} conflicts = {}
self.runtime_dependencies.each do |dep| runtime_dependencies.each do |dep|
spec = Gem.loaded_specs[dep.name] spec = Gem.loaded_specs[dep.name]
if spec && !spec.satisfies_requirement?(dep) if spec && !spec.satisfies_requirement?(dep)
(conflicts[spec] ||= []) << dep (conflicts[spec] ||= []) << dep
@ -1703,7 +1703,7 @@ class Gem::Specification < Gem::BasicSpecification
def has_conflicts? def has_conflicts?
return true unless Gem.env_requirement(name).satisfied_by?(version) return true unless Gem.env_requirement(name).satisfied_by?(version)
self.dependencies.any? do |dep| dependencies.any? do |dep|
if dep.runtime? if dep.runtime?
spec = Gem.loaded_specs[dep.name] spec = Gem.loaded_specs[dep.name]
spec && !spec.satisfies_requirement?(dep) spec && !spec.satisfies_requirement?(dep)
@ -1808,7 +1808,7 @@ class Gem::Specification < Gem::BasicSpecification
Gem::Specification.each do |spec| Gem::Specification.each do |spec|
deps = check_dev ? spec.dependencies : spec.runtime_dependencies deps = check_dev ? spec.dependencies : spec.runtime_dependencies
deps.each do |dep| deps.each do |dep|
if self.satisfies_requirement?(dep) if satisfies_requirement?(dep)
sats = [] sats = []
find_all_satisfiers(dep) do |sat| find_all_satisfiers(dep) do |sat|
sats << sat sats << sat
@ -2251,7 +2251,7 @@ class Gem::Specification < Gem::BasicSpecification
attributes.unshift :name attributes.unshift :name
attributes.each do |attr_name| attributes.each do |attr_name|
current_value = self.send attr_name current_value = send attr_name
current_value = current_value.sort if %i[files test_files].include? attr_name current_value = current_value.sort if %i[files test_files].include? attr_name
if current_value != default_value(attr_name) || if current_value != default_value(attr_name) ||
self.class.required_attribute?(attr_name) self.class.required_attribute?(attr_name)
@ -2277,7 +2277,7 @@ class Gem::Specification < Gem::BasicSpecification
# that is already loaded (+other+) # that is already loaded (+other+)
def check_version_conflict(other) # :nodoc: def check_version_conflict(other) # :nodoc:
return if self.version == other.version return if version == other.version
# This gem is already loaded. If the currently loaded gem is not in the # This gem is already loaded. If the currently loaded gem is not in the
# list of candidate gems, then we have a version conflict. # list of candidate gems, then we have a version conflict.
@ -2285,7 +2285,7 @@ class Gem::Specification < Gem::BasicSpecification
msg = "can't activate #{full_name}, already activated #{other.full_name}" msg = "can't activate #{full_name}, already activated #{other.full_name}"
e = Gem::LoadError.new msg e = Gem::LoadError.new msg
e.name = self.name e.name = name
raise e raise e
end end
@ -2377,7 +2377,7 @@ class Gem::Specification < Gem::BasicSpecification
# True if this gem has the same attributes as +other+. # True if this gem has the same attributes as +other+.
def same_attributes?(spec) def same_attributes?(spec)
@@attributes.all? {|name, _default| self.send(name) == spec.send(name) } @@attributes.all? {|name, _default| send(name) == spec.send(name) }
end end
private :same_attributes? private :same_attributes?
@ -2514,7 +2514,7 @@ class Gem::Specification < Gem::BasicSpecification
@@attributes.each do |attr_name| @@attributes.each do |attr_name|
next if handled.include? attr_name next if handled.include? attr_name
current_value = self.send(attr_name) current_value = send(attr_name)
if current_value != default_value(attr_name) || self.class.required_attribute?(attr_name) if current_value != default_value(attr_name) || self.class.required_attribute?(attr_name)
result << " s.#{attr_name} = #{ruby_code current_value}" result << " s.#{attr_name} = #{ruby_code current_value}"
end end
@ -2706,7 +2706,7 @@ class Gem::Specification < Gem::BasicSpecification
end end
nil_attributes.each do |attribute| nil_attributes.each do |attribute|
default = self.default_value attribute default = default_value attribute
value = case default value = case default
when Time, Numeric, Symbol, true, false, nil then default when Time, Numeric, Symbol, true, false, nil then default