1 var f = require('util').format;
3 var Define = function(name, object, stream) {
6 this.stream = typeof stream == 'boolean' ? stream : false;
7 this.instrumentations = {};
10 Define.prototype.classMethod = function(name, options) {
11 var keys = Object.keys(options).sort();
12 var key = generateKey(keys, options);
14 // Add a list of instrumentations
15 if(this.instrumentations[key] == null) {
16 this.instrumentations[key] = {
17 methods: [], options: options
21 // Push to list of method for this instrumentation
22 this.instrumentations[key].methods.push(name);
25 var generateKey = function(keys, options) {
27 for(var i = 0; i < keys.length; i++) {
28 parts.push(f('%s=%s', keys[i], options[keys[i]]));
34 Define.prototype.staticMethod = function(name, options) {
35 options.static = true;
36 var keys = Object.keys(options).sort();
37 var key = generateKey(keys, options);
39 // Add a list of instrumentations
40 if(this.instrumentations[key] == null) {
41 this.instrumentations[key] = {
42 methods: [], options: options
46 // Push to list of method for this instrumentation
47 this.instrumentations[key].methods.push(name);
50 Define.prototype.generate = function(keys, options) {
51 // Generate the return object
53 name: this.name, obj: this.object, stream: this.stream,
57 for(var name in this.instrumentations) {
58 object.instrumentations.push(this.instrumentations[name]);
64 module.exports = Define;