diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-02 13:50:51 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-02 13:50:51 +0200 |
commit | b80dfd7b9a41b03f0bc30895c300deba54df8d6b (patch) | |
tree | 12135d2297f02385eb406868419e9f382180729e /lib/api/deprecate.js | |
parent | 4c144b6ceb648053001f0a8a143cddea3d154bc3 (diff) | |
download | gitbook-b80dfd7b9a41b03f0bc30895c300deba54df8d6b.zip gitbook-b80dfd7b9a41b03f0bc30895c300deba54df8d6b.tar.gz gitbook-b80dfd7b9a41b03f0bc30895c300deba54df8d6b.tar.bz2 |
Add method contentLink as deprecated for plugin API
Diffstat (limited to 'lib/api/deprecate.js')
-rw-r--r-- | lib/api/deprecate.js | 20 |
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 |