How to use the ember-cp-validations/utils/lookup-validator function in ember-cp-validations

To help you get started, we’ve selected a few ember-cp-validations examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github offirgolan / ember-cp-validations / addon / validators / base.js View on Github external
test(type, ...args) {
    const cache = this.get('_testValidatorCache');
    const unsupportedTypes = ['alias', 'belongs-to', 'dependent', 'has-many'];

    if (unsupportedTypes.includes(type)) {
      throw new Error(
        `[ember-cp-validations] The \`test\` API does not support validators of type: ${type}.`
      );
    }

    cache[type] = cache[type] || lookupValidator(getOwner(this), type).create();
    const result = cache[type].validate(...args);

    if (isPromise(result)) {
      return result.then(r => new TestResult(r), r => new TestResult(r));
    }

    return new TestResult(result);
  }
});