From a9617ef5297ab37c7e08cdc23b887f03c8c19073 Mon Sep 17 00:00:00 2001 From: Makis Tracend Date: Fri, 11 Jan 2013 19:25:54 -0800 Subject: [PATCH] #37 Adding update() & remove() methods --- lib/crudr.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/crudr.js b/lib/crudr.js index 2d28d65..c467871 100644 --- a/lib/crudr.js +++ b/lib/crudr.js @@ -105,6 +105,28 @@ CRUDr.prototype = { // include dbs / backends add: function ( options ) { + //console.log( "----- add ------"); + + var db = options.db || false; + var backends = options.backends || false; + // stop if there's no db or backend + if( !db || !backends ) return; + // create new backends + var backends = this.backends( options ); + // extend the existing db object + this.db = _.extend( this.db, backends); + // update routes + //console.log( backends ); + // update sockets + this.sockets.events( backends ); + this.sockets.db = this.db; + + }, + // update an existing backend + update : function( options ){ + + console.log( "----- update ------"); + var db = options.db || false; var backends = options.backends || false; // stop if there's no db or backend @@ -112,6 +134,7 @@ CRUDr.prototype = { // create new backends var backends = this.backends( options ); // extend the existing db object + //console.log( backends ); this.db = _.extend( this.db, backends); // update routes //console.log( backends ); @@ -119,6 +142,28 @@ CRUDr.prototype = { this.sockets.events( backends ); this.sockets.db = this.db; + }, + // remove a backend + remove: function ( options ) { + + //console.log( "----- remove ------"); + + var db = options.db || false; + var backends = options.backends || false; + // stop if there's no db or backend + if( !db || !backends ) return; + // create new backends + var backends = this.backends( options ); + + for( var i in backends ){ + delete this.db[i]; + } + // remove events from sockets + + + //update dbs + this.sockets.db = this.db; + }