Created
May 28, 2010 23:07
-
-
Save grampelberg/417867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mimic = { | |
history: {}, | |
get_history: function(k) { | |
if (k in mimic.history) return mimic.history[k]; | |
mimic.history[k] = []; | |
return mimic.history[k]; | |
}, | |
record: function(root, priv, not_recursive) { | |
function inspect(obj, path) { | |
_.each(obj, function(v, k) { | |
if (!priv && k.match(/^_.*/)) return | |
var current_path = path ? path + '.' + k : k; | |
if (_.isFunction(v)) { | |
obj[k] = _.wrap(v, _.bind(mimic._report, this, current_path)); | |
return | |
} | |
if (!not_recursive) return inspect(v, current_path); | |
}); | |
} | |
inspect(root); | |
}, | |
_report: function(name, fn) { | |
var resp = fn.apply(this, _.toArray(arguments).slice(2)); | |
mimic.get_history(name).push({ name: name, resp: resp }); | |
return resp; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment