Skip to content

Instantly share code, notes, and snippets.

@Marak
Created September 3, 2012 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marak/1598f9392360f9139770 to your computer and use it in GitHub Desktop.
Save Marak/1598f9392360f9139770 to your computer and use it in GitHub Desktop.
resourceful-functions-pre.js
var resourceful = require('../lib/resourceful');
resourceful.use('memory');
var Creature = resourceful.define('creature');
var lazer = function(options){
console.log('firing mah lazar @ ' + options.powa);
};
Creature.method('fire', lazer, { properties: {
"powa": {
"type": "string",
"enum": ["high", "low", "med", "SUPA POWA"],
"required": true
}
}});
Creature.fire({ powa: "med"});
Creature.fire({ powa: "TOO HIGH"}, function(err, result){
// errors since TOO HIGH is not in enum
console.log(err, result);
});
// throws validation error
// Creature.fire({ powa: "TOO HIGH"});
Creature.create({
id: 'Marak'
}, function(err, marak){
if(err){
console.log(err.validate)
}
marak.fire({ powa: "med"});
// throws validation error
// marak.fire({ powa: "TOO HIGH"});
marak.fire({ powa: "low"}, function(err, result){
console.log(err, result);
});
marak.fire({ powa: "TOO HIGH"}, function(err, result){
// errors since TOO HIGH is not in enum
console.log(err, result);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment