Sha256: 57ecef05ba7c508220f0a1d42651ecef0c7966fe290ea54f2e391418692ce00c

Contents?: true

Size: 1.56 KB

Versions: 14

Compression:

Stored size: 1.56 KB

Contents

o_O.validations = {
  run: function(object){
    this.run_custom_validations(object);
    this.run_length_validations(object);
    this.run_presence_validations(object);
  },
  run_custom_validations: function(object){
    for(var i = 0; i < object.validations.custom.length; i++)
    {
      object.validations.custom[i](object);
    }
  },
  run_length_validations: function(object){
    for(var i = 0; i < object.validations.lengthliness.length; i++)
    {
      var field = object.validations.lengthliness[i].field;
      var max = object.validations.lengthliness[i].max
      var min = object.validations.lengthliness[i].min
      if(object[field])
      {
        if(max && object[field].length > max)
        {
          var message = field.capitalize() + ' should be less than ' + max + ' characters';
          object.errors.push({field: field, type: 'length', message: message});
        }
        if(min && object[field].length < min)
        {
          var message = field.capitalize() + ' should be greater than ' + min + ' characters';
          object.errors.push({field: field, type: 'length', message: message});
        }
      }
    }
  },
  run_presence_validations: function(object){
    for(var i = 0; i < object.validations.presence.length; i++)
    {
      var field = object.validations.presence[i].field;
      if(object[field] == null || (typeof object[field] === 'string' && object[field].blank()) )
      {
        var message = field.capitalize() + ' should be present';
        object.errors.push({field: field, type: 'presence', message: message})
      }
    }
  }
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
eyeballs-0.5.8.2 src/modules/o_O.validations.js
eyeballs-0.5.8.1 src/modules/o_O.validations.js
eyeballs-0.5.8 src/modules/o_O.validations.js
eyeballs-0.5.7.2 src/modules/o_O.validations.js
eyeballs-0.5.7.1 src/modules/o_O.validations.js
eyeballs-0.5.7 src/modules/o_O.validations.js
eyeballs-0.5.6.1 src/modules/o_O.validations.js
eyeballs-0.5.6 src/modules/o_O.validations.js
eyeballs-0.5.5 src/modules/o_O.validations.js
eyeballs-0.5.4 src/modules/o_O.validations.js
eyeballs-0.5.3 src/modules/o_O.validations.js
eyeballs-0.5.2 src/modules/o_O.validations.js
eyeballs-0.5.1 src/modules/o_O.validations.js
eyeballs-0.5.0 src/modules/o_O.validations.js