Skip to content

Instantly share code, notes, and snippets.

@ritch
Created June 15, 2011 23:57
Show Gist options
  • Save ritch/1028427 to your computer and use it in GitHub Desktop.
Save ritch/1028427 to your computer and use it in GitHub Desktop.
var hive = require('hive');
exports = module.exports = hive.Model.extend({
_name: 'user',
activity: [],
following: [],
did: function(method, action, type, id) {
var activity = {type: type, at: new Date().getTime(), id: id};
activity[method] = action;
this.push({activity: activity});
},
follow: function(user) {
this.push({following: user})
},
validate: function() {
var assert = this.assert;
return this.describe({
'email': {
'you must enter a valid email address': function(email) {
assert.exists(email.match(/(.+)@(\w+)(\.\w+)*\.(\w{2,6})/));
}
},
'password': {
'you must enter a password': function(password) {
assert.exists(password);
},
'a password must be atleast 4 characters': function(password) {
if(password) {
assert.true(password.length >= 4);
}
}
},
'name': {
'a name is required': function(name) {
assert.exists(name);
},
'a name can only be 256 chars in length': function(name) {
assert.true(name.length < 256);
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment