Permalink
Browse files

Added a new attribute called ‘patternProperties’

  • Loading branch information...
1 parent 9d573be commit 598afd2e71b76eac8491cab82f57fd5c6432de83 @Baggz committed Mar 14, 2012
Showing with 47 additions and 0 deletions.
  1. +47 −0 src/engines/json/attributes/patternProperties.js
@@ -0,0 +1,47 @@
+(function() {
+
+ /**
+ * PatternProperties
+ */
+ var attribute = function patternProperties(property, propertyValue, attributeValue, propertyAttributes, callback) {
+
+ // Saves a reference to ‘this’
+ var self = this;
+
+ // Skip
+ if (isEmpty(attributeValue)) {
+ return callback();
+ }
+
+ var matches = {};
+ var patterns = keys(attributeValue);
+
+ each(propertyValue, function(key, value) {
+
+ each(patterns, function(index, pattern) {
+ if (key.match(new RegExp(pattern))) {
+ matches[key] = attributeValue[pattern];
+ }
+ });
+
+ });
+
+ if (isEmpty(matches)) {
+ return callback();
+ }
+
+ each(matches, function(propertyName, propertySchema, callback) {
+ return self.validateSchema(
+ propertyValue[propertyName],
+ propertySchema,
+ property + '.' + propertyName, // Fix Me!
+ callback
+ );
+ }, callback);
+
+ };
+
+ // Export
+ Validation.prototype.addAttribute('patternProperties', attribute);
+
+}());

0 comments on commit 598afd2

Please sign in to comment.