Skip to content

Commit

Permalink
validation: remove unneeded comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Aug 31, 2014
1 parent 8e99082 commit 2434b07
Showing 1 changed file with 2 additions and 55 deletions.
57 changes: 2 additions & 55 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,27 @@ var assert = require('assert');

module.exports.validate = function(record) {

// Check if the input is correct.

assert('object' == typeof record, 'Record should be an object');

// Create a new object to hold our return value.

var result = {};

// Go over all the properties on our model
// and check they match the properties
// of our record.

Object.keys(this._schema).forEach(function(key) {

// Create variables we can re-use
// throughout our function.

var modelProp = this._schema[key];
var recordProp = record[key];

// Assert our values are what we think
// they are.

assert(recordProp, 'Property should exist on the record');
assert(modelProp, 'Property should exist on the model');

// If a property on our model doesn't
// demand a type, check if the value
// exists to determine if it's valid
// or not.

if (!modelProp.type) {
return result[key] = recordProp == undefined ? undefined : true;
if (!modelProp.type) { return result[key] = recordProp == undefined ?
undefined : true;
}

// Now that we've established our property
// does exist on the model, check if the
// value is undefined.

if (undefined === typeof recordProp) return result[key] = undefined;

// Since the value of our property isn't
// undefined, check if it's the same as
// defined on the model.

if (modelProp.type != typeof recordProp) return result[key] = false;
result[key] = true;

}.bind(this));

// Broadcast our results
// to the people.

this.emit('validated', result);
}

Expand All @@ -83,40 +51,19 @@ module.exports.validate = function(record) {

module.exports.allAccountedFor = function(record) {

// Check if the input is correct.

assert('object' == typeof record, 'Record should be an object');

// Go over every property on the model
// and check if the value is present
// in the record we just submitted.

var value = Object.keys(this._schema).every(function(key) {

// Create variables we can re-use
// throughout our function.

var modelProp = this._schema[key];
var recordProp = record[key];

// Check if our model demands the
// value to be present.

if (!modelProp) return true;
if (!modelProp.required) return true;

// Apparently our model demands
// the record to be present. So let's
// check if the value is actually
// present.

if (recordProp) return true;
return false;

}.bind(this));

// Broadcast our results
// to the people.

this.emit('allAccountedFor', value);
};

0 comments on commit 2434b07

Please sign in to comment.