ende 0.4.4 → 0.4.5

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.
@@ -1,212 +1,224 @@
1
- (function() {
2
- var errorsable, extensions, initializers, manager, messages, observable, root, stampit, type;
3
-
4
- require('./translationable');
5
-
6
- root = typeof exports !== "undefined" && exports !== null ? exports : this;
7
-
8
- stampit = require('../../vendor/stampit');
9
-
10
- observable = require('observable').mixin;
11
-
12
- type = require('type');
13
-
14
- messages = {
15
- blank: function(attribute_name) {
16
- attribute_name = this.human_attribute_name(attribute_name);
17
- return "O campo " + attribute_name + " não pode ficar em branco.";
18
- },
19
- cpf: function(attribute_name) {
20
- attribute_name = this.human_attribute_name(attribute_name);
21
- return "O campo " + attribute_name + " não está válido.";
22
- },
23
- confirmation: function(attribute_name) {
24
- var confirmation_attribute_name;
25
- confirmation_attribute_name = this.human_attribute_name(attribute_name);
26
- attribute_name = this.human_attribute_name(attribute_name.replace('_confirmation', ''));
27
- return "O campo " + attribute_name + " não está de acordo com o campo " + confirmation_attribute_name + ".";
28
- },
29
- associated: function(attribute_name) {
30
- attribute_name = this.human_attribute_name(attribute_name);
31
- return "O registro associado " + attribute_name + " não é válido.";
32
- },
33
- server: function(attribute_name, options) {
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
- }
40
- },
41
- type: function(attribute_name, options) {
1
+ var errorsable, extensions, initializers, manager, messages, observable, root, stampit, type;
2
+
3
+ require('./translationable');
4
+
5
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
6
+
7
+ stampit = require('../../vendor/stampit');
8
+
9
+ observable = require('observable').mixin;
10
+
11
+ type = require('type');
12
+
13
+ messages = {
14
+ blank: function(attribute_name) {
15
+ attribute_name = this.human_attribute_name(attribute_name);
16
+ return "O campo " + attribute_name + " não pode ficar em branco.";
17
+ },
18
+ cpf: function(attribute_name) {
19
+ attribute_name = this.human_attribute_name(attribute_name);
20
+ return "O campo " + attribute_name + " não está válido.";
21
+ },
22
+ confirmation: function(attribute_name) {
23
+ var confirmation_attribute_name;
24
+
25
+ confirmation_attribute_name = this.human_attribute_name(attribute_name);
26
+ attribute_name = this.human_attribute_name(attribute_name.replace('_confirmation', ''));
27
+ return "O campo " + attribute_name + " não está de acordo com o campo " + confirmation_attribute_name + ".";
28
+ },
29
+ associated: function(attribute_name) {
30
+ attribute_name = this.human_attribute_name(attribute_name);
31
+ return "O registro associado " + attribute_name + " não é válido.";
32
+ },
33
+ server: function(attribute_name, options) {
34
+ if (attribute_name === 'base') {
35
+ return options.server_message;
36
+ } else {
42
37
  attribute_name = this.human_attribute_name(attribute_name);
43
- return "O campo " + attribute_name + " não está válido.";
38
+ return "" + attribute_name + " " + options.server_message + ".";
44
39
  }
45
- };
46
-
47
- errorsable = stampit({
48
- add: function(attribute_name, message_key, options) {
49
- var translator;
50
- this.push([attribute_name, message_key, options]);
51
- this.messages[attribute_name] = '';
52
- translator = messages[message_key];
53
- if (translator != null) {
54
- return this.messages[attribute_name] += translator.call(this.model, attribute_name, options);
55
- } else {
56
- return this.messages[attribute_name] += message_key;
57
- }
58
- },
59
- clear: function() {
60
- var attribute_name, _results;
61
- if (this.length) {
62
- this.length = 0;
63
- _results = [];
64
- for (attribute_name in this.messages) {
65
- _results.push(this.messages[attribute_name] = null);
66
- }
67
- return _results;
68
- }
69
- },
70
- push: Array.prototype.push,
71
- splice: Array.prototype.splice,
72
- indexOf: Array.prototype.indexOf
73
- }, {
74
- model: null,
75
- messages: null,
76
- length: 0
77
- }, function() {
78
- this.messages = {};
79
- return this;
80
- });
81
-
82
- initializers = {
83
- define_triggers: function() {
84
- this.errors = errorsable({
85
- model: model[this.resource]
86
- });
87
- this.before('save', function() {
88
- if (this.save) return this.validate();
89
- });
90
- this.validated = false;
91
- this.subscribe('dirty', function(value) {
92
- return value && (this.validated = false);
93
- });
94
- return Object.defineProperty(this, 'valid', {
95
- get: function() {
96
- this.validate();
97
- if (this.validation.state() === 'resolved') {
98
- return !this.errors.length;
99
- } else {
100
- return null;
101
- }
102
- },
103
- set: function() {
104
- throw new TypeError("You can't set the value for the valid property.");
105
- },
106
- enumerable: false
107
- });
108
- },
109
- create_validators: function(definitions) {
110
- var definition, name, validator, validator_options, _ref, _results;
111
- this.validators = [];
112
- _ref = manager.validators;
40
+ },
41
+ type: function(attribute_name, options) {
42
+ attribute_name = this.human_attribute_name(attribute_name);
43
+ return "O campo " + attribute_name + " não está válido.";
44
+ }
45
+ };
46
+
47
+ errorsable = stampit({
48
+ add: function(attribute_name, message_key, options) {
49
+ var translator;
50
+
51
+ this.push([attribute_name, message_key, options]);
52
+ this.messages[attribute_name] = '';
53
+ translator = messages[message_key];
54
+ if (translator != null) {
55
+ return this.messages[attribute_name] += translator.call(this.model, attribute_name, options);
56
+ } else {
57
+ return this.messages[attribute_name] += message_key;
58
+ }
59
+ },
60
+ clear: function() {
61
+ var attribute_name, _results;
62
+
63
+ if (this.length) {
64
+ this.length = 0;
113
65
  _results = [];
114
- for (name in _ref) {
115
- validator = _ref[name];
116
- definition = definitions[validator.definition_key];
117
- if (definition) {
118
- if (type(definition) !== 'array') definition = [definition];
119
- _results.push((function() {
120
- var _i, _len, _results2;
121
- _results2 = [];
122
- for (_i = 0, _len = definition.length; _i < _len; _i++) {
123
- validator_options = definition[_i];
124
- if (type(validator_options) !== 'object') {
125
- validator_options = {
126
- attribute_name: validator_options
127
- };
128
- }
129
- validator_options.model = this;
130
- this.validators.push(validator(validator_options));
131
- _results2.push(delete definitions[validator.definition_key]);
132
- }
133
- return _results2;
134
- }).call(this));
135
- } else {
136
- _results.push(void 0);
137
- }
66
+ for (attribute_name in this.messages) {
67
+ _results.push(this.messages[attribute_name] = null);
138
68
  }
139
69
  return _results;
140
70
  }
141
- };
142
-
143
- extensions = {
144
- model: {
145
- validators: null
146
- },
147
- record: {
148
- validate_attribute: function(attribute, doned, failed) {
149
- var results, validation, validator, _i, _len, _ref;
150
- this.errors.messages[attribute] = null;
151
- results = [this, attribute];
152
- _ref = model[this.resource.toString()].validators;
153
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
154
- validator = _ref[_i];
155
- if (validator.attribute_name === attribute) {
156
- results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));
157
- }
71
+ },
72
+ push: Array.prototype.push,
73
+ splice: Array.prototype.splice,
74
+ indexOf: Array.prototype.indexOf
75
+ }, {
76
+ model: null,
77
+ messages: null,
78
+ length: 0
79
+ }, function() {
80
+ this.messages = {};
81
+ return this;
82
+ });
83
+
84
+ initializers = {
85
+ define_triggers: function() {
86
+ this.errors = errorsable({
87
+ model: model[this.resource]
88
+ });
89
+ this.before('save', function() {
90
+ if (this.save) {
91
+ return this.validate();
92
+ }
93
+ });
94
+ this.validated = false;
95
+ this.subscribe('dirty', function(value) {
96
+ return value && (this.validated = false);
97
+ });
98
+ return Object.defineProperty(this, 'valid', {
99
+ get: function() {
100
+ this.validate();
101
+ if (this.validation.state() === 'resolved') {
102
+ return !this.errors.length;
103
+ } else {
104
+ return null;
158
105
  }
159
- validation = jQuery.when.apply(jQuery, results);
160
- validation.done(doned);
161
- validation.fail(failed);
162
- return validation;
163
106
  },
164
- validate: function(doned, failed) {
165
- var results, validator, _i, _len, _ref;
166
- if (this.validated && !this.dirty) return this.validation;
167
- this.errors.clear();
168
- results = [this];
169
- _ref = model[this.resource.toString()].validators;
170
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
171
- validator = _ref[_i];
172
- results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));
107
+ set: function() {
108
+ throw new TypeError("You can't set the value for the valid property.");
109
+ },
110
+ enumerable: false
111
+ });
112
+ },
113
+ create_validators: function(definitions) {
114
+ var definition, name, validator, validator_options, _ref, _results;
115
+
116
+ this.validators = [];
117
+ _ref = manager.validators;
118
+ _results = [];
119
+ for (name in _ref) {
120
+ validator = _ref[name];
121
+ definition = definitions[validator.definition_key];
122
+ if (definition) {
123
+ if (type(definition) !== 'array') {
124
+ definition = [definition];
173
125
  }
174
- this.validation = jQuery.when.apply(jQuery, results);
175
- this.validation.done(doned);
176
- this.validation.fail(failed);
177
- return this.validation.then(function(record) {
178
- var old_dirty;
179
- old_dirty = record.dirty;
180
- record.dirty = null;
181
- record.validated || (record.validated = true);
182
- return record.dirty = old_dirty;
183
- });
126
+ _results.push((function() {
127
+ var _i, _len, _results1;
128
+
129
+ _results1 = [];
130
+ for (_i = 0, _len = definition.length; _i < _len; _i++) {
131
+ validator_options = definition[_i];
132
+ if (type(validator_options) !== 'object') {
133
+ validator_options = {
134
+ attribute_name: validator_options
135
+ };
136
+ }
137
+ validator_options.model = this;
138
+ this.validators.push(validator(validator_options));
139
+ _results1.push(delete definitions[validator.definition_key]);
140
+ }
141
+ return _results1;
142
+ }).call(this));
143
+ } else {
144
+ _results.push(void 0);
184
145
  }
185
146
  }
186
- };
147
+ return _results;
148
+ }
149
+ };
150
+
151
+ extensions = {
152
+ model: {
153
+ validators: null
154
+ },
155
+ record: {
156
+ validate_attribute: function(attribute, doned, failed) {
157
+ var results, validation, validator, _i, _len, _ref;
158
+
159
+ this.errors.messages[attribute] = null;
160
+ results = [this, attribute];
161
+ _ref = model[this.resource.toString()].validators;
162
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
163
+ validator = _ref[_i];
164
+ if (validator.attribute_name === attribute) {
165
+ results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));
166
+ }
167
+ }
168
+ validation = jQuery.when.apply(jQuery, results);
169
+ validation.done(doned);
170
+ validation.fail(failed);
171
+ return validation;
172
+ },
173
+ validate: function(doned, failed) {
174
+ var results, validator, _i, _len, _ref;
187
175
 
188
- manager = {
189
- validators: {}
190
- };
176
+ if (this.validated && !this.dirty) {
177
+ return this.validation;
178
+ }
179
+ this.errors.clear();
180
+ results = [this];
181
+ _ref = model[this.resource.toString()].validators;
182
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
183
+ validator = _ref[_i];
184
+ results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));
185
+ }
186
+ this.validation = jQuery.when.apply(jQuery, results);
187
+ this.validation.done(doned);
188
+ this.validation.fail(failed);
189
+ return this.validation.done(function(record) {
190
+ var old_dirty;
191
+
192
+ old_dirty = record.dirty;
193
+ record.dirty = null;
194
+ record.validated || (record.validated = true);
195
+ record.dirty = old_dirty;
196
+ return record;
197
+ });
198
+ }
199
+ }
200
+ };
191
201
 
192
- model.mix(function(modelable) {
193
- jQuery.extend(modelable, extensions.model);
194
- jQuery.extend(modelable.record, extensions.record);
195
- modelable.after_mix.unshift(initializers.create_validators);
196
- modelable.record.after_initialize.push(initializers.define_triggers);
197
- return model.validators = manager.validators;
198
- });
202
+ manager = {
203
+ validators: {}
204
+ };
199
205
 
200
- manager.validators.confirmation = require('./validations/confirmation');
206
+ model.mix(function(modelable) {
207
+ jQuery.extend(modelable, extensions.model);
208
+ jQuery.extend(modelable.record, extensions.record);
209
+ modelable.after_mix.unshift(initializers.create_validators);
210
+ modelable.record.after_initialize.push(initializers.define_triggers);
211
+ return model.validators = manager.validators;
212
+ });
201
213
 
202
- manager.validators.associated = require('./validations/associated');
214
+ manager.validators.confirmation = require('./validations/confirmation');
203
215
 
204
- manager.validators.presence = require('./validations/presence');
216
+ manager.validators.associated = require('./validations/associated');
205
217
 
206
- manager.validators.remote = require('./validations/remote');
218
+ manager.validators.presence = require('./validations/presence');
207
219
 
208
- manager.validators.type = require('./validations/type');
220
+ manager.validators.remote = require('./validations/remote');
209
221
 
210
- manager.validators.cpf = require('./validations/cpf');
222
+ manager.validators.type = require('./validations/type');
211
223
 
212
- }).call(this);
224
+ manager.validators.cpf = require('./validations/cpf');
@@ -173,7 +173,7 @@ extensions =
173
173
  @validation.fail failed
174
174
 
175
175
  # TODO store this callback
176
- @validation.then (record) ->
176
+ @validation.done (record) ->
177
177
  # Disable dirty checking to prevent validation believe that
178
178
  # the model values has changed
179
179
  old_dirty = record.dirty
@@ -184,6 +184,8 @@ extensions =
184
184
  # Restore dirty state
185
185
  record.dirty = old_dirty
186
186
 
187
+ record
188
+
187
189
 
188
190
  # Validators management
189
191
  manager =
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ende
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heitor Salazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-03 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -389,7 +389,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
389
389
  version: '0'
390
390
  requirements: []
391
391
  rubyforge_project:
392
- rubygems_version: 2.1.11
392
+ rubygems_version: 2.0.3
393
393
  signing_key:
394
394
  specification_version: 4
395
395
  summary: Endë (core, middle) a web application engine for rails with aurajs.