codus 0.0.1 → 0.0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascript/yojs.js +70 -0
- data/lib/codus/version.rb +1 -1
- metadata +2 -1
@@ -0,0 +1,70 @@
|
|
1
|
+
// git@github.com:codus/yojs.git
|
2
|
+
// Version: 0.0.1
|
3
|
+
|
4
|
+
if(!Array.prototype.last) {
|
5
|
+
Array.prototype.last = function() {
|
6
|
+
return this[this.length - 1];
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
var yojs = (function(){
|
11
|
+
var nameFunctionHash = {};
|
12
|
+
var parentsNamespaces = [];
|
13
|
+
|
14
|
+
var getNameSpaceResult = function(namespace, arguments) {
|
15
|
+
if (typeof(nameFunctionHash[namespace]) == 'function') {
|
16
|
+
return nameFunctionHash[namespace].apply(this, arguments);
|
17
|
+
} else {
|
18
|
+
return nameFunctionHash[namespace];
|
19
|
+
}
|
20
|
+
}
|
21
|
+
return {
|
22
|
+
define: function(namespace, value) {
|
23
|
+
if (this.isDefined(namespace)) {
|
24
|
+
var errorMessage = "Error: trying to define namespace '" + namespace + "'' twice";
|
25
|
+
throw errorMessage;
|
26
|
+
} else {
|
27
|
+
nameFunctionHash[namespace] = value;
|
28
|
+
}
|
29
|
+
return;
|
30
|
+
},
|
31
|
+
|
32
|
+
set: function(namespace, value) {
|
33
|
+
this.define(namespace, value);
|
34
|
+
},
|
35
|
+
|
36
|
+
call: function(namespace){
|
37
|
+
var parentNamespaceArray = namespace.split(".");
|
38
|
+
var lastNameCalled = parentNamespaceArray.pop();
|
39
|
+
var currentParentNamespace = parentNamespaceArray.join(".");
|
40
|
+
var returnValue = null;
|
41
|
+
var lastParentNamespace = parentsNamespaces.last();
|
42
|
+
var functionWithLastParentClassNamespace = lastParentNamespace + "." + lastNameCalled;
|
43
|
+
var errorMessage = "";
|
44
|
+
var calledFunctionArguments = Array.prototype.slice.apply(arguments, [1]);
|
45
|
+
|
46
|
+
parentsNamespaces.push(currentParentNamespace);
|
47
|
+
|
48
|
+
if (this.isDefined(namespace)) {
|
49
|
+
returnValue = getNameSpaceResult(namespace, calledFunctionArguments);
|
50
|
+
} else if (this.isDefined(functionWithLastParentClassNamespace)) {
|
51
|
+
returnValue = getNameSpaceResult(functionWithLastParentClassNamespace, calledFunctionArguments);
|
52
|
+
} else {
|
53
|
+
var errorMessage = "Error: called namespace '" + namespace + "'. But it doesn't exist.";
|
54
|
+
throw errorMessage;
|
55
|
+
}
|
56
|
+
|
57
|
+
parentsNamespaces.pop();
|
58
|
+
|
59
|
+
return returnValue;
|
60
|
+
},
|
61
|
+
|
62
|
+
get: function(namespace) {
|
63
|
+
return this.call(namespace);
|
64
|
+
},
|
65
|
+
|
66
|
+
isDefined: function(namespace) {
|
67
|
+
return nameFunctionHash.hasOwnProperty(namespace);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}());
|
data/lib/codus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/codus/view_helpers.rb
|
57
57
|
- lib/codus.rb
|
58
58
|
- lib/README.md
|
59
|
+
- app/assets/javascript/yojs.js
|
59
60
|
- README.md
|
60
61
|
homepage: https://github.com/codus/codus
|
61
62
|
licenses:
|