mongojs-hooks
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -17,8 +17,9 @@ var mongojs = require("mongojs"); | ||
//Tenancy helper | ||
mongojs.Database.prototype.tenant = function () { | ||
mongojs.Database.prototype.tenant = function (tenantName) { | ||
var db = this; | ||
var tenant = mongojs.Database.prototype.collection.apply(this, arguments); | ||
tenant.collection = function (name) { | ||
tenant.collection = function (collName) { | ||
//'this' currently refers to the collection returned as 'tenant' and not the db | ||
return mongojs.Database.prototype.collection.call(this, name); | ||
return mongojs.Database.prototype.collection.call(db, tenantName + "." + collName, collName); | ||
}; | ||
@@ -45,9 +46,9 @@ | ||
mongojs.Database.prototype.collection = _.wrap(mongojs.Database.prototype.collection, function (fn, name) { | ||
mongojs.Database.prototype.collection = _.wrap(mongojs.Database.prototype.collection, function (fn, name, collName) { | ||
//Create a parent mongojs collection to setup _name and _get fields | ||
var collection = fn.call(this, name); | ||
//Now if a pre-defined collection exists, call it with the internal fields retrieved above | ||
if (colls[name]) | ||
collection = new colls[name](collection._name, collection._get); | ||
//Now if a pre-defined collection exists (use tenent-less name if it exists), call it with the internal fields retrieved above | ||
if (colls[collName || name]) | ||
collection = new colls[collName || name](collection._name, collection._get); | ||
@@ -54,0 +55,0 @@ return collection; |
{ | ||
"name": "mongojs-hooks", | ||
"description": "Wrap monogjs in pre and post hooks", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "./mongojs-hooks", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -29,2 +29,13 @@ require("should"); | ||
}); | ||
//This test doesn't need to assert anything, because if we mock out the call and test to | ||
//see if it executes, then we don't evaluate the lazy loading and won't know if it called | ||
//correctly. Instead, this test will fail by throwing an exception. | ||
it("tenant().collection().find() - with tenant name - should not throw an exception", function (done) { | ||
var collection = db.tenant("tenant").collection("tests"); | ||
collection.find(function () { | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16640
248