classified-magic
Advanced tools
Comparing version 0.0.5 to 0.0.6
29
magic.js
@@ -1,4 +0,5 @@ | ||
var classified = require('classified'); | ||
var separator = require('path').sep; | ||
var classified = require('classified'), | ||
separator = require('path').sep, | ||
registry = {}; | ||
if(typeof Proxy === 'undefined') { | ||
@@ -60,3 +61,8 @@ var Proxy = require('node-proxy'); | ||
//if prototype is a string | ||
if(typeof prototype === 'string') { | ||
//and it's definied in the registry | ||
if(typeof prototype === 'string' | ||
&& typeof registry[prototype] !== 'undefined') { | ||
prototype = registry[prototype]; | ||
//if prototype is a string | ||
} else if(typeof prototype === 'string') { | ||
//its a path to a file | ||
@@ -74,2 +80,6 @@ var path = _getCallerPath(); | ||
} | ||
//its a string and we do not know | ||
//what to do with it | ||
} else { | ||
return this; | ||
} | ||
@@ -107,2 +117,13 @@ } | ||
/** | ||
* Registers this class for extend | ||
* | ||
* @param string | ||
* @return this | ||
*/ | ||
method.register = function(name) { | ||
registry[name] = this.definition(); | ||
return this; | ||
}; | ||
/** | ||
* Sets loader to return a single instance | ||
@@ -109,0 +130,0 @@ * |
{ | ||
"name": "classified-magic", | ||
"description": "OOP for NodeJS with magic", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Christian Blanquera", |
@@ -242,3 +242,15 @@ var assert = require('assert'); | ||
}); | ||
it('should not be able to register and access root', function() { | ||
Root.register('rooty'); | ||
var child = classified({ | ||
sampleMethod: function() { | ||
return typeof this.___parent.__sampleMethod; | ||
} | ||
}).extend('rooty').load(); | ||
assert.equal('undefined', child.sampleMethod()); | ||
}); | ||
}); | ||
}); |
16621
411