mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-08 04:03:12 +03:00
983110d931
no issue - add eslint-plugin-ember, configure no-old-shims rule - run `eslint --fix` on `app`, `lib`, `mirage`, and `tests` to move imports to the new module imports - further cleanup of Ember globals usage - remove event-dispatcher initializer now that `canDispatchToEventManager` is deprecated
38 lines
1.0 KiB
JavaScript
38 lines
1.0 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({
|
|
properties: [],
|
|
passed: false,
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
});
|