Permalink
Browse files

[fix] Curry no-option method calls. Return fn values on sync (no-call…

…back) method calls. Attach resource methods to Resource.methods object for convenience.
  • Loading branch information...
1 parent 2670180 commit 837c6ca8768c54bfa6176eb1d8f490359b798e2f @Marak Marak committed Sep 5, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/resourceful/resource.js
@@ -729,6 +729,9 @@ Resource.method = function (name, fn, schema) {
if (typeof schema === 'object') {
this[name] = function(){
var args = utile.args(arguments);
+ if(args.length === 0) {
+ args[0] = {};
+ }
var valid = validator.validate(args[0], schema);
if(!valid.valid) {
if(typeof args.cb === 'function') {
@@ -737,19 +740,21 @@ Resource.method = function (name, fn, schema) {
throw new Error(JSON.stringify(valid.errors)); // TODO: better errors
}
} else {
- fn.apply(this, arguments);
+ return fn.apply(this, arguments);
}
};
} else {
this[name] = fn;
}
this[name].type = "method";
this[name].schema = schema;
+ if(typeof this.methods === "undefined") {
+ this.methods = {};
+ }
+ this.methods[name] = this[name];
return;
};
-
-
Resource.property = function (name, typeOrSchema, schema) {
var definer = {};
var type = (function () {
@@ -777,7 +782,6 @@ Resource.property = function (name, typeOrSchema, schema) {
this.schema.properties[name].conditions = {};
definer.name = name;
resourceful.mixin(definer, definers.all, definers[schema.type] || {});
-
return definer;
};

0 comments on commit 837c6ca

Please sign in to comment.