Skip to content

Commit 780b27e

Browse files
committed
change the way to init mongoose
1 parent 99d0ed0 commit 780b27e

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

index.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
'use strict';
22

3-
var mongoose = require('mongoose');
3+
//var mongoose = require('mongoose');
44

55
var locales=['en','ru'];
66
var locale='en';
77

8-
(function(){
8+
var prototype_mongoose=function(mongoose){
99
var ma = mongoose.Schema.prototype.add;
1010
var addI18n=function(schema,obj){
11-
//console.log('====');
12-
13-
//console.log(obj);
14-
//console.trace();
1511
var keys = Object.keys(obj);
1612

1713
if (keys.length==1 && keys=='_id') return obj;
@@ -74,18 +70,19 @@ var locale='en';
7470
};
7571
return ret;
7672
}
73+
7774
mongoose.Schema.prototype.add = function add (obj, prefix) {
78-
//console.log({in:obj})
79-
//console.trace();
8075
var oobj=addI18n(this,obj);
81-
//console.log({out:oobj})
8276
ma.call(this,oobj,prefix);
8377
};
84-
})();
78+
};
8579

86-
var localize=module.exports = function(opt){
87-
if (opt.locales) locales=opt.locales;
88-
if (opt.locale) locale=opt.locale;
80+
var localize=module.exports = function(mongoose,opt){
81+
if (opt){
82+
if (opt.locales) locales=opt.locales;
83+
if (opt.locale) locale=opt.locale;
84+
}
85+
prototype_mongoose(mongoose);
8986
return {}
9087
}
9188
localize.locale=function(){
@@ -100,3 +97,4 @@ localize.locales=function(){
10097
localize.setLocales=function(sLocales){
10198
locales=sLocales;
10299
}
100+

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
},
55
"name": "mongoose-localize",
66
"description": "A module to conver mongoose model property to set of localized properties.",
7-
"version": "0.0.3",
7+
"version": "0.0.6",
88
"repository": {
99
"url": "git://github.com/dsame/mongoose-localize.git"
1010
},
1111
"main": "./index",
12-
"dependencies": {
13-
"mongoose": ">=3.8.8"
14-
},
1512
"engines": {
1613
"node": "*"
1714
},

0 commit comments

Comments
 (0)