Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Exposed schema on Model, fixed constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
pluma committed Jan 21, 2014
1 parent 86455c3 commit f581ef4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions index.js
@@ -1,4 +1,4 @@
/*! revalidator-model 0.2.3 Original author Alan Plum <me@pluma.io>. Released into the Public Domain under the UNLICENSE. @preserve */
/*! revalidator-model 0.2.4 Original author Alan Plum <me@pluma.io>. Released into the Public Domain under the UNLICENSE. @preserve */
var revalidator = require('revalidator'),
filterObj = require('object-filter'),
transform = require('transform-object'),
Expand All @@ -14,7 +14,7 @@ function model(schema) {
if (!Model.prototype.isPrototypeOf(self)) {
return new Model(data);
}
self.data = aug({}, schema.defaults, filterObj(data || {}, function(v, k) {
self.data = aug({}, self.schema.defaults, filterObj(data || {}, function(v, k) {
if (self.schema.properties && k in self.schema.properties) {
return true;
}
Expand All @@ -29,15 +29,16 @@ function model(schema) {
}

Model.prototype = Object.create(schema.proto || Object.prototype);
Model.prototype.schema = schema;
Model.prototype.constructor = Model;
Model.prototype.schema = Model.schema = schema;
Model.prototype.validate = function() {
return revalidator.validate(this.data, this.schema);
};
Model.prototype.dehydrate = function() {
return transform(this.data, this.schema.dehydrate);
};
Model.hydrate = function(data) {
return new Model(transform(data || {}, Model.prototype.schema.hydrate));
return new Model(transform(data || {}, Model.schema.hydrate));
};

return Model;
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "revalidator-model",
"version": "0.2.3",
"version": "0.2.4",
"author": "Alan Plum <me@pluma.io>",
"description": "Simple validatable models with revalidator.",
"licenses": {
Expand Down

0 comments on commit f581ef4

Please sign in to comment.