Skip to content

Commit

Permalink
Remove passesOptionalCheck, use generic hasRule helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
garygreen committed Sep 19, 2016
1 parent 61cee9a commit 235e810
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Validator.prototype = {
var attributeRules = this.rules[attribute];
var inputValue = this._objectPath(this.input, attribute);

if (this._passesOptionalCheck(attributeRules) && !(this._suppliedWithData(attribute))) {
if (this._hasRule(attribute, ['sometimes']) && !this._suppliedWithData(attribute)) {
continue;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ Validator.prototype = {
var attributeRules = this.rules[attribute];
var inputValue = this._objectPath(this.input, attribute);

if (this._passesOptionalCheck(attributeRules) && !(this._suppliedWithData(attribute))) {
if (this._hasRule(attribute, ['sometimes']) && !this._suppliedWithData(attribute)) {
continue;
}

Expand Down Expand Up @@ -245,22 +245,6 @@ Validator.prototype = {
return parsedRules;
},

/**
* Determines if the input value being validated is optional or not.
*
* @param {array} attributeRules
* @return {boolean}
*/
_passesOptionalCheck: function(attributeRules) {
for(var i = 0; i < attributeRules.length; i++) {
if (attributeRules[i].name === 'sometimes') {
return true;
}
}

return false;
},

/**
* Determines if the attribute is supplied with the original data object.
*
Expand Down

0 comments on commit 235e810

Please sign in to comment.