summaryrefslogtreecommitdiffstats
path: root/lib/api/deprecate.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/deprecate.js')
-rw-r--r--lib/api/deprecate.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/api/deprecate.js b/lib/api/deprecate.js
index d8d6ac1..95ab93b 100644
--- a/lib/api/deprecate.js
+++ b/lib/api/deprecate.js
@@ -1,4 +1,5 @@
var is = require('is');
+var objectPath = require('object-path');
var logged = {};
var disabled = {};
@@ -96,8 +97,27 @@ function disableDeprecation(key) {
disabled[key] = true;
}
+/**
+ Deprecate a method in favor of another one
+
+ @param {Book} book
+ @param {String} key
+ @param {Object} instance
+ @param {String} oldName
+ @param {String} newName
+*/
+function deprecateRenamedMethod(book, key, instance, oldName, newName, msg) {
+ msg = msg || ('"' + oldName + '" is deprecated, use "' + newName + '()" instead');
+ var fn = objectPath.get(instance, newName);
+
+ instance[oldName] = deprecateMethod(book, key, function() {
+ return fn.apply(instance, arguments);
+ }. msg);
+}
+
module.exports = {
method: deprecateMethod,
+ renamedMethod: deprecateRenamedMethod,
field: deprecateField,
enable: enableDeprecation,
disable: disableDeprecation