Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f396869
Showing
10 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
material/ | ||
node_modules/ | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "support/expresso"] | ||
path = support/expresso | ||
url = https://github.com/visionmedia/expresso.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.git* | ||
material/ | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**v0.0.1** (2011-06-18): | ||
|
||
- Initial version of the extension for Mongose 1.3.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
EXPRESSO = support/expresso/bin/expresso -I lib | ||
|
||
TESTS = tests/*.test.js | ||
|
||
test: | ||
@$(EXPRESSO) $(TESTS) $(TEST_FLAGS) | ||
|
||
test-cov: | ||
@$(MAKE) TEST_FLAGS=--cov test | ||
|
||
.PHONY: test test-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
mongoose-misc - Miscellaneous types and plugins for Mongoose | ||
============= | ||
|
||
### Overview | ||
|
||
Mongoose-Closures is an extension for Mongoose that provides a collection of miscellaneous types and plugins for the | ||
Mongoose ORM. | ||
|
||
### Contributors | ||
- [Stuart Hudson](https://github.com/goulash1971) | ||
|
||
### License | ||
MIT License | ||
|
||
### Acknowledgements | ||
- [Brian Noguchi](https://github.com/bnoguchi) for the 'mongoose-types' extension that was used as a template for this extension | ||
|
||
--- | ||
### Author | ||
Stuart Hudson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Module file for Mongoose-Joins | ||
* | ||
* Copyright 2011, Stuart Hudson <goulash1971@yahoo.com> | ||
* Released under the terms of the MIT License. | ||
* | ||
* Version 0.0.1 | ||
*/ | ||
|
||
module.exports = require("./lib"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/** | ||
* lib/index.js - extension loader | ||
* | ||
* Copyright 2011, Stuart Hudson <goulash1971@yahoo.com> | ||
* Released under the terms of the MIT License. | ||
* | ||
* Version 0.0.1 | ||
*/ | ||
|
||
|
||
/** | ||
* Expose the utilities that are available from this module (these | ||
* are also accessed from the loadTypes function. | ||
*/ | ||
exports.utils = utils = require("./utils"); | ||
|
||
|
||
/** | ||
* Utility function that will convert an {Array} of arguments into a | ||
* loading specification consiting of a filter {Function} and an | ||
* {Array} of names. | ||
* | ||
* @param {Array} arguments to be converted to a loading spec | ||
* @return {Object} loading spec of filter and names | ||
* @api private | ||
*/ | ||
var figureLoadSpec = function (args) { | ||
var spec = {filter: function (name) { return true; }, names: []}; | ||
if (args.length == 1) { | ||
if (typeof args[0] === 'function') | ||
spec.filter = args[0]; | ||
else spec.names = args; | ||
} else spec.names = args; | ||
return spec; | ||
} | ||
|
||
/** | ||
* Loads either the named types or all available types in the | ||
* {@code lib/types} source directory | ||
* | ||
* @param {Mongoose} the active Mongoose instance for installation | ||
* @param {Array} (optional) type filenames | ||
* @return {Object} the types that were loaded for the module | ||
* @api public | ||
*/ | ||
exports.loadTypes = loadTypes = function (mongoose, types) { | ||
types = figureLoadSpec(types ? types : []); | ||
var loaded = {}; | ||
if (types.names.length) { | ||
types.names.forEach(function (type) { | ||
if (types.filter(type)) { | ||
var val = require("./types/" + type).loadType(mongoose); | ||
if (typeof val === 'function') | ||
loaded[val.name] = val; | ||
} | ||
}); | ||
} else { | ||
var files = require("fs").readdirSync(__dirname + "/types"); | ||
files.forEach(function(filename) { | ||
if (filename.slice(filename.length-3) === '.js') { | ||
var base = filename.slice(0, filename.length-3); | ||
if (types.filter(base)) { | ||
var val = require("./types/" + base).loadType(mongoose); | ||
if (typeof val === 'function') | ||
loaded[val.name] = val; | ||
} | ||
} | ||
}); | ||
} | ||
return loaded; | ||
}; | ||
|
||
|
||
/** | ||
* Installs either the named plugins or all available plugins in the | ||
* {@code lib/plugins} source directory | ||
* | ||
* @param {Mongoose} the active Mongoose instance for installation | ||
* @param {Array} (optional) plugin filenames | ||
* @return {Object} the plugins that were loaded for this module | ||
* @api public | ||
*/ | ||
exports.installPlugins = installPlugins = function (mongoose, plugins) { | ||
plugins = figureLoadSpec(plugins ? plugins : []); | ||
var loaded = {}; | ||
if (plugins.names.length) { | ||
plugins.names.forEach(function (plugin) { | ||
if (plugins.filter(plugin)) { | ||
var val = require("./plugins/" + plugin).install(mongoose); | ||
if (typeof val === 'function') | ||
loaded[val.name] = val; | ||
} | ||
}); | ||
} else { | ||
var files = require("fs").readdirSync(__dirname + "/plugins"); | ||
files.forEach(function(filename) { | ||
if (filename.slice(filename.length-3) === '.js') { | ||
var base = filename.slice(0, filename.length-3); | ||
if (plugins.filter(base)) { | ||
var val = require("./plugins/" + base).install(mongoose); | ||
if (typeof val === 'function') | ||
loaded[val.name] = val; | ||
} | ||
} | ||
}); | ||
} | ||
return loaded; | ||
} | ||
|
||
/** | ||
* Installs either the named patches or all available patches in the | ||
* {@code lib/patches} source directory | ||
* | ||
* @param {Mongoose} the active Mongoose instance for installation | ||
* @param {Array} (optional) patch filenames or filter function | ||
* @return the utilities of the extension (see './utils.js') | ||
* @api public | ||
*/ | ||
exports.installPatches = installPatches = function (mongoose, patches) { | ||
patches = figureLoadSpec(patches ? patches : []); | ||
if (patches.names.length) { | ||
patches.names.forEach(function (patch) { | ||
if (patches.filter(patch)) | ||
require("./patches/" + patch).install(mongoose); | ||
}); | ||
} else { | ||
var files = require("fs").readdirSync(__dirname + "/patches"); | ||
files.forEach(function(filename) { | ||
if (filename.slice(filename.length-3) === '.js') { | ||
var base = filename.slice(0, filename.length-3); | ||
if (patches.filter(base)) | ||
require("./patches/" + base).install(mongoose); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Installation function that will load all of the types and install | ||
* both the plugins and the patches that are defined for this mongoose | ||
* extension. | ||
* | ||
* The {@param options} can either be a {Function} which is passed to | ||
* the types, plugins and patches installers for filtering, or an | ||
* {Object} which identifies which types ({@param options#types}), | ||
* plugins ({@param options#plugins}) or patches ({@param options#patches}) | ||
* are to be installed. | ||
* | ||
* @param {Mongoose} the active Mongoose instance for installation | ||
* @param {Object} identifying what is to be installed | ||
* @return {Object} the types, plugins and patches loaded | ||
* @api public | ||
*/ | ||
exports.install = function (mongoose, spec) { | ||
var loaded = {}; | ||
if (typeof spec == 'function') | ||
spec = {types: spec, plugins: spec, patches: spec}; | ||
else if (!(typeof spec == 'object')) | ||
spec = {types: [], plugins: [], patches: []}; | ||
loaded.types = loadTypes (mongoose, spec.types); | ||
loaded.plugins = installPlugins(mongoose, spec.plugins); | ||
loaded.patches = installPatches(mongoose, spec.patches); | ||
return loaded; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* lib/utils.js - module utilities loader | ||
* | ||
* Copyright 2011, Stuart Hudson <goulash1971@yahoo.com> | ||
* Released under the terms of the MIT License. | ||
* | ||
* Version 0.0.1 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "mongoose-misc", | ||
"description": "Miscellaneous types & plugins for Mongoose", | ||
"version": "0.0.1", | ||
"author": "Stuart Hudson <goulash1971@yahoo.com>", | ||
"keywords": ["mongodb", "mongoose", "mongo", "plugins", "types"], | ||
"homepage": "https://github.com/goulash1971/mongoose-misc", | ||
"contributors": [ | ||
"Stuart Hudson <goulash1971@yahoo.com> (http://goulash1971.com/)" | ||
], | ||
"dependencies": { | ||
"mongoose": ">= 1.0.16" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"directories": { | ||
"lib": "lib/", | ||
"test": "tests/" | ||
}, | ||
"main": "./index", | ||
"engines": { | ||
"node": ">= 0.1.101" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/goulash1971/mongoose-misc.git" | ||
}, | ||
"licenses": [ | ||
{"type": "The MIT License", "url": "http://www.opensource.org/licenses/mit-license.php"} | ||
] | ||
} |