Skip to content

Commit

Permalink
Changes instance.save() to support an hash of changes before saving (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Apr 10, 2013
1 parent 84645c8 commit 9a74103
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,26 @@ function Instance(opts) {
enumerable: false
});
Object.defineProperty(instance, "save", {
value: function (cb) {
saveInstance(cb);
value: function () {
if (arguments.length === 0) {
saveInstance();
} else {
switch (typeof arguments[0]) {
case "object":
for (var k in arguments[0]) {
if (arguments[0].hasOwnProperty(k)) {
this[k] = arguments[0][k];
}
}
saveInstance(arguments[1]);
break;
case "function":
saveInstance(arguments[0]);
break;
default:
throw new Error("Unknown parameter type '" + (typeof arguments[0]) + "' in Instance.save()");
}
}

return this;
},
Expand Down

0 comments on commit 9a74103

Please sign in to comment.