Skip to content

Commit

Permalink
So the demo server can handle dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
makara committed Nov 8, 2012
1 parent 361b816 commit 52bbdc4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions servers/Resource.bones.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
// A demo server with only a set of helpers.
server = Bones.Server.extend({
mount: function(name) {
initialize: function(app) {
this.mounted = {};
},
mount: function(name, route) {
if (this.plugin.resources && this.plugin.resources[name]) {
var resource = new this.plugin.resources[name]();
resource.mountTo(this);
route || (route = '/');
// Don't mount a same resource to a same route twice or more.
this.mounted[route] || (this.mounted[route] = {});
if (!this.mounted[route][name]) {
var resource = new this.plugin.resources[name]();
// Handle dependencies.
_(resource.dependencies || null).each(function(name, route) {
this.mount(name, route);
}, this);
this.mounted[route][name] = true;
resource.mountTo(this, route);
}
}
return this;
},
mountAll: function() {
_(this.plugin.resources || null).each(function(Res) {
var resource = new Res();
resource.mountTo(this);
_(this.plugin.resources || null).each(function(Res, name) {
this.mount(name);
}, this);
return this;
}
Expand Down

0 comments on commit 52bbdc4

Please sign in to comment.