Comparing version
@@ -18,3 +18,3 @@ /*! | ||
var SkinAdmin = exports.SkinAdmin = makeSkinClass(Admin); | ||
var SkinAdmin = exports.SkinAdmin = makeSkinClass(Admin, false, true); | ||
@@ -26,3 +26,3 @@ SkinAdmin.prototype._open = function(callback) { | ||
callback(null, p_db.admin()); | ||
}) | ||
} | ||
}); | ||
}; |
@@ -22,3 +22,3 @@ /*! | ||
exports.makeSkinClass = function makeSkinClass(NativeClass, useNativeConstructor) { | ||
exports.makeSkinClass = function makeSkinClass(NativeClass, useNativeConstructor, isSingle) { | ||
@@ -49,5 +49,38 @@ function onError (err, args, name) { | ||
this._init && this._init(); | ||
if(isSingle) { | ||
for(var propName in SkinClass.prototype) { | ||
if(propName[0] != '_') { | ||
this[propName] = SkinClass.prototype[propName]; | ||
} | ||
} | ||
var res = NativeClass.apply(this, args); | ||
for(propName in res) { | ||
this[propName] = res[propName]; | ||
if(propName[0] != '_') bindObject(this, propName); | ||
} | ||
} | ||
} | ||
SkinClass._class_name = skinClassName; | ||
function bindObject(target, propName) { | ||
if(target.hasOwnProperty(propName) && typeof target[propName] == 'function') { | ||
var fn = target[propName]; | ||
target[propName] = function() { | ||
var args = __slice.apply(arguments); | ||
if (target._state == STATE_OPEN) { | ||
this._native[propName].apply(this._native, args); | ||
} else { | ||
this.open(function(err, p_native) { | ||
if (err) { | ||
onError(err, args, skinClassName + '.' + propName); | ||
} else { | ||
p_native[propName].apply(p_native, args); | ||
} | ||
}); | ||
} | ||
return this; | ||
}.bind(target); | ||
} | ||
} | ||
function bindSkin(propName) { | ||
@@ -113,4 +146,6 @@ var fn; | ||
for(var propName in NativeClass.prototype) { | ||
if(propName[0] != '_') bindSkin(propName); | ||
if(!isSingle) { | ||
for(var propName in NativeClass.prototype) { | ||
if(propName[0] != '_') bindSkin(propName); | ||
} | ||
} | ||
@@ -117,0 +152,0 @@ |
{ | ||
"name": "mongoskin", | ||
"description": "The future layer above node-mongodb-native", | ||
"version": "1.3.23", | ||
"version": "1.4.0", | ||
"author": "Gui Lin <guileen@gmail.com>", | ||
@@ -24,3 +24,3 @@ "homepage": "https://github.com/kissjs/node-mongoskin", | ||
"dependencies": { | ||
"mongodb": "1.3.23" | ||
"mongodb": "1.4.0" | ||
}, | ||
@@ -30,3 +30,3 @@ "devDependencies": { | ||
"blanket": "~1.1.6", | ||
"coveralls": "~2.8.0", | ||
"coveralls": "~2.10.0", | ||
"mocha-lcov-reporter": "0.0.1", | ||
@@ -33,0 +33,0 @@ "travis-cov": "~0.2.5", |
Sorry, the diff of this file is not supported yet
34395
3.43%743
4.8%+ Added
+ Added
+ Added
- Removed
- Removed
Updated