Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.1x deprecate fixes 2 #1076

Merged
merged 4 commits into from Nov 20, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/faraday/deprecate.rb
Expand Up @@ -7,20 +7,23 @@ module Faraday
# usage about deprecation.
# @see Faraday::Deprecate
module DeprecatedClass
def self.proxy_class(new_klass)
Class.new(new_klass) do
class << self
def self.proxy_class(origclass, ver = '1.0')
technoweenie marked this conversation as resolved.
Show resolved Hide resolved
metaclass = nil
proxyclass = Class.new(origclass) do
metaclass = class << self
extend Faraday::Deprecate
# Make this more human readable than #<Class:Faraday::ClientError>
klass_name = superclass.to_s[/^#<Class:([\w:]+)>$/, 1]
deprecate :new, "#{klass_name}.new", '1.0'
deprecate :inherited, klass_name, '1.0'

def ===(other)
superclass === other || super
other.is_a?(superclass) || super
end

self
end
end

metaclass.send(:deprecate, :new, "#{origclass}.new", ver)
metaclass.send(:deprecate, :inherited, origclass.name, ver)
proxyclass
end
end

Expand Down Expand Up @@ -73,6 +76,7 @@ def skip_during
# @param ver [String] the semver the method will be removed.
def deprecate(name, repl, ver)
class_eval do
gem_ver = Gem::Version.new(ver)
old = "_deprecated_#{name}"
alias_method old, name
define_method name do |*args, &block|
Expand All @@ -87,7 +91,7 @@ def deprecate(name, repl, ver)
msg = [
"NOTE: #{target_message} is deprecated",
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
"It will be removed in or after version #{Gem::Version.new(ver)}",
"It will be removed in or after version #{gem_ver}",
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
]
warn "#{msg.join}." unless Faraday::Deprecate.skip
Expand Down