Sha256: 140d4926e70c19e93dd068178b1a7f9c423df5289703514cff8339bc1653aabe

Contents?: true

Size: 954 Bytes

Versions: 30

Compression:

Stored size: 954 Bytes

Contents

# TODO Add base settings to validation
# model = window.model

# TODO implement method
# model[resource].validators_on 'field' # Get all validators related to this field

validations = require '../validatable'
stampit     = require '../../../vendor/stampit'

typeable = stampit
  validate_each: (record, attribute, value) ->
    # TODO store type on validator instantiation
    @type ||= model[record.resource.toString()][attribute]

    if value

      if value instanceof @type

        # TODO store type_name on costructor
        @type_name ||= @type.name

        unless value.valid # Will trigger validation
          record.errors.add attribute, 'type', type_name: @type_name?

      else
        throw new Error "Invalid attribute value type! Found #{typeof value} expected #{@type.name}"


composed = stampit.compose(validations.validatable, typeable)
composed.definition_key = 'validates_type_of'

validations.manager.validators.type = composed

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
ende-0.3.13 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.12 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.11 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.10 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.9 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.8 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.7 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.6 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.5 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.4 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.3 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.2 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.1 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.3.0 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.2.21 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.2.20 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.2.19 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.2.18 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.2.17 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.2.16 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee