Permalink
Browse files

Corrected an error with the monkey-patch logic

  • Loading branch information...
1 parent b5ee770 commit c517877dec8f9637fecb0356bc325892dc654202 @hkjels committed May 31, 2012
Showing with 24 additions and 25 deletions.
  1. +1 −1 examples/user/app.js
  2. +15 −16 lib/crud.js
  3. +8 −8 package.json
View
@@ -8,7 +8,7 @@ var express = require('express')
, models = require('./models')
, stylus = require('stylus')
, nib = require('nib')
- , crud = require('../../lib/crud')(app)
+ , crud = require('../../lib/crud')
require('express-namespace')
View
@@ -15,29 +15,28 @@ var express = require('express')
, mongoose = require('mongoose')
, friendly = require('./mongoose-friendly')
, en = lingo.en
- , instance
- , Model
+ , app = express.application
+ ? express.application
+ : express.HTTPServer.prototype
/**
- * CRUD
+ * Model & instance-name
*/
-var crud = module.exports = function crud (app) {
+var instance
+ , Model
- /**
- * Monkeypatch express with `crud`
- */
+/**
+ * Monkeypatch express with `crud`
+ */
- express.HTTPServer.prototype.crud =
- express.HTTPSServer.prototype.crud = function (name, options) {
- for (var model in mongoose.models) {
- if (!mongoose.models.hasOwnProperty(model)) continue
- if (model.toLowerCase() === name.toLowerCase()) Model = mongoose.model(model)
- }
- instance = en.singularize(Model.modelName).toLowerCase()
- app.resource(name, resource)
+app.crud = function (name, options) {
+ for (var model in mongoose.models) {
+ if (!mongoose.models.hasOwnProperty(model)) continue
+ if (model.toLowerCase() === name.toLowerCase()) Model = mongoose.model(model)
}
-
+ instance = en.singularize(Model.modelName).toLowerCase()
+ this.resource(name, resource)
}
/**
View
@@ -1,20 +1,20 @@
{
"name": "crud"
- , "version": "0.0.26"
- , "author": "Henrik Kjelsberg <henrik@kjelsberg.net>"
+ , "description": "Crud functionality for mongoose-models. Fits well with express.js"
+ , "keywords": ["mongoose", "express", "crud", "scaffold", "rest"]
, "homepage": "http://hkjels.github.com/crud/"
- , "bugs": {
- "url": "https://github.com/hkjels/crud/issues"
- }
+ , "version": "0.0.27"
+ , "author": "Henrik Kjelsberg <henrik@kjelsberg.net>"
, "contributors": [
{ "name": "Henrik Kjelsberg", "email": "henrik@kjelsberg.net" }
]
- , "description": "Crud functionality for mongoose-models. Fits well with express.js"
- , "keywords": ["mongoose", "express", "crud", "scaffold"]
+ , "main": "index.js"
+ , "bugs": {
+ "url": "https://github.com/hkjels/crud/issues"
+ }
, "repository": "git://github.com/hkjels/crud.git"
, "scripts": {
"prepublish": "make mocha with cream and sugar"
- , "start": "node-dev examples/user/app"
, "test": "make mocha"
}
, "dependencies": {

0 comments on commit c517877

Please sign in to comment.