ende 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assets/javascripts/aura/extensions/devise.js.coffee +2 -2
  3. data/lib/assets/javascripts/widgets/viewer/main.js.coffee +1 -1
  4. data/lib/ende/version.rb +1 -1
  5. data/vendor/assets/components/build.js +638 -133
  6. data/vendor/components/indefinido-indemma/.gitignore +14 -0
  7. data/vendor/components/indefinido-indemma/.gitignore~ +2 -0
  8. data/vendor/components/indefinido-indemma/.ruby-gemset +1 -0
  9. data/vendor/components/indefinido-indemma/.ruby-version +1 -0
  10. data/vendor/components/indefinido-indemma/Gemfile +13 -0
  11. data/vendor/components/indefinido-indemma/Guardfile +39 -0
  12. data/vendor/components/indefinido-indemma/History.md +0 -0
  13. data/vendor/components/indefinido-indemma/Readme.md +447 -0
  14. data/vendor/components/indefinido-indemma/build/development.js +340 -0
  15. data/vendor/components/indefinido-indemma/build/release.js +22039 -0
  16. data/vendor/components/indefinido-indemma/build/test.js +22039 -0
  17. data/vendor/components/indefinido-indemma/component.json +7 -3
  18. data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/component.json +18 -0
  19. data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/index.js +110 -0
  20. data/vendor/components/indefinido-indemma/components/chaijs-chai/component.json +47 -0
  21. data/vendor/components/indefinido-indemma/components/chaijs-chai/index.js +1 -0
  22. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/assertion.js +130 -0
  23. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
  24. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
  25. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
  26. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/should.js +76 -0
  27. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
  28. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
  29. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
  30. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/eql.js +129 -0
  31. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
  32. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
  33. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
  34. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
  35. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
  36. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
  37. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
  38. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/index.js +108 -0
  39. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
  40. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
  41. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
  42. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
  43. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/test.js +26 -0
  44. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
  45. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/type.js +45 -0
  46. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai.js +80 -0
  47. data/vendor/components/indefinido-indemma/components/component-bind/component.json +14 -0
  48. data/vendor/components/indefinido-indemma/components/component-bind/index.js +24 -0
  49. data/vendor/components/indefinido-indemma/components/component-jquery/component.json +14 -0
  50. data/vendor/components/indefinido-indemma/components/component-jquery/index.js +9601 -0
  51. data/vendor/components/indefinido-indemma/components/component-type/component.json +18 -0
  52. data/vendor/components/indefinido-indemma/components/component-type/index.js +32 -0
  53. data/vendor/components/indefinido-indemma/components/indefinido-advisable/component.json +21 -0
  54. data/vendor/components/indefinido-indemma/components/indefinido-advisable/index.js +1 -0
  55. data/vendor/components/indefinido-indemma/components/indefinido-advisable/lib/advisable.js +60 -0
  56. data/vendor/components/indefinido-indemma/components/indefinido-observable/component.json +25 -0
  57. data/vendor/components/indefinido-indemma/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
  58. data/vendor/components/indefinido-indemma/components/indefinido-observable/index.js +1 -0
  59. data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/adapters/rivets.js +26 -0
  60. data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/observable.js +323 -0
  61. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
  62. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors.js +173 -0
  63. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
  64. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/object.create.js +77 -0
  65. data/vendor/components/indefinido-indemma/components/kapit-observe-utils/component.json +13 -0
  66. data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/component.json +17 -0
  67. data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/es6-shim.js +996 -0
  68. data/vendor/components/indefinido-indemma/components/pluma-assimilate/component.json +25 -0
  69. data/vendor/components/indefinido-indemma/components/pluma-assimilate/dist/assimilate.js +127 -0
  70. data/vendor/components/indefinido-indemma/karma.conf.js +86 -0
  71. data/vendor/components/indefinido-indemma/lib/record/associable.js +229 -82
  72. data/vendor/components/indefinido-indemma/lib/record/errors.js +1 -0
  73. data/vendor/components/indefinido-indemma/lib/record/persistable.js +32 -0
  74. data/vendor/components/indefinido-indemma/lib/record/queryable.js +32 -0
  75. data/vendor/components/indefinido-indemma/lib/record/resource.js +12 -4
  76. data/vendor/components/indefinido-indemma/lib/record/rest.js +1 -1
  77. data/vendor/components/indefinido-indemma/lib/record/restfulable.js +38 -27
  78. data/vendor/components/indefinido-indemma/lib/record/scopable.js +15 -2
  79. data/vendor/components/indefinido-indemma/lib/record/storable.js +48 -0
  80. data/vendor/components/indefinido-indemma/lib/record/validatable.js +10 -5
  81. data/vendor/components/indefinido-indemma/lib/record/validations/cpf.js +1 -1
  82. data/vendor/components/indefinido-indemma/lib/record.js +15 -12
  83. data/vendor/components/indefinido-indemma/spec/record/associable_spec.js +137 -0
  84. data/vendor/components/indefinido-indemma/spec/record/persistable_spec.js +36 -0
  85. data/vendor/components/indefinido-indemma/spec/record/queryable_spec.js +33 -0
  86. data/vendor/components/indefinido-indemma/spec/record/resource_spec.js +93 -0
  87. data/vendor/components/indefinido-indemma/spec/record/rest_spec.js +32 -0
  88. data/vendor/components/indefinido-indemma/spec/record/restfulable_spec.js +288 -0
  89. data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +212 -0
  90. data/vendor/components/indefinido-indemma/spec/record/storable_spec.js +53 -0
  91. data/vendor/components/indefinido-indemma/spec/record/translationable.js +28 -0
  92. data/vendor/components/indefinido-indemma/spec/record/validatable_spec.js +111 -0
  93. data/vendor/components/indefinido-indemma/spec/record/validations/associated_spec.js +43 -0
  94. data/vendor/components/indefinido-indemma/spec/record/validations/confirmation_spec.js +36 -0
  95. data/vendor/components/indefinido-indemma/spec/record/validations/cpf_spec.js +35 -0
  96. data/vendor/components/indefinido-indemma/spec/record/validations/presence_spec.js +28 -0
  97. data/vendor/components/indefinido-indemma/spec/record/validations/remote_spec.js +87 -0
  98. data/vendor/components/indefinido-indemma/spec/record/validations/type_spec.js +48 -0
  99. data/vendor/components/indefinido-indemma/spec/record_spec.js +37 -0
  100. data/vendor/components/indefinido-indemma/spec/spec_helper.js +11 -0
  101. data/vendor/components/indefinido-indemma/spec/support/value_objects/phone.js +45 -0
  102. data/vendor/components/indefinido-indemma/src/lib/extensions/rivets.coffee +17 -0
  103. data/vendor/components/indefinido-indemma/src/lib/record/associable.coffee +342 -0
  104. data/vendor/components/indefinido-indemma/src/lib/record/errors.coffee +20 -0
  105. data/vendor/components/indefinido-indemma/src/lib/record/maid.coffee +16 -0
  106. data/vendor/components/indefinido-indemma/src/lib/record/persistable.coffee +27 -0
  107. data/vendor/components/indefinido-indemma/src/lib/record/queryable.coffee +29 -0
  108. data/vendor/components/indefinido-indemma/src/lib/record/resource.coffee +106 -0
  109. data/vendor/components/indefinido-indemma/src/lib/record/rest.coffee +28 -0
  110. data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +348 -0
  111. data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +275 -0
  112. data/vendor/components/indefinido-indemma/src/lib/record/storable.coffee +46 -0
  113. data/vendor/components/indefinido-indemma/src/lib/record/translationable.coffee +18 -0
  114. data/vendor/components/indefinido-indemma/src/lib/record/validatable.coffee +217 -0
  115. data/vendor/components/indefinido-indemma/src/lib/record/validations/associated.coffee +32 -0
  116. data/vendor/components/indefinido-indemma/src/lib/record/validations/confirmation.coffee +19 -0
  117. data/vendor/components/indefinido-indemma/src/lib/record/validations/cpf.coffee +58 -0
  118. data/vendor/components/indefinido-indemma/src/lib/record/validations/presence.coffee +19 -0
  119. data/vendor/components/indefinido-indemma/src/lib/record/validations/remote.coffee +65 -0
  120. data/vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee +32 -0
  121. data/vendor/components/indefinido-indemma/src/lib/record.coffee +136 -0
  122. data/vendor/components/indefinido-indemma/src/spec/record/associable_spec.coffee +130 -0
  123. data/vendor/components/indefinido-indemma/src/spec/record/persistable_spec.coffee +30 -0
  124. data/vendor/components/indefinido-indemma/src/spec/record/queryable_spec.coffee +27 -0
  125. data/vendor/components/indefinido-indemma/src/spec/record/resource_spec.coffee +69 -0
  126. data/vendor/components/indefinido-indemma/src/spec/record/rest_spec.coffee +22 -0
  127. data/vendor/components/indefinido-indemma/src/spec/record/restfulable_spec.coffee +207 -0
  128. data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +191 -0
  129. data/vendor/components/indefinido-indemma/src/spec/record/storable_spec.coffee +40 -0
  130. data/vendor/components/indefinido-indemma/src/spec/record/translationable.coffee +19 -0
  131. data/vendor/components/indefinido-indemma/src/spec/record/validatable_spec.coffee +100 -0
  132. data/vendor/components/indefinido-indemma/src/spec/record/validations/associated_spec.coffee +35 -0
  133. data/vendor/components/indefinido-indemma/src/spec/record/validations/confirmation_spec.coffee +25 -0
  134. data/vendor/components/indefinido-indemma/src/spec/record/validations/cpf_spec.coffee +28 -0
  135. data/vendor/components/indefinido-indemma/src/spec/record/validations/presence_spec.coffee +24 -0
  136. data/vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee +74 -0
  137. data/vendor/components/indefinido-indemma/src/spec/record/validations/type_spec.coffee +33 -0
  138. data/vendor/components/indefinido-indemma/src/spec/record_spec.coffee +23 -0
  139. data/vendor/components/indefinido-indemma/src/spec/spec_helper.coffee +9 -0
  140. data/vendor/components/indefinido-indemma/src/spec/support/value_objects/phone.coffee +30 -0
  141. data/vendor/components/indefinido-indemma/vendor/object/mixin.js +196 -0
  142. data/vendor/components/indefinido-indemma/vendor/owl/pluralize.js +190 -0
  143. metadata +130 -2
@@ -0,0 +1,32 @@
1
+ var extend, model, queryable, record, stampit, storable;
2
+
3
+ extend = require('assimilate');
4
+
5
+ storable = require('./storable');
6
+
7
+ stampit = require('../../vendor/stampit');
8
+
9
+ queryable = {
10
+ storage: storable(),
11
+ find: function(key) {
12
+ return this.storage.store(key);
13
+ },
14
+ all: function() {
15
+ return this.storage.values();
16
+ },
17
+ where: function() {
18
+ throw new Error('queryable.where: Not implemented yet');
19
+ }
20
+ };
21
+
22
+ model = window.model;
23
+
24
+ record = window.record;
25
+
26
+ model.queryable = true;
27
+
28
+ module.exports = queryable;
29
+
30
+ model.mix(function(modelable) {
31
+ return extend(modelable, queryable);
32
+ });
@@ -2,6 +2,8 @@ var model, resource, resourceable, stampit;
2
2
 
3
3
  stampit = require('../../vendor/stampit');
4
4
 
5
+ require('../../vendor/owl/pluralize');
6
+
5
7
  resource = stampit({
6
8
  toString: function() {
7
9
  return this.name;
@@ -24,12 +26,12 @@ resource = stampit({
24
26
  });
25
27
 
26
28
  resourceable = {
27
- pluralize: function(word) {
29
+ pluralize: function(word, count, plural) {
28
30
  if (!(word && word.length)) {
29
31
  throw new TypeError("Invalid string passed to pluralize '" + word + "'");
30
32
  }
31
33
  if (word.indexOf('s') !== word.length - 1) {
32
- return word + 's';
34
+ return owl.pluralize(word, count, plural);
33
35
  } else {
34
36
  return word;
35
37
  }
@@ -73,7 +75,9 @@ resourceable = {
73
75
  },
74
76
  parent_id: {
75
77
  get: function() {
76
- return this[this.parent_resource]._id;
78
+ if (this[this.parent_resource]) {
79
+ return this[this.parent_resource]._id;
80
+ }
77
81
  },
78
82
  set: function() {
79
83
  return console.error('Warning changing associations throught parent_id not allowed for security and style guide purposes');
@@ -83,7 +87,11 @@ resourceable = {
83
87
  var resource_definition, _ref;
84
88
 
85
89
  if (this.parent_resource) {
86
- Object.defineProperty(this, "" + this.parent_resource + "_id", resourceable.parent_id);
90
+ Object.defineProperty(this, "" + this.parent_resource + "_id", {
91
+ value: resourceable.parent_id,
92
+ configurable: true,
93
+ enumerable: true
94
+ });
87
95
  }
88
96
  resource_definition = {};
89
97
  if (typeof this.resource === 'string') {
@@ -13,7 +13,7 @@ module.exports = {
13
13
  return request.call(this, 'post', this.route, data);
14
14
  },
15
15
  "delete": function(data) {
16
- return request.call(this, 'delete', this.route, data);
16
+ return request.call(this, 'delete', (this._id ? "" + this.route + "/" + this._id : this.route), data);
17
17
  }
18
18
  };
19
19
 
@@ -79,8 +79,14 @@ restful = {
79
79
  get: function(action, data) {
80
80
  var old_route, payload, promise, resource, route;
81
81
 
82
+ if (data == null) {
83
+ data = {};
84
+ }
82
85
  old_route = this.route;
83
- this.route = "/" + (model.pluralize(this.resource.name)) + "/" + action;
86
+ this.route = "/" + (model.pluralize(this.resource.name));
87
+ if (action) {
88
+ this.route += "/" + action;
89
+ }
84
90
  resource = data.resource;
85
91
  if (data && data.json) {
86
92
  data = data.json();
@@ -94,20 +100,24 @@ restful = {
94
100
  route = old_route;
95
101
  return promise;
96
102
  },
97
- put: rest.put
103
+ put: rest.put,
104
+ "delete": rest["delete"]
98
105
  },
99
106
  record: {
100
107
  reload: function() {
101
- var argument, promise, _i, _len;
108
+ var data, param, params, promise, _i, _len;
102
109
 
103
- promise = rest.get.call(this);
110
+ params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
111
+ data = params.pop();
112
+ if (type(data) !== 'object') {
113
+ params.push(data);
114
+ }
115
+ promise = rest.get.call(this, data || {});
104
116
  promise.done(this.assign_attributes);
105
117
  promise.fail(this.failed);
106
- for (_i = 0, _len = arguments.length; _i < _len; _i++) {
107
- argument = arguments[_i];
108
- if (type(argument) === 'function') {
109
- promise.done(argument);
110
- }
118
+ for (_i = 0, _len = params.length; _i < _len; _i++) {
119
+ param = params[_i];
120
+ promise.done(param);
111
121
  }
112
122
  return promise;
113
123
  },
@@ -151,13 +161,16 @@ restful = {
151
161
  association_name = _ref2[_l];
152
162
  association_attributes = attributes[association_name];
153
163
  delete attributes[association_name];
164
+ delete attributes[association_name + "_attributes"];
154
165
  if (association_attributes) {
155
166
  this[association_name] = this["build_" + association_name](association_attributes);
156
167
  }
157
168
  }
158
169
  _results = [];
159
170
  for (attribute in attributes) {
160
- _results.push(this[attribute] = attributes[attribute]);
171
+ if (attribute !== this[attribute]) {
172
+ _results.push(this[attribute] = attributes[attribute]);
173
+ }
161
174
  }
162
175
  return _results;
163
176
  },
@@ -221,7 +234,7 @@ restful = {
221
234
  }
222
235
  },
223
236
  failed: function(xhr, error, status) {
224
- var attribute_name, definition, e, message, messages, payload, _ref, _results;
237
+ var attribute_name, definition, e, message, messages, payload, _i, _len, _ref;
225
238
 
226
239
  payload = xhr.responseJSON;
227
240
  try {
@@ -234,37 +247,33 @@ restful = {
234
247
  case 422:
235
248
  definition = model[this.resource];
236
249
  _ref = payload.errors;
237
- _results = [];
238
250
  for (attribute_name in _ref) {
239
251
  messages = _ref[attribute_name];
240
- if (!(this.hasOwnProperty(attribute_name) || definition.hasOwnProperty(attribute_name))) {
252
+ if (!definition.associations) {
253
+ definition.associations = definition.has_one.concat(definition.has_many.concat(definition.belongs_to));
254
+ }
255
+ if (!(this.hasOwnProperty(attribute_name) || definition.hasOwnProperty(attribute_name) || definition.associations.indexOf(attribute_name) !== -1 || attribute_name === 'base')) {
241
256
  message = "Server returned an validation error message for a attribute that is not defined in your model.\n";
242
257
  message += "The attribute was '" + attribute_name + "', the model resource was '" + this.resource + "'.\n";
243
258
  message += "The model definition keys were '" + (JSON.stringify(Object.keys(definition))) + "'.\n";
244
259
  message += "Please remove server validation, or update your model definition.";
245
260
  throw new TypeError(message);
246
261
  }
247
- _results.push((function() {
248
- var _i, _len, _results1;
249
-
250
- _results1 = [];
251
- for (_i = 0, _len = messages.length; _i < _len; _i++) {
252
- message = messages[_i];
253
- _results1.push(this.errors.add(attribute_name, 'server', {
254
- server_message: message
255
- }));
256
- }
257
- return _results1;
258
- }).call(this));
262
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
263
+ message = messages[_i];
264
+ this.errors.add(attribute_name, 'server', {
265
+ server_message: message
266
+ });
267
+ }
259
268
  }
260
- return _results;
261
269
  break;
262
270
  default:
263
271
  message = "Fail in " + this.resource + ".save:\n";
264
272
  message += "Record: " + this + "\n";
265
273
  message += "Status: " + status + " (" + (payload.status || xhr.status) + ")\n";
266
- return message += "Error : " + (payload.error || payload.message || payload);
274
+ message += "Error : " + (payload.error || payload.message || payload);
267
275
  }
276
+ return this.saving = false;
268
277
  },
269
278
  toString: function() {
270
279
  var serialized;
@@ -310,10 +319,12 @@ restful = {
310
319
  delete json.route;
311
320
  delete json.initial_route;
312
321
  delete json.after_initialize;
322
+ delete json.before_initialize;
313
323
  delete json.parent_resource;
314
324
  delete json.nested_attributes;
315
325
  delete json.saving;
316
326
  delete json.salvation;
327
+ delete json.sustained;
317
328
  delete json.element;
318
329
  delete json["default"];
319
330
  delete json.lock;
@@ -31,7 +31,7 @@ scopable = {
31
31
  }
32
32
  builder = builders[type];
33
33
  if (builder == null) {
34
- throw "Unknown scope type " + type + " for model with resource " + model.resource;
34
+ throw "Unknown scope type: '" + type + "', For model with resource: '" + this.resource + "'";
35
35
  }
36
36
  this.scope.declared.push(name);
37
37
  return this[name] = builder({
@@ -100,7 +100,7 @@ scopable = {
100
100
  forward_scopes_to_associations: function() {
101
101
  var associated_factory, associated_resource, association, association_name, factory, forwarder, generate_forwarder, scope, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4;
102
102
 
103
- factory = model[this.resource];
103
+ factory = model[this.resource.name];
104
104
  _ref = factory.has_many;
105
105
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
106
106
  association_name = _ref[_i];
@@ -180,6 +180,19 @@ scopable = {
180
180
  };
181
181
 
182
182
  builders = {
183
+ string: stampit().enclose(function() {
184
+ var base;
185
+
186
+ base = scopable.base(this);
187
+ return stampit.mixIn(function() {
188
+ var callbacks, value, _base, _name;
189
+
190
+ value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
191
+ callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));
192
+ (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this["$" + base.name]);
193
+ return this;
194
+ });
195
+ }),
183
196
  boolean: stampit().enclose(function() {
184
197
  var base;
185
198
 
@@ -0,0 +1,48 @@
1
+ var extend, merge, model, record, stampit, storable;
2
+
3
+ extend = require('assimilate');
4
+
5
+ merge = extend.withStrategy('deep');
6
+
7
+ stampit = require('../../vendor/stampit');
8
+
9
+ storable = stampit({
10
+ store: function(keypath, value, options) {
11
+ var collection, entry, key, _i, _len;
12
+
13
+ collection = this.database;
14
+ keypath = keypath.toString().split('.');
15
+ key = keypath.pop();
16
+ for (_i = 0, _len = keypath.length; _i < _len; _i++) {
17
+ entry = keypath[_i];
18
+ collection[entry] || (collection[entry] = {});
19
+ collection = collection[entry];
20
+ }
21
+ if (arguments.length === 1) {
22
+ this.reads++;
23
+ return collection[key];
24
+ } else {
25
+ this.writes++;
26
+ value.sustained = true;
27
+ return collection[key] = value;
28
+ }
29
+ },
30
+ values: function() {
31
+ return Object.values(this.database);
32
+ }
33
+ }, {
34
+ type: 'object',
35
+ writes: 0,
36
+ reads: 0
37
+ }, function() {
38
+ this.database || (this.database = {});
39
+ return this;
40
+ });
41
+
42
+ model = window.model;
43
+
44
+ record = window.record;
45
+
46
+ model.storable = true;
47
+
48
+ module.exports = storable;
@@ -31,8 +31,12 @@ messages = {
31
31
  return "O registro associado " + attribute_name + " não é válido.";
32
32
  },
33
33
  server: function(attribute_name, options) {
34
- attribute_name = this.human_attribute_name(attribute_name);
35
- return "" + attribute_name + " " + options.server_message + ".";
34
+ if (attribute_name === 'base') {
35
+ return options.server_message;
36
+ } else {
37
+ attribute_name = this.human_attribute_name(attribute_name);
38
+ return "" + attribute_name + " " + options.server_message + ".";
39
+ }
36
40
  },
37
41
  type: function(attribute_name, options) {
38
42
  attribute_name = this.human_attribute_name(attribute_name);
@@ -66,7 +70,8 @@ errorsable = stampit({
66
70
  }
67
71
  },
68
72
  push: Array.prototype.push,
69
- splice: Array.prototype.splice
73
+ splice: Array.prototype.splice,
74
+ indexOf: Array.prototype.indexOf
70
75
  }, {
71
76
  model: null,
72
77
  messages: null,
@@ -87,7 +92,7 @@ initializers = {
87
92
  }
88
93
  });
89
94
  this.validated = false;
90
- this.subscribe('dirty', function() {
95
+ this.subscribe('dirty', function(value) {
91
96
  return this.validated = false;
92
97
  });
93
98
  return Object.defineProperty(this, 'valid', {
@@ -168,7 +173,7 @@ extensions = {
168
173
  validate: function(doned, failed) {
169
174
  var results, validator, _i, _len, _ref;
170
175
 
171
- if (this.validated) {
176
+ if (this.validated && !this.dirty) {
172
177
  return this.validation;
173
178
  }
174
179
  this.errors.clear();
@@ -30,7 +30,7 @@ cpfable = stampit({
30
30
  if (d1 > 9) {
31
31
  d1 = 0;
32
32
  }
33
- if (+dv.charAt(0 !== d1)) {
33
+ if (+dv.charAt(0) !== d1) {
34
34
  return false;
35
35
  }
36
36
  d1 *= 2;
@@ -21,7 +21,8 @@ this.model = (function() {
21
21
  modelable = {
22
22
  after_mix: [],
23
23
  record: {
24
- after_initialize: []
24
+ after_initialize: [],
25
+ before_initialize: []
25
26
  },
26
27
  all: function() {
27
28
  return this.cache;
@@ -32,11 +33,6 @@ this.model = (function() {
32
33
  params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
33
34
  throw 'model.create not implemented yet, try using the restful.model.create method';
34
35
  },
35
- find: function(id) {
36
- return this.where({
37
- id: id
38
- }, true);
39
- },
40
36
  where: function(conditions, first) {
41
37
  var record, results, _i, _len, _ref;
42
38
 
@@ -66,7 +62,7 @@ this.model = (function() {
66
62
  }
67
63
  };
68
64
  initialize_record = function(data) {
69
- var after_initialize, callback, instance, _i, _len, _ref;
65
+ var after_initialize, callback, creation, index, instance, _i, _j, _len, _len1, _ref, _ref1;
70
66
 
71
67
  if (data == null) {
72
68
  data = {
@@ -79,12 +75,18 @@ this.model = (function() {
79
75
  data.route || (data.route = this.route);
80
76
  data.nested_attributes = this.nested_attributes || [];
81
77
  after_initialize = (data.after_initialize || []).concat(this.record.after_initialize);
82
- instance = record.call(extend(Object.create(data), this.record, {
78
+ creation = extend(Object.create(data), this.record, creation, {
83
79
  after_initialize: after_initialize
84
- }));
85
- _ref = instance.after_initialize;
86
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
87
- callback = _ref[_i];
80
+ });
81
+ _ref = this.record.before_initialize;
82
+ for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
83
+ callback = _ref[index];
84
+ callback.call(this, creation);
85
+ }
86
+ instance = record.call(creation);
87
+ _ref1 = instance.after_initialize;
88
+ for (index = _j = 0, _len1 = _ref1.length; _j < _len1; index = ++_j) {
89
+ callback = _ref1[index];
88
90
  callback.call(instance, instance);
89
91
  }
90
92
  delete instance.after_initialize;
@@ -108,6 +110,7 @@ this.model = (function() {
108
110
  extend(instance, merge(this, modelable));
109
111
  this.record = instance.record = merge({}, instance.record, modelable.record);
110
112
  this.record.after_initialize = instance.record.after_initialize = instance.record.after_initialize.concat(after_initialize);
113
+ this.record.before_initialize = instance.record.before_initialize.concat([]);
111
114
  _ref = modelable.after_mix;
112
115
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
113
116
  callback = _ref[_i];
@@ -0,0 +1,137 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/associable');
6
+
7
+ describe('record', function() {
8
+ var record;
9
+
10
+ record = root.record;
11
+ return it('should create a record');
12
+ });
13
+
14
+ describe('model', function() {
15
+ var arthur, corporation, model, person, radio;
16
+
17
+ model = root.model;
18
+ arthur = radio = null;
19
+ person = corporation = null;
20
+ beforeEach(function() {
21
+ var ford, friend;
22
+
23
+ corporation = model.call({
24
+ resource: 'corporation'
25
+ });
26
+ friend = model.call({
27
+ resource: 'friends'
28
+ });
29
+ person = model.call({
30
+ resource: 'person',
31
+ has_many: 'friends',
32
+ belongs_to: 'corporation'
33
+ });
34
+ radio = corporation({
35
+ _id: 1,
36
+ name: 'Local Radio'
37
+ });
38
+ ford = friend({
39
+ _id: 2,
40
+ name: 'Ford Perfect'
41
+ });
42
+ return arthur = person({
43
+ _id: 3,
44
+ name: 'Arthur Philip Dent'
45
+ });
46
+ });
47
+ describe('has_one', function() {
48
+ return it('should add a has_one property with the associations descriptions', function() {
49
+ return $.type(person.has_one).should.be.eq('array');
50
+ });
51
+ });
52
+ describe('belongs_to', function() {
53
+ it('should add a belongs_to property with the associations descriptions', function() {
54
+ return $.type(person.belongs_to).should.be.eq('array');
55
+ });
56
+ describe("#associated_id", function() {
57
+ it('should return an partial resource when acessing associated', function() {
58
+ arthur.corporation_id = radio._id;
59
+ arthur.should.have.property('corporation');
60
+ arthur.corporation.should.be.object;
61
+ arthur.corporation.should.have.property('resource');
62
+ return arthur.corporation.should.have.property('_id', radio._id);
63
+ });
64
+ return xit('should fetch the resource when accessing associated and resource not present', function(done) {
65
+ radio = corporation({
66
+ _id: 1,
67
+ name: 'Local Radio'
68
+ });
69
+ arthur.corporation_id = radio._id;
70
+ arthur.corporation.should.be.object;
71
+ arthur.corporation.should.have.property('resource', radio.resource);
72
+ arthur.corporation._id.should.be(null);
73
+ arthur.corporation.locking.should.be.object;
74
+ return arthur.corporation.locking.done(function(corporation) {
75
+ corporation.should.have.property('_id', radio.id);
76
+ return corporation.should.have.property('name', radio.name);
77
+ });
78
+ });
79
+ });
80
+ describe("#associated", function() {
81
+ return it('should update associated id and record when associated record changes', function() {
82
+ radio = corporation({
83
+ _id: 1,
84
+ name: 'Local Radio',
85
+ sustained: true
86
+ });
87
+ expect(arthur.corporation).to.be.undefined;
88
+ arthur.corporation = radio;
89
+ arthur.should.to.have.property('corporation', radio);
90
+ return arthur.should.to.have.property('corporation_id', radio._id);
91
+ });
92
+ });
93
+ return describe("#build_associated", function() {
94
+ return it('should add builded object to association named attribute', function() {
95
+ arthur = person({
96
+ name: 'Arthur Dent'
97
+ });
98
+ corporation = arthur.build_corporation();
99
+ arthur.should.have.property('corporation');
100
+ return expect(corporation).to.be.ok;
101
+ });
102
+ });
103
+ });
104
+ return describe('has_many', function() {
105
+ it('should add a has_many property with the associations descriptions', function() {
106
+ return $.type(person.has_many).should.be.eq('array');
107
+ });
108
+ it('should return a record factory with associations stored', function() {
109
+ var has_many;
110
+
111
+ person.has_many.should.be.array;
112
+ has_many = Array.prototype.splice.call(person.has_many, 0);
113
+ return has_many.should.contain('friends');
114
+ });
115
+ return describe('#()', function() {
116
+ it('should return a record with an association object', function() {
117
+ return person().should.have.property('friends');
118
+ });
119
+ return describe('{generated_association}', function() {
120
+ var association;
121
+
122
+ association = null;
123
+ beforeEach(function() {
124
+ return association = person().friends;
125
+ });
126
+ it('should have query methods', function() {
127
+ association.should.have.property('all');
128
+ association.should.have.property('each');
129
+ return association.should.have.property('reload');
130
+ });
131
+ return describe('#all', function() {
132
+ return it('should auto observe nested associations attributes');
133
+ });
134
+ });
135
+ });
136
+ });
137
+ });
@@ -0,0 +1,36 @@
1
+ var persistable, root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ persistable = require('indemma/lib/record/persistable');
6
+
7
+ describe('persistable', function() {
8
+ return describe('model', function() {
9
+ it('should set the persistable key', function() {
10
+ return model.should.have.property('persistable', true);
11
+ });
12
+ return describe('#find', function() {
13
+ beforeEach(function() {
14
+ this.person = model.call({
15
+ resource: 'person',
16
+ has_many: 'friends',
17
+ belongs_to: 'corporation'
18
+ });
19
+ return this.arthur = this.person({
20
+ _id: '1',
21
+ name: 'Arthur Philip Dent'
22
+ });
23
+ });
24
+ return it('should call try to store a record after saving', function(done) {
25
+ var _this = this;
26
+
27
+ sinon.stub(this.person.storage, 'store').returns(true);
28
+ this.arthur.save(function() {
29
+ expect(_this.person.storage.store.calledOnce).to.be["true"];
30
+ return done();
31
+ });
32
+ return this.person.storage.store.restore();
33
+ });
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,33 @@
1
+ var queryable, root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ queryable = require('indemma/lib/record/queryable');
6
+
7
+ describe('queryable', function() {
8
+ return describe('model', function() {
9
+ beforeEach(function() {
10
+ return this.person = model.call({
11
+ resource: 'person'
12
+ });
13
+ });
14
+ it('should set the queryable key', function() {
15
+ return model.should.have.property('queryable', true);
16
+ });
17
+ it('should create a storage', function() {
18
+ return this.person.should.have.property('storage');
19
+ });
20
+ return describe('#find', function() {
21
+ beforeEach(function() {
22
+ this.arthur = this.person({
23
+ _id: '1',
24
+ name: 'Arthur Philip Dent'
25
+ });
26
+ return this.arthur.save();
27
+ });
28
+ return it('should retrieve a record by key', function() {
29
+ return this.person.find('1').should.have.property('name', this.arthur.name);
30
+ });
31
+ });
32
+ });
33
+ });