Skip to content

Commit

Permalink
Updated Iridium DB constructor for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jul 29, 2014
1 parent eebe77a commit a95caa1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ var _ = require('lodash');

(require.modules || {}).Database = module.exports = Database;

function Database(config) {
function Database(uri, config) {
/// <summary>Creates a new Iridium instance</summary>
/// <param name="config" type="Object">A configuration object describing the details of the database to connect to</param>
/// <param name="uri" type="String" optional="true">A MongoDB URI which can be used to connect to the database</param>
/// <param name="config" type="Object" optional="true">A configuration object describing the details of the database to connect to</param>

"use strict";

Expand All @@ -16,15 +17,27 @@ function Database(config) {
this.connection = null;
this.models = {};
this.plugins = [];

var args = Array.prototype.slice.call(arguments, 0);
uri = config = null;
for(var i = 0; i < args.length; i++) {
if(typeof args[i] == 'string')
uri = args[i];
else if(typeof args[i] == 'object')
config = args[i];
}

if(!uri && !config) throw new Error("Expected either a URI or config object to be supplied when initializing Iridium");

if(typeof config == 'string') {
if(uri) {
Object.defineProperty(this, 'uri', {
get: function () {
return config;
},
enumerable: false
});
} else {
}
if(config) {
Object.defineProperty(this, 'settings', {
get: function () {
return config;
Expand Down

0 comments on commit a95caa1

Please sign in to comment.