Skip to content

Commit

Permalink
Add next_rubygems_major_version method
Browse files Browse the repository at this point in the history
  • Loading branch information
bronzdoc committed Mar 31, 2020
1 parent d1a9e83 commit db5bb65
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/rubygems/deprecate.rb
Expand Up @@ -41,16 +41,17 @@ def skip_during
Gem::Deprecate.skip = original
end

def self.next_rubygems_major_version # :nodoc:
Gem::Version.new(Gem.rubygems_version.segments.first).bump
end

##
# Simple deprecation method that deprecates +name+ by wrapping it up
# in a dummy method. It warns on each call to the dummy method
# telling the user of +repl+ (unless +repl+ is :none) and the
# Rubygems version that it is planned to go away.

def deprecate(name, replacement=:none)
current_major = Gem::Version.new(Gem.rubygems_version.segments.first)
next_rubygems_major_version = current_major.bump

class_eval do
old = "_deprecated_#{name}"
alias_method old, name
Expand All @@ -59,7 +60,7 @@ def deprecate(name, replacement=:none)
target = klass ? "#{self}." : "#{self.class}#"
msg = [ "NOTE: #{target}#{name} is deprecated",
replacement == :none ? " with no replacement" : "; use #{replacement} instead",
". It will be removed in Rubygems #{next_rubygems_major_version}",
". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}",
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
]
warn "#{msg.join}." unless Gem::Deprecate.skip
Expand All @@ -70,17 +71,14 @@ def deprecate(name, replacement=:none)

# Deprecation method to deprecate Rubygems commands
def deprecate_command
current_major = Gem::Version.new(Gem.rubygems_version.segments.first)
next_rubygems_major_version = current_major.bump

class_eval do
define_method "deprecated?" do
true
end

define_method "deprecation_warning" do
msg = [ "#{self.command} command is deprecated",
". It will be removed in Rubygems #{next_rubygems_major_version}.\n",
". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}.\n",
]

alert_warning "#{msg.join}" unless Gem::Deprecate.skip
Expand Down

0 comments on commit db5bb65

Please sign in to comment.