Skip to content

Commit

Permalink
added serialize function
Browse files Browse the repository at this point in the history
  • Loading branch information
gushov committed Feb 5, 2013
1 parent ed354f7 commit 6e0fa6e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -78,6 +78,8 @@ dunkel.save(function (err) {

### _model_.destroy(callback, context)

### _model_.serialize()

### collection.extend(config)

### collection.create(propertiesList)
Expand All @@ -92,6 +94,8 @@ dunkel.save(function (err) {

### _collection_.find(query, callback, context)

### _collection_.serialize()

## License
Copyright (c) 2012 August Hovland
Licensed under the MIT license.
24 changes: 23 additions & 1 deletion dist/lilmodel.js
@@ -1,4 +1,4 @@
/*! lilmodel - v0.0.9 - 2013-01-25
/*! lilmodel - v0.0.10 - 2013-02-05
* Copyright (c) 2013 August Hovland <gushov@gmail.com>; Licensed MIT */

(function (ctx) {
Expand Down Expand Up @@ -589,6 +589,14 @@ module.exports = arr.extend({
this.query = query;
sync('find', this, parser(ctx, this, next));

},

serialize: function () {

return _.map(this, function (elem) {
return elem.serialize();
});

}

});
Expand Down Expand Up @@ -714,6 +722,20 @@ module.exports = obj.extend({
var sync = syncr();
sync('destroy', this, parser(ctx, this, next));

},

serialize: function () {

return _.map(this.$, function (name, value) {

if (this.children && this.children[name]) {
return value.serialize();
} else {
return value;
}

}, this);

}

});
Expand Down
4 changes: 2 additions & 2 deletions dist/lilmodel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/lilmodel/collection.js
Expand Up @@ -89,6 +89,14 @@ module.exports = arr.extend({
this.query = query;
sync('find', this, parser(ctx, this, next));

},

serialize: function () {

return _.map(this, function (elem) {
return elem.serialize();
});

}

});
14 changes: 14 additions & 0 deletions lib/lilmodel/model.js
Expand Up @@ -115,6 +115,20 @@ module.exports = obj.extend({
var sync = syncr();
sync('destroy', this, parser(ctx, this, next));

},

serialize: function () {

return _.map(this.$, function (name, value) {

if (this.children && this.children[name]) {
return value.serialize();
} else {
return value;
}

}, this);

}

});
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "August Hovland <gushov@gmail.com>",
"name": "lilmodel",
"description": "A li'l model wrapper",
"version": "0.0.10",
"version": "0.0.11",
"repository": {
"type": "git",
"url": "git://github.com/gushov/lilmodel.git"
Expand Down
13 changes: 13 additions & 0 deletions test/lilmodel-test.js
Expand Up @@ -62,8 +62,21 @@ buster.testCase("lilmodel", {
var results = chef.recipes.get({ name: 'tacos' });
chef.recipes.remove({ name: 'meatball sauce' });

var serialized = chef.serialize();
assert.equals(chef.name, 'gus');
assert.equals(chef.sousChef.name, 'zoe');
assert.equals(serialized, {
name: 'gus',
style: 'classic',
sousChef: {
name: 'zoe',
style: 'classic'
},
recipes: [
{ name: 'tacos' },
{ name: 'eggs' }
]
});

chef.name = 'august';
chef.sousChef = { name: 'zozo' };
Expand Down

0 comments on commit 6e0fa6e

Please sign in to comment.