mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
f25624234f
no issue - https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/avoid-leaking-state-in-ember-objects.md
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import EmberObject from '@ember/object';
|
|
|
|
/**
|
|
* Base validator that all validators should extend
|
|
* Handles checking of individual properties or the entire model
|
|
*/
|
|
export default EmberObject.extend({
|
|
passed: false,
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
this.properties = this.properties || [];
|
|
},
|
|
|
|
/**
|
|
* When passed a model and (optionally) a property name,
|
|
* checks it against a list of validation functions
|
|
* @param {Ember.Object} model Model to validate
|
|
* @param {string} prop Property name to check
|
|
* @return {boolean} True if the model passed all (or one) validation(s),
|
|
* false if not
|
|
*/
|
|
check(model, prop) {
|
|
this.set('passed', true);
|
|
|
|
if (prop && this[prop]) {
|
|
this[prop](model);
|
|
} else {
|
|
this.get('properties').forEach((property) => {
|
|
if (this[property]) {
|
|
this[property](model);
|
|
}
|
|
});
|
|
}
|
|
return this.get('passed');
|
|
},
|
|
|
|
invalidate() {
|
|
this.set('passed', false);
|
|
}
|
|
});
|