Sha256: 52a08182b277dc147bbc0ce83ef9c6afe976d48f0f488848df161aa0d3badb98

Contents?: true

Size: 934 Bytes

Versions: 30

Compression:

Stored size: 934 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 require('./validatorable'), typeable
composed.definition_key = 'validates_type_of'
module.exports = composed

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
ende-0.5.22 components/indefinido/indemma/master/src/lib/record/validations/type.coffee
ende-0.5.21 components/indefinido/indemma/master/src/lib/record/validations/type.coffee
ende-0.4.25 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.24 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.23 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.5.1 components/indefinido/indemma/master/src/lib/record/validations/type.coffee
ende-0.4.22 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.21 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.5.0 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.20 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.19 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.18 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.17 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.16 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.15 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.14 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.13 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.12 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.11 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee
ende-0.4.10 vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee