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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/faraday/deprecate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ module Faraday
# usage about deprecation.
# @see Faraday::Deprecate
module DeprecatedClass
def self.proxy_class(new_klass)
Class.new(new_klass) do
def self.proxy_class(origclass, ver = '1.0')
technoweenie marked this conversation as resolved.
Show resolved Hide resolved
proxy = Class.new(origclass) do
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
end
end
proxy.singleton_class.send(:deprecate, :new, "#{origclass}.new", ver)
proxy.singleton_class.send(:deprecate, :inherited, origclass.name, ver)
proxy
end
end

Expand Down Expand Up @@ -73,6 +72,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 +87,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