Skip to content

Commit

Permalink
add deprecation notice when using old constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Jan 19, 2012
1 parent 7ec1ead commit 9c3f2a4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/faraday_middleware/backwards_compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
deprecation_warning = lambda { |old, new, trace|
warn "Deprecation warning: #{old} is deprecated; use #{new}"
warn trace[0,10].join("\n") if $DEBUG
}

Faraday::Request.extend Module.new {
legacy = [:OAuth, :OAuth2]
define_method(:const_missing) { |const|
if legacy.include? const
const_set const, FaradayMiddleware.const_get(const)
klass = FaradayMiddleware.const_get(const)
deprecation_warning.call "Faraday::Request::#{const}", klass.name, caller
const_set const, klass
else
super
end
Expand All @@ -13,7 +20,9 @@
legacy = [:Mashify, :Rashify, :ParseJson, :ParseMarshal, :ParseXml, :ParseYaml]
define_method(:const_missing) { |const|
if legacy.include? const
const_set const, FaradayMiddleware.const_get(const)
klass = FaradayMiddleware.const_get(const)
deprecation_warning.call "Faraday::Response::#{const}", klass.name, caller
const_set const, klass
else
super
end
Expand Down

0 comments on commit 9c3f2a4

Please sign in to comment.