* Wraps a method so that you can pass in either a string, OID or the object * itself and you will always get back a promise that resolves to the object. * @param {Object} objectType The object type that you're expecting to receive. * @param {Function} lookupFunction The function to do the lookup fo
(objectType, lookupFunction)
| 9 | * @return {Function} |
| 10 | */ |
| 11 | function lookupWrapper(objectType, lookupFunction) { |
| 12 | lookupFunction = lookupFunction || objectType.lookup; |
| 13 | |
| 14 | return function(repo, id, callback) { |
| 15 | if (id instanceof objectType) { |
| 16 | return Promise.resolve(id).then(function(obj) { |
| 17 | obj.repo = repo; |
| 18 | |
| 19 | if (typeof callback === "function") { |
| 20 | callback(null, obj); |
| 21 | } |
| 22 | |
| 23 | return obj; |
| 24 | }, callback); |
| 25 | } |
| 26 | |
| 27 | return lookupFunction(repo, id).then(function(obj) { |
| 28 | obj.repo = repo; |
| 29 | |
| 30 | if (typeof callback === "function") { |
| 31 | callback(null, obj); |
| 32 | } |
| 33 | |
| 34 | return obj; |
| 35 | }, callback); |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | NodeGit.Utils.lookupWrapper = lookupWrapper; |
no outgoing calls
no test coverage detected
searching dependent graphs…