Skip to content

Instantly share code, notes, and snippets.

@grampelberg
Created May 28, 2010 23:07
Show Gist options
  • Save grampelberg/417867 to your computer and use it in GitHub Desktop.
Save grampelberg/417867 to your computer and use it in GitHub Desktop.
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