Permalink
Browse files

Minor improvements to the ‘Validation’ constructor

  • Loading branch information...
1 parent 37895bd commit 3d2f09dd202c9f7fb4eff4a1248f6b81ae61b3ad @Baggz committed Mar 12, 2012
Showing with 20 additions and 6 deletions.
  1. +20 −6 src/engines/json/validation.js
@@ -9,12 +9,26 @@ var Validation = function(options) {
// Save a reference to the ‘this’
var self = this;
- // Options
- this.singleError = options.hasOwnProperty('singleError') ? options.singleError : true;
- this.attributes = attributes;
- this.messages = (options.messages) ? merge(options.messages, messages) : messages;
+ var defaultOptions = {
+ singleError: true,
+ errorMessages: errorMessages,
+ cache: false
+ };
- // Initializes a new instance of the ‘Error’ object
- this.Errors = new AmandaError();
+ each(defaultOptions, function(key, value) {
+
+ if (isObject(value) && options[key]) {
+ self[key] = merge(options[key], defaultOptions[key]);
+
+ } else if (isObject(value) && !options[key]) {
+ self[key] = merge ({}, defaultOptions[key]);
+
+ } else {
+ self[key] = options[key] || defaultOptions[key];
+ }
+
+ });
+
+ this.errors = new ValidationError();
};

0 comments on commit 3d2f09d

Please sign in to comment.