Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only warn once for each instance a deprecated method is called

  • Loading branch information...
commit e21d6eb7da74b3f283995c1d27d5880e75f0ae84 1 parent 2989d6e
@arsduo authored
Showing with 13 additions and 4 deletions.
  1. +13 −4 lib/multi_json.rb
View
17 lib/multi_json.rb
@@ -43,7 +43,7 @@ def default_adapter
# TODO: Remove for 2.0 release (but no sooner)
def engine
- Kernel.warn "#{Kernel.caller.first}: [DEPRECATION] MultiJson.engine is deprecated and will be removed in the next major version. Use MultiJson.adapter instead."
+ deprecate("MultiJson.engine is deprecated and will be removed in the next major version. Use MultiJson.adapter instead.")
self.adapter
end
@@ -56,7 +56,7 @@ def adapter
# TODO: Remove for 2.0 release (but no sooner)
def adapter=(new_adapter)
- Kernel.warn "#{Kernel.caller.first}: [DEPRECATION] MultiJson.adapter= is deprecated and will be removed in the next major version. Use MultiJson.use instead."
+ deprecate("MultiJson.adapter= is deprecated and will be removed in the next major version. Use MultiJson.use instead.")
self.use(new_adapter)
end
@@ -85,7 +85,7 @@ def use(new_adapter)
# TODO: Remove for 2.0 release (but no sooner)
def decode(string, options={})
- Kernel.warn "#{Kernel.caller.first}: [DEPRECATION] MultiJson.decode is deprecated and will be removed in the next major version. Use MultiJson.load instead."
+ deprecate("MultiJson.decode is deprecated and will be removed in the next major version. Use MultiJson.load instead.")
self.load(string, options)
end
@@ -102,7 +102,7 @@ def load(string, options={})
# TODO: Remove for 2.0 release (but no sooner)
def encode(object, options={})
- Kernel.warn "#{Kernel.caller.first}: [DEPRECATION] MultiJson.encode is deprecated and will be removed in the next major version. Use MultiJson.dump instead."
+ deprecate("MultiJson.encode is deprecated and will be removed in the next major version. Use MultiJson.dump instead.")
self.dump(object, options)
end
@@ -110,4 +110,13 @@ def encode(object, options={})
def dump(object, options={})
adapter.dump(object, options)
end
+
+ # Sends of a deprecation warning
+ def deprecate(message)
+ @messages ||= {}
+ unless @messages[message]
+ @messages[message] = true
+ Kernel.warn "#{Kernel.caller.first}: [DEPRECATION] #{message}"
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.