shimmer does a bunch of the work necessary to wrap other methods in
a wrapper you provide:
var http = require'http';var shimmer = require'shimmer';shimmerwraphttp 'request'returnconsole.log"Starting request!";var returned = originalapplythis argumentsconsole.log"Done setting up request -- OH YEAH!";return returned;;;
All monkeypatched functions have an attribute,
__wrapped, set to true on
If you pass in an options object containing a function labeled
shimmer will use it instead of the logger, which defaults to
shimmer is built to be as unobtrusive as possible and has no need to run
asynchronously, so it defaults to logging when things fail, instead of
shimmer monkeypatches in place, so it expects to be passed an object.
It accepts either instances, prototypes, or the results of calling
name must be the string key for the field's name on the
wrapper is a function that takes a single parameter, which is the original
function to be monkeypatched.
shimmer assumes that you're adding behavior
to the original method, and not replacing it outright. If you are replacing
the original function, feel free to ignore the passed-in function.
If you aren't discarding the original, remember these tips:
original.apply(this, arguments), unless your reason for monkeypatching is to transform the arguments.
wrap, with the addition that you can wrap multiple methods on
multiple modules. Note that this function expects the list of functions to be
monkeypatched on all of the modules to be the same.
A convenience function for restoring the function back the way it was before you started. Won't unwrap if somebody else has monkeypatched the function after you (but will log in that case). Won't throw if you try to double-unwrap a function (but will log).