-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheden.js
executable file
·110 lines (94 loc) · 2.22 KB
/
eden.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var eden = module.exports = require('eden-class').extend(function() {
/* Require
-------------------------------*/
/* Constants
-------------------------------*/
/* Public.Properties
-------------------------------*/
/* Protected Properties
-------------------------------*/
/* Private Properties
-------------------------------*/
/* Magic
-------------------------------*/
this.___get = function(name) {
//if it starts with a capital letter
if(/^[A-Z]/g.test(name)) {
//its probably a class
return function() {
var args = this.args();
args.unshift(name.toLowerCase());
return this.load.apply(this, args);
};
}
};
/* Public.Methods
-------------------------------*/
/**
* No operation
*
* @return void
*/
this.noop = function() {};
/**
* Turns off argument test.
* argument testing is a performance gain
* though it helps with stablizing your code
*
* @return this
*/
this.noArgumentTesting = function() {
this.argument().turnOff();
return this;
};
/**
* Returns an array form of arguments
*
* @return array
*/
this.args = function() {
return Array.prototype.slice.apply(arguments.callee.caller.caller.arguments);
};
/**
* Loads a file and calls it passing arguments
*
* @param [mixed[,mixed..]]
* @return object
*/
this.load = function() {
//argument 1 must be a string
this.argument().test(1, 'string');
var args = this.args();
return this.get(args.shift()).apply(null, args);
};
/**
* Returns the classified definition
*
* @param string
* @return function
*/
this.get = function(name) {
return require('eden-'+name);
};
/* Protected.Methods
-------------------------------*/
/* Private Methods
-------------------------------*/
}).register('eden');
var instance = null, container = eden.get();
container.load = function() {
//first instantiate
if(instance === null) {
var definition = function() {};
definition.prototype = container.prototype;
instance = new definition();
if(typeof instance.__construct === 'function') {
instance.__construct.call(instance);
}
}
//if there are arguments
if(arguments.length) {
return instance.load.apply(instance, arguments);
}
return instance;
};