lacey-rails 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69f076ae1d57d71c0558f9b1b78d141568b9f242
4
- data.tar.gz: 4f6f65717dcb80eb6fb0178adf457143782c74ee
3
+ metadata.gz: 562c88bfad178367751a8002f3370e913305a478
4
+ data.tar.gz: 35808af3c1fbe1a01e6213b50d10d651f93674f0
5
5
  SHA512:
6
- metadata.gz: 5c9ac8c0128cfaee63208897ced17b6ee3cf4fbe51d300ca457c00d84091617b7869563d3f3b1d0849941fa67a267079a76fea2d6e3792094e29872dc2a0700b
7
- data.tar.gz: 56e8fb89d223df3e2dc94bfd30b455a59494c5f9992167db592e29bb11946f9a96c1cd560e3d1a1165f4ee9e4f2bd7ae61274fc71da602cf16804251739b9034
6
+ metadata.gz: f5214d28c2608a58ca8e7b6971cfb82d662c613b3ba5396c119b2b2c1f1068a20836afd22ab5518673c8ce1135cb5d8043303f366b35f4cdfb98e9d59848bb5a
7
+ data.tar.gz: 35d160d59fc925e2614e9bb7bce79f3165868dfccda1ba441463c66bbd8ae6eb4d3e5e94fbbc2a7fcc8fef9292081e214f81e7ef0441dcdb5330ab54a204c21e
@@ -1,5 +1,5 @@
1
1
  module Lacey
2
2
  module Rails
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -1,41 +1,131 @@
1
- window.App = function (app_name) {
2
- if (typeof app_name !== 'string' || app_name == '') {
3
- throw 'InvalidAppNameError - you must give a valid name to your lacey app';
4
- }
5
- this.app_name = app_name;
6
- this.modules = [];
7
- return this;
1
+ Object.prototype.has_parent = Object.prototype.is_child = false;
2
+
3
+ Object.prototype.inherits_from = function (klass) {
4
+ this.prototype = new (Function.bind.apply(klass, arguments))();
5
+ this.prototype.constructor = this;
6
+ this.prototype.is_child = this.prototype.has_parent = true;
8
7
  };
9
8
 
10
- App.prototype.register_module = function (module_name, module) {
11
- if (typeof module_name !== 'string' || module_name == '') {
12
- throw 'InvalidModuleNameError - you must give a valid name to your module';
13
- }
14
- if (typeof module !== 'function') {
15
- throw 'InvalidModuleError - your module must be a function';
9
+ var LaceyApp,
10
+ LaceyModule,
11
+ modules,
12
+ validate_app_name,
13
+ validate_duplicated_module,
14
+ validate_module_name,
15
+ validate_module_type,
16
+ validate_parent_module_name;
17
+
18
+ LaceyApp = function (app_name) {
19
+ validate_app_name.call(this, app_name);
20
+
21
+ this.modules = [];
22
+ this.name = app_name;
23
+ modules = {};
24
+
25
+ return this;
26
+ };
27
+
28
+ LaceyApp.prototype.register_module = function (module_name, parent_module, Module) {
29
+ if (typeof parent_module === 'function') {
30
+ Module = parent_module;
31
+ parent_module = null;
32
+ }
33
+
34
+ validate_module_name.call(this, module_name);
35
+ validate_module_type.call(this, Module);
36
+ validate_duplicated_module.call(this, module_name);
37
+
38
+ this[module_name] = new LaceyModule(module_name, parent_module, Module);
39
+ this.modules.push(module_name);
40
+ modules[module_name] = Module;
41
+
42
+ return this[module_name];
43
+ };
44
+
45
+ LaceyApp.prototype.unregister_module = function (module_name) {
46
+ validate_module_name.call(this, module_name);
47
+
48
+ this[module_name] = null;
49
+ modules[module_name] = null;
50
+
51
+ delete this[module_name];
52
+ delete modules[module_name];
53
+
54
+ return this;
55
+ };
56
+
57
+ validate_app_name = function (app_name) {
58
+ if (typeof app_name !== 'string' || app_name === '') {
59
+ throw 'InvalidNameError - you must give a valid name to your lacey app';
60
+ }
61
+
62
+ return true;
63
+ };
64
+
65
+ validate_module_name = function (module_name) {
66
+ if (typeof module_name !== 'string' || module_name === '') {
67
+ throw 'InvalidModuleNameError - you must give a valid name to your module';
68
+ }
69
+
70
+ return true;
71
+ };
72
+
73
+ validate_module_type = function (Module) {
74
+ if (typeof Module !== 'function') {
75
+ throw 'InvalidModuleError - your module must be a function';
76
+ }
77
+
78
+ return true;
79
+ };
80
+
81
+ validate_duplicated_module = function (module_name) {
82
+ if (this.modules[module_name] !== void 0) {
83
+ throw 'DuplicateModuleError - your module has already been registered';
84
+ }
85
+
86
+ return true;
87
+ };
88
+
89
+ LaceyModule = function (module_name, parent_module, Module) {
90
+ var instance = null;
91
+
92
+ this.initialized = false;
93
+ this.module_name = module_name;
94
+
95
+ this.get_instance = function () {
96
+ if (instance === null) {
97
+ if (parent_module !== null && parent_module !== module_name) {
98
+ validate_parent_module_name.call(this, parent_module);
99
+ Module.inherits_from(modules[parent_module]);
100
+ }
101
+
102
+ instance = new Module();
16
103
  }
17
- this.modules.push(module_name);
18
- this[module_name] = (function () {
19
- var initialize, get_instance, instance;
20
- instance = null;
21
- get_instance = function () {
22
- if (instance == null) {
23
- instance = new module;
24
- }
25
- return instance;
26
- };
27
- initialize = function () {
28
- if (instance == null) {
29
- var module = get_instance();
30
- if (typeof module.init == 'function')
31
- module.init()
32
- }
33
- return module;
34
- };
35
- return {
36
- initialize: initialize,
37
- get_instance: get_instance
38
- };
39
- })();
40
- return this[module_name];
41
- };
104
+
105
+ return instance;
106
+ };
107
+
108
+ return this;
109
+ };
110
+
111
+ LaceyModule.prototype.initialize = function () {
112
+ var instance = this.get_instance();
113
+
114
+ if (!this.initialized && (instance.initialize !== null) && typeof instance.initialize === 'function') {
115
+ instance.initialize();
116
+ this.initialized = true;
117
+ }
118
+
119
+ return instance;
120
+ };
121
+
122
+ validate_parent_module_name = function (parent_module) {
123
+ if (modules[parent_module] === null) {
124
+ throw 'InvalidParentModule - the parent module does not exist';
125
+ }
126
+
127
+ return true;
128
+ };
129
+
130
+
131
+ window.LaceyApp = LaceyApp;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lacey-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexzicat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-15 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,7 +55,6 @@ files:
55
55
  - lib/lacey/rails.rb
56
56
  - lib/lacey/rails/version.rb
57
57
  - vendor/assets/javascripts/lacey.js
58
- - vendor/assets/javascripts/lacey.min.js
59
58
  homepage: https://github.com/alexzicat/lacey-rails
60
59
  licenses:
61
60
  - MIT
@@ -1 +0,0 @@
1
- window.App=function(t){if("string"!=typeof t||""==t)throw"InvalidAppNameError - you must give a valid name to your lacey app";return this.app_name=t,this.modules=[],this},App.prototype.register_module=function(t,n){if("string"!=typeof t||""==t)throw"InvalidModuleNameError - you must give a valid name to your module";if("function"!=typeof n)throw"InvalidModuleError - your module must be a function";return this.modules.push(t),this[t]=function(){var t,i,o;return o=null,i=function(){return null==o&&(o=new n),o},t=function(){if(null==o){var t=i();"function"==typeof t.init&&t.init()}return t},{initialize:t,get_instance:i}}(),this[t]};