Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 837c6ca8768c54bfa6176eb1d8f490359b798e2f 1 parent 2670180
@Marak Marak authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/resourceful/resource.js
View
12 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,7 +740,7 @@ 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 {
@@ -745,11 +748,13 @@ Resource.method = function (name, fn, schema) {
}
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;
};
Please sign in to comment.
Something went wrong with that request. Please try again.