-
-
Save Marak/1598f9392360f9139770 to your computer and use it in GitHub Desktop.
resourceful-functions-pre.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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