Show:
buildValidations
(
  • validations
)
Ember.Mixin

Top level method that will ultimately return a mixin with all CP validations

Parameters:

  • validations Object

    Validation rules

Returns:

createAttrsClass
(
  • validatableAttributes
  • validationRules
  • model
)
Ember.Object
private

Creates the attrs class which holds all the CP logic

model.get('validations.attrs.username');
  model.get('validations.attrs.nested.object.attribute');
  

Parameters:

Returns:

createCPValidationFor
(
  • attribute
  • model
  • validations
)
Ember.ComputedProperty
private

CP generator for the given attribute

Parameters:

  • attribute String
  • model Object

    Since the CPs are created once per class on the first initialization, this is the first model that was instantiated

  • validations Array

Returns:

Ember.ComputedProperty:

A computed property which is a ResultCollection

createTopLevelPropsMixin
(
  • validations
)
private

Create a mixin that will have all the top level CPs under the validations object. These are computed collections on different properties of each attribute validations CP

Parameters:

createValidationsClass
(
  • inheritedValidationsClass
  • validations
  • model
)
Ember.Object
private

Creates the validations class that will become model.validations.

  • Setup parent validation inheritance
  • Normalize nested keys (i.e. 'details.dob') into objects (i.e { details: { dob: validator() }})
  • Merge normalized validations with parent
  • Create global CPs (i.e. 'isValid', 'messages', etc...)

Parameters:

Returns:

createValidatorsFor
(
  • attribute
  • model
)
Array
private

Create validators for the give attribute and store them in a cache

Parameters:

Returns:

extractOptionsDependentKeys
(
  • options
)
Array
private

Extract all dependentKeys from any property that is a CP

Parameters:

Returns:

Array:

dependentKeys

generateValidationResultsFor
(
  • attribute
  • model
  • validators
  • validate
  • opts
)
Array
private

Generates the validation results for a given attribute and validators. If a given validator should be validated, it calls upon the validate callback to retrieve the result.

Parameters:

Returns:

getCPDependentKeysFor
(
  • attribute
  • model
  • validations
)
Array
private

CP dependency generator for a give attribute depending on its relationships

Parameters:

  • attribute String
  • model Object

    Since the CPs are created once per class on the first initialization, this is the first model that was instantiated

  • validations Array

Returns:

Array:

Unique list of dependencies

getValidatorCacheFor
(
  • attribute
  • model
)
Map
private

Get debounced validation cache for the given attribute. If it doesn't exist, create a new one.

Parameters:

Returns:

Map
getValidatorsFor
(
  • attribute
  • model
)
Array
private

Get validators for the give attribute. If they are not in the cache, then create them.

Parameters:

Returns:

hasOption
(
  • validations
  • option
  • value=true
)
Boolean
private

Check if a collection of validations have an option equal to the given value

Parameters:

Returns:

normalizeOptions
(
  • validations
)
private

Validation rules can be created with default and global options { description: 'Username', validators: [...] }

This method generate the default options pojo, applies it to each validation rule, and flattens the object

Parameters:

Returns:

resolveDebounce
(
  • resolve
)
private

Call the passed resolve method. This is needed as run.debounce expects a static method to work properly.

Parameters:

validate
(
  • options
  • isAsync
)
Promise or Object
model.validate({ on: ['username', 'email'] }).then(({ m, validations }) => {
    validations.get('isValid'); // true or false
    validations.get('isValidating'); // false
  
    let usernameValidations = m.get('validations.attrs.username');
    usernameValidations.get('isValid') // true or false
  });
  

Parameters:

  • options Object
    • on Array

      Only validate the given attributes. If empty, will validate over all validatable attribute

    • excludes Array

      Exclude validation on the given attributes

  • isAsync Boolean

    If false, will get all validations and will error if an async validations is found. If true, will get all validations and wrap them in a promise hash

Returns:

Promise or Object:

Promise if isAsync is true, object if isAsync is false

validateAttribute
(
  • attribute
  • value
)
Promise
async

A functional approach to check if a given attribute on a model is valid independently of the model attribute's validations. This method will always return a promise which will then resolve to a ResultCollection.

model.validateAttribute('username', 'offirgolan').then(({ m, validations }) => {
    validations.get('isValid'); // true or false
    validations.get('isValidating'); // false
  });
  

Parameters:

  • attribute String
  • value Mixed

Returns:

validateSync
(
  • options
)
Object
let { m, validations } = model.validateSync();
  validations.get('isValid') // true or false
  

Parameters:

  • options Object
    • on Array

      Only validate the given attributes. If empty, will validate over all validatable attribute

    • excludes Array

      Exclude validation on the given attributes

Returns:

validationReturnValueHandler
(
  • attribute
  • value
  • model
)
ValidationResult
private

A handler used to create ValidationResult object from values returned from a validator

Parameters:

Returns:

ValidationResult