micromodel
Advanced tools
Comparing version 2.1.1 to 2.2.0
34
model.js
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.6.2 | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
@@ -13,11 +13,9 @@ var Model, defineClassInheritableAccessor, _, | ||
var _name; | ||
_name = "_" + name; | ||
return obj[name] = function() { | ||
var _ref, _ref1; | ||
if ((_ref = this[_name]) == null) { | ||
var _ref; | ||
if (this[_name] == null) { | ||
this[_name] = _(defaultValue).clone(); | ||
} | ||
if (this[_name] === ((_ref1 = this.__super__) != null ? _ref1.constructor[_name] : void 0)) { | ||
if (this[_name] === ((_ref = this.__super__) != null ? _ref.constructor[_name] : void 0)) { | ||
this[_name] = _(this[_name]).clone(); | ||
@@ -40,3 +38,2 @@ } | ||
var name, value, _results; | ||
if (attrs) { | ||
@@ -56,3 +53,2 @@ _results = []; | ||
var defaults; | ||
this.errors = {}; | ||
@@ -74,3 +70,2 @@ if (!_.isEmpty(defaults = this.constructor.defaults())) { | ||
var name, otherSize, size, value; | ||
if (this === other) { | ||
@@ -106,3 +101,2 @@ return true; | ||
var changes, name, newValue, oldValue; | ||
if (attrs == null) { | ||
@@ -139,3 +133,2 @@ return {}; | ||
var changes, name; | ||
changes = attributes(); | ||
@@ -153,3 +146,2 @@ for (name in this) { | ||
var name, validator, _results; | ||
if (validations) { | ||
@@ -168,4 +160,3 @@ _results = []; | ||
Model.prototype.validate = function() { | ||
var msg, name, validator, _base, _ref, _ref1, _results; | ||
var msg, name, validator, _base, _ref, _results; | ||
_ref = this.constructor.validations(); | ||
@@ -177,3 +168,3 @@ _results = []; | ||
if (msg = validator.call(this, this[name])) { | ||
_results.push(((_ref1 = (_base = this.errors)[name]) != null ? _ref1 : _base[name] = []).push(msg)); | ||
_results.push(((_base = this.errors)[name] != null ? _base[name] : _base[name] = []).push(msg)); | ||
} else { | ||
@@ -197,9 +188,8 @@ _results.push(void 0); | ||
Model.prototype.addError = function() { | ||
var args, _base, _base1, _name, _ref, _ref1; | ||
var args, _base, _base1, _name; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (args.length < 2) { | ||
return ((_ref = (_base = this.errors).base) != null ? _ref : _base.base = []).push(args[0]); | ||
return ((_base = this.errors).base != null ? _base.base : _base.base = []).push(args[0]); | ||
} else { | ||
return ((_ref1 = (_base1 = this.errors)[_name = args[0]]) != null ? _ref1 : _base1[_name] = []).push(args[1]); | ||
return ((_base1 = this.errors)[_name = args[0]] != null ? _base1[_name] : _base1[_name] = []).push(args[1]); | ||
} | ||
@@ -210,3 +200,2 @@ }; | ||
var attrs, name, value; | ||
attrs = {}; | ||
@@ -229,3 +218,2 @@ for (name in this) { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
@@ -241,3 +229,2 @@ return this.toJson.apply(this, args); | ||
var count, id, rand, symbols, _ref; | ||
if (length == null) { | ||
@@ -257,3 +244,2 @@ length = 6; | ||
var tmp; | ||
if (_.isFunction(type)) { | ||
@@ -296,3 +282,2 @@ return type(value); | ||
var name, type, _results; | ||
if (types) { | ||
@@ -312,3 +297,2 @@ _results = []; | ||
var casted, name, type, _ref; | ||
casted = {}; | ||
@@ -315,0 +299,0 @@ _ref = this.constructor.types(); |
125
mongodb.js
@@ -1,4 +0,4 @@ | ||
// Generated by CoffeeScript 1.6.2 | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Collection, Cursor, Db, MongoClient, inspect, sync, _, _ref; | ||
var Collection, Cursor, Db, MongoClient, inspect, sync, syncCursor, _, _ref; | ||
@@ -12,43 +12,41 @@ sync = require('synchronize'); | ||
Db.prototype.clear = function(callback) { | ||
var _this = this; | ||
if (!callback) { | ||
throw new Error("callback required!"); | ||
} | ||
return this.collectionNames(function(err, names) { | ||
var counter, dropNext; | ||
if (err) { | ||
return callback(err); | ||
} | ||
names = _(names).collect(function(obj) { | ||
return obj.name.replace(/^[^\.]+\./, ''); | ||
}); | ||
names = _(names).select(function(name) { | ||
return !/^system\./.test(name); | ||
}); | ||
counter = 0; | ||
dropNext = function() { | ||
var name; | ||
if (counter === names.length) { | ||
return callback(); | ||
} else { | ||
name = names[counter]; | ||
counter += 1; | ||
return _this.collection(name, function(err, collection) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return collection.drop(function(err) { | ||
return this.collectionNames((function(_this) { | ||
return function(err, names) { | ||
var counter, dropNext; | ||
if (err) { | ||
return callback(err); | ||
} | ||
names = _(names).collect(function(obj) { | ||
return obj.name.replace(/^[^\.]+\./, ''); | ||
}); | ||
names = _(names).select(function(name) { | ||
return !/^system\./.test(name); | ||
}); | ||
counter = 0; | ||
dropNext = function() { | ||
var name; | ||
if (counter === names.length) { | ||
return callback(); | ||
} else { | ||
name = names[counter]; | ||
counter += 1; | ||
return _this.collection(name, function(err, collection) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return dropNext(); | ||
return collection.drop(function(err) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return dropNext(); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
return dropNext(); | ||
}; | ||
return dropNext(); | ||
}); | ||
})(this)); | ||
}; | ||
@@ -60,12 +58,23 @@ | ||
sync(Collection.prototype, 'insert', 'findOne', 'count', 'remove', 'update', 'ensureIndex', 'indexes', 'drop', 'aggregate'); | ||
sync(Collection.prototype, 'insert', 'findOne', 'count', 'remove', 'update', 'ensureIndex', 'indexes', 'drop', 'aggregate', 'findAndModify'); | ||
sync(Cursor.prototype, 'toArray', 'count', 'nextObject'); | ||
syncCursor = function(obj) { | ||
return sync(obj, 'toArray', 'count', 'nextObject'); | ||
}; | ||
syncCursor(Cursor.prototype); | ||
Collection.prototype.findWithoutSynchronizedCursor = Collection.prototype.find; | ||
Collection.prototype.find = function() { | ||
var cursor; | ||
cursor = this.findWithoutSynchronizedCursor.apply(this, arguments); | ||
syncCursor(cursor); | ||
return cursor; | ||
}; | ||
module.exports.ModelPersistence = function(Model) { | ||
var handleSomeErrors; | ||
handleSomeErrors = function(model, fn) { | ||
var err, _base, _ref1; | ||
try { | ||
@@ -110,3 +119,2 @@ fn(); | ||
var data; | ||
if (selector == null) { | ||
@@ -145,4 +153,2 @@ selector = {}; | ||
Model.all = function(selector, options) { | ||
var _this = this; | ||
if (selector == null) { | ||
@@ -154,5 +160,7 @@ selector = {}; | ||
} | ||
return this.collection().find(selector, options).toArray().map(function(o) { | ||
return new _this(o); | ||
}); | ||
return this.collection().find(selector, options).toArray().map((function(_this) { | ||
return function(o) { | ||
return new _this(o); | ||
}; | ||
})(this)); | ||
}; | ||
@@ -182,3 +190,2 @@ Model.find = function(selector, options) { | ||
var model; | ||
model = this.build(attrs); | ||
@@ -191,4 +198,2 @@ model.create(options) || (function() { | ||
Model.prototype.create = function(options) { | ||
var _this = this; | ||
if (options == null) { | ||
@@ -200,10 +205,10 @@ options = {}; | ||
} | ||
return handleSomeErrors(this, function() { | ||
return _this.collection().insert(_this.toJson(), options); | ||
}); | ||
return handleSomeErrors(this, (function(_this) { | ||
return function() { | ||
return _this.collection().insert(_this.toJson(), options); | ||
}; | ||
})(this)); | ||
}; | ||
Model.prototype.update = function(options) { | ||
var originalId, | ||
_this = this; | ||
var originalId; | ||
if (options == null) { | ||
@@ -218,7 +223,9 @@ options = {}; | ||
} | ||
return handleSomeErrors(this, function() { | ||
return _this.collection().update({ | ||
id: originalId || _this.id | ||
}, _this.toJson(), options); | ||
}); | ||
return handleSomeErrors(this, (function(_this) { | ||
return function() { | ||
return _this.collection().update({ | ||
id: originalId || _this.id | ||
}, _this.toJson(), options); | ||
}; | ||
})(this)); | ||
}; | ||
@@ -225,0 +232,0 @@ Model.prototype["delete"] = function(options) { |
{ | ||
"name" : "micromodel", | ||
"main" : "./model", | ||
"version" : "2.1.1", | ||
"version" : "2.2.0", | ||
"homepage" : "http://alexeypetrushin.github.com/micromodel", | ||
"dependencies" : { | ||
"mongodb" : "1.2.x", | ||
"mongodb" : "1.3.x", | ||
"underscore" : "1.3.x" | ||
@@ -9,0 +9,0 @@ }, |
Sorry, the diff of this file is not supported yet
65014
533
+ Addedbson@0.2.5(transitive)
+ Addedkerberos@0.0.3(transitive)
+ Addedmongodb@1.3.23(transitive)
- Removedbson@0.1.8(transitive)
- Removedmongodb@1.2.14(transitive)
Updatedmongodb@1.3.x