Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit f3968691fe83dd729dc637aae00accca91432f9e 0 parents
@goulash1971 authored
4 .gitignore
@@ -0,0 +1,4 @@
+.DS_Store
+material/
+node_modules/
+npm-debug.log
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "support/expresso"]
+ path = support/expresso
+ url = https://github.com/visionmedia/expresso.git
3  .npmignore
@@ -0,0 +1,3 @@
+.git*
+material/
+npm-debug.log
3  CHANGELOG.md
@@ -0,0 +1,3 @@
+**v0.0.1** (2011-06-18):
+
+ - Initial version of the extension for Mongose 1.3.3
11 Makefile
@@ -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
20 README.md
@@ -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
10 index.js
@@ -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");
165 lib/index.js
@@ -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;
+}
9 lib/utils.js
@@ -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
+ */
+
32 package.json
@@ -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"}
+ ]
+}
Please sign in to comment.
Something went wrong with that request. Please try again.