Files
deployd/lib/plugins/apps/app.js
Ritchie Martori e8241902f3 settings key fixes
2011-11-26 23:57:00 -08:00

58 lines
1.2 KiB
JavaScript

var Model = require('../../model');
module.exports = Model.spawn({
collection: 'apps',
plugin: 'apps',
description: {
name: {type: 'string', unique: true},
creator: 'string',
db: 'string',
host: 'string'
},
allowed: {
read: 'creator',
write: 'creator',
remove: 'creator',
create: 'user'
},
save: function() {
var name = this.get('name')
, host = this.toHostName()
, creator = this.get('creator')
;
if(!creator) this.error('Must be logged in to create an app.', 'App');
if(host && creator) {
if(this.isNew()) {
this.set({name: name, host: host, db: this.toDatabaseName(), creator: creator});
} else {
this.restart(host);
}
}
Model.save.apply(this, arguments);
},
toHostName: function() {
var name = this.get('name')
, app = name && name.replace(/ /g, '-')
, creator = this.get('creator')
;
return app.toLowerCase();
},
defineRoutes: function() {
// TODO move routes here
},
toDatabaseName: function() {
return this.toHostName().replace(/\./g, ':').toLowerCase();
}
});