1 // !code vendor/crayon/lib/crayon.js
  2 // !code vendor/crayon/lib/crayon.js
  3 /**
  4 * @class
  5 * @namespace Holds functionality for validations
  6 * @requires crayon/lib/crayon.js
  7 */
  8 Crayon.Validate = {
  9   /**
 10   * Validate the field value is neither undefined nor null.
 11   */
 12   require : function(doc, field, message){
 13     message = message || "Document must have a " + field;
 14     if(doc[field] === undefined || doc[field] === null){
 15       throw({forbidden : message});
 16     }
 17   },
 18 
 19   /**
 20   * Validate the field value is not changed.
 21   */
 22   unchanged : function(newDoc, oldDoc, field, message){
 23     message = message || "Field cannot be changed: " + field;
 24     if (oldDoc && toJSON(oldDoc[field]) != toJSON(newDoc[field])){
 25       throw({forbidden : message});
 26     }
 27   }
 28 };
 29