micromodel
Advanced tools
Comparing version 2.1.0 to 2.1.1
18
model.js
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.6.1 | ||
// Generated by CoffeeScript 1.6.2 | ||
(function() { | ||
@@ -13,5 +13,7 @@ var Model, defineClassInheritableAccessor, _, | ||
var _name; | ||
_name = "_" + name; | ||
return obj[name] = function() { | ||
var _ref, _ref1; | ||
if ((_ref = this[_name]) == null) { | ||
@@ -38,2 +40,3 @@ this[_name] = _(defaultValue).clone(); | ||
var name, value, _results; | ||
if (attrs) { | ||
@@ -53,2 +56,3 @@ _results = []; | ||
var defaults; | ||
this.errors = {}; | ||
@@ -70,2 +74,3 @@ if (!_.isEmpty(defaults = this.constructor.defaults())) { | ||
var name, otherSize, size, value; | ||
if (this === other) { | ||
@@ -101,2 +106,3 @@ return true; | ||
var changes, name, newValue, oldValue; | ||
if (attrs == null) { | ||
@@ -133,2 +139,3 @@ return {}; | ||
var changes, name; | ||
changes = attributes(); | ||
@@ -146,2 +153,3 @@ for (name in this) { | ||
var name, validator, _results; | ||
if (validations) { | ||
@@ -161,2 +169,3 @@ _results = []; | ||
var msg, name, validator, _base, _ref, _ref1, _results; | ||
_ref = this.constructor.validations(); | ||
@@ -188,2 +197,3 @@ _results = []; | ||
var args, _base, _base1, _name, _ref, _ref1; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
@@ -199,2 +209,3 @@ if (args.length < 2) { | ||
var attrs, name, value; | ||
attrs = {}; | ||
@@ -217,2 +228,3 @@ for (name in this) { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
@@ -228,2 +240,3 @@ return this.toJson.apply(this, args); | ||
var count, id, rand, symbols, _ref; | ||
if (length == null) { | ||
@@ -243,2 +256,3 @@ length = 6; | ||
var tmp; | ||
if (_.isFunction(type)) { | ||
@@ -281,2 +295,3 @@ return type(value); | ||
var name, type, _results; | ||
if (types) { | ||
@@ -296,2 +311,3 @@ _results = []; | ||
var casted, name, type, _ref; | ||
casted = {}; | ||
@@ -298,0 +314,0 @@ _ref = this.constructor.types(); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.6.1 | ||
// Generated by CoffeeScript 1.6.2 | ||
(function() { | ||
@@ -13,2 +13,3 @@ var Collection, Cursor, Db, MongoClient, inspect, sync, _, _ref; | ||
var _this = this; | ||
if (!callback) { | ||
@@ -19,2 +20,3 @@ throw new Error("callback required!"); | ||
var counter, dropNext; | ||
if (err) { | ||
@@ -32,2 +34,3 @@ return callback(err); | ||
var name; | ||
if (counter === names.length) { | ||
@@ -59,14 +62,17 @@ return callback(); | ||
sync(Collection.prototype, 'insert', 'findOne', 'count', 'remove', 'update', 'ensureIndex', 'indexes', 'drop'); | ||
sync(Collection.prototype, 'insert', 'findOne', 'count', 'remove', 'update', 'ensureIndex', 'indexes', 'drop', 'aggregate'); | ||
sync(Cursor.prototype, 'toArray', 'count'); | ||
sync(Cursor.prototype, 'toArray', 'count', 'nextObject'); | ||
module.exports.ModelPersistence = function(Model) { | ||
var handleSomeErrors; | ||
handleSomeErrors = function(model, fn) { | ||
var _base, _ref1; | ||
var err, _base, _ref1; | ||
try { | ||
fn(); | ||
return true; | ||
} catch (err) { | ||
} catch (_error) { | ||
err = _error; | ||
if ((_ref1 = err.code) === 11000 || _ref1 === 11001) { | ||
@@ -106,2 +112,3 @@ ((_base = model.errors).base || (_base.base = [])).push('not unique'); | ||
var data; | ||
if (selector == null) { | ||
@@ -120,4 +127,24 @@ selector = {}; | ||
}; | ||
Model.firstRequired = function(selector, options) { | ||
if (selector == null) { | ||
selector = {}; | ||
} | ||
if (options == null) { | ||
options = {}; | ||
} | ||
return this.first(selector, options) || ((function() { | ||
throw new Error("no '" + this.name + "' for '" + selector + "' query!"); | ||
}).call(this)); | ||
}; | ||
Model.exist = function(selector) { | ||
if (selector == null) { | ||
selector = {}; | ||
} | ||
return !!this.first(selector, { | ||
_id: 1 | ||
}); | ||
}; | ||
Model.all = function(selector, options) { | ||
var _this = this; | ||
if (selector == null) { | ||
@@ -133,2 +160,11 @@ selector = {}; | ||
}; | ||
Model.find = function(selector, options) { | ||
if (selector == null) { | ||
selector = {}; | ||
} | ||
if (options == null) { | ||
options = {}; | ||
} | ||
return this.collection().find(selector, options); | ||
}; | ||
Model.count = function(selector, options) { | ||
@@ -148,2 +184,3 @@ if (selector == null) { | ||
var model; | ||
model = this.build(attrs); | ||
@@ -157,2 +194,3 @@ model.create(options) || (function() { | ||
var _this = this; | ||
if (options == null) { | ||
@@ -171,2 +209,3 @@ options = {}; | ||
_this = this; | ||
if (options == null) { | ||
@@ -173,0 +212,0 @@ options = {}; |
{ | ||
"name" : "micromodel", | ||
"main" : "./model", | ||
"version" : "2.1.0", | ||
"version" : "2.1.1", | ||
"homepage" : "http://alexeypetrushin.github.com/micromodel", | ||
@@ -6,0 +6,0 @@ "dependencies" : { |
Sorry, the diff of this file is not supported yet
64265
519