Skip to content

Commit

Permalink
Merge pull request #1076 from lostisland/0.1x-deprecate-fixes-2
Browse files Browse the repository at this point in the history
0.1x deprecate fixes 2
  • Loading branch information
technoweenie committed Nov 20, 2019
2 parents 2f1a8c9 + b499d4f commit 389ede4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/faraday/deprecate.rb
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')
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

0 comments on commit 389ede4

Please sign in to comment.