Skip to content
Browse files

fix for CoffeeScript inheritance

  • Loading branch information...
1 parent c64d5a2 commit 10120fdba856061778c6158b7358ec84b312df8a @vdemedes committed Feb 16, 2012
Showing with 44 additions and 6 deletions.
  1. +16 −2 lib/mongorito.coffee
  2. +28 −4 lib/mongorito.js
View
18 lib/mongorito.coffee
@@ -48,7 +48,16 @@ String.prototype.underscore = function() {
}
var hasProp = Object.prototype.hasOwnProperty,
- extendsClass = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }
+ extendsClass = function(child, parent) {
+ for (var key in parent) {
+ if (hasProp.call(parent, key)) child[key] = parent[key];
+ }
+ function ctor(proto) { this.constructor = child; for(var method in proto) { this[method] = proto[method]; } }
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor(child.prototype);
+ child.__super__ = parent.prototype;
+ return child;
+ }
`
class Mongorito
@@ -80,12 +89,14 @@ class Mongorito
object = new model
model.collection = object.collection
model.model = model
+ model
+
class MongoritoModel
constructor: (@collection = '') ->
fields: ->
- notFields = ['constructor', 'save', 'collection', 'create', 'fields', 'update', 'remove']
+ notFields = ['constructor', 'save', 'collection', 'create', 'fields', 'update', 'remove', 'beforeCreate', 'aroundCreate', 'afterCreate', 'beforeUpdate', 'aroundUpdate', 'afterUpdate']
fields = {}
for field of @
fields[field] = @[field] if -1 is notFields.indexOf field
@@ -284,6 +295,9 @@ class MongoritoModel
process.nextTick ->
callback err if callback
+
+class GenericModel extends MongoritoModel
+
module.exports=
connect: Mongorito.connect
disconnect: Mongorito.disconnect
View
32 lib/mongorito.js
@@ -1,4 +1,6 @@
-var Client, Mongorito, MongoritoModel, async, mongolian;
+var Client, GenericModel, Mongorito, MongoritoModel, async, mongolian,
+ __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
mongolian = require('mongolian');
@@ -52,7 +54,16 @@ String.prototype.underscore = function() {
}
var hasProp = Object.prototype.hasOwnProperty,
- extendsClass = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }
+ extendsClass = function(child, parent) {
+ for (var key in parent) {
+ if (hasProp.call(parent, key)) child[key] = parent[key];
+ }
+ function ctor(proto) { this.constructor = child; for(var method in proto) { this[method] = proto[method]; } }
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor(child.prototype);
+ child.__super__ = parent.prototype;
+ return child;
+ }
;
Mongorito = (function() {
@@ -97,7 +108,8 @@ Mongorito = (function() {
extendsClass(model, MongoritoModel);
object = new model;
model.collection = object.collection;
- return model.model = model;
+ model.model = model;
+ return model;
};
return Mongorito;
@@ -112,7 +124,7 @@ MongoritoModel = (function() {
MongoritoModel.prototype.fields = function() {
var field, fields, notFields;
- notFields = ['constructor', 'save', 'collection', 'create', 'fields', 'update', 'remove'];
+ notFields = ['constructor', 'save', 'collection', 'create', 'fields', 'update', 'remove', 'beforeCreate', 'aroundCreate', 'afterCreate', 'beforeUpdate', 'aroundUpdate', 'afterUpdate'];
fields = {};
for (field in this) {
if (-1 === notFields.indexOf(field)) fields[field] = this[field];
@@ -375,6 +387,18 @@ MongoritoModel = (function() {
})();
+GenericModel = (function(_super) {
+
+ __extends(GenericModel, _super);
+
+ function GenericModel() {
+ GenericModel.__super__.constructor.apply(this, arguments);
+ }
+
+ return GenericModel;
+
+})(MongoritoModel);
+
module.exports = {
connect: Mongorito.connect,
disconnect: Mongorito.disconnect,

0 comments on commit 10120fd

Please sign in to comment.
Something went wrong with that request. Please try again.