Skip to content

Commit

Permalink
Merge branch 'release/v0.1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Aug 11, 2015
2 parents 67cd87d + 9c4f5e1 commit 8913eab
Show file tree
Hide file tree
Showing 42 changed files with 4,388 additions and 4,076 deletions.
5 changes: 5 additions & 0 deletions .bithoundrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ignore": [
"es5/**/*.js"
]
}
4 changes: 4 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
languages:
JavaScript: true
exclude_paths:
- es5/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Seat extends Model {

# Quality and Compatibility

[![Build Status](https://travis-ci.org/FreeAllMedia/dovima.png?branch=master)](https://travis-ci.org/FreeAllMedia/dovima) [![Coverage Status](https://coveralls.io/repos/FreeAllMedia/dovima/badge.svg)](https://coveralls.io/r/FreeAllMedia/dovima) [![Code Climate](https://codeclimate.com/github/FreeAllMedia/dovima/badges/gpa.svg)](https://codeclimate.com/github/FreeAllMedia/dovima) [![Dependency Status](https://david-dm.org/FreeAllMedia/dovima.png?theme=shields.io)](https://david-dm.org/FreeAllMedia/dovima?theme=shields.io) [![Dev Dependency Status](https://david-dm.org/FreeAllMedia/dovima/dev-status.svg)](https://david-dm.org/FreeAllMedia/dovima?theme=shields.io#info=devDependencies)
[![Build Status](https://travis-ci.org/FreeAllMedia/dovima.png?branch=master)](https://travis-ci.org/FreeAllMedia/dovima) [![Coverage Status](https://coveralls.io/repos/FreeAllMedia/dovima/badge.svg)](https://coveralls.io/r/FreeAllMedia/dovima) [![Code Climate](https://codeclimate.com/github/FreeAllMedia/dovima/badges/gpa.svg)](https://codeclimate.com/github/FreeAllMedia/dovima) [![bitHound Score](https://www.bithound.io/github/FreeAllMedia/dovima/badges/score.svg)](https://www.bithound.io/github/FreeAllMedia/dovima) [![Dependency Status](https://david-dm.org/FreeAllMedia/dovima.png?theme=shields.io)](https://david-dm.org/FreeAllMedia/dovima?theme=shields.io) [![Dev Dependency Status](https://david-dm.org/FreeAllMedia/dovima/dev-status.svg)](https://david-dm.org/FreeAllMedia/dovima?theme=shields.io#info=devDependencies)

*Every build and release is automatically tested on the following platforms:*

Expand Down
95 changes: 95 additions & 0 deletions es5/lib/associationSetter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var ambiguous = Symbol(),
dependent = Symbol();

var AssociationSetter = (function () {
function AssociationSetter(association) {
_classCallCheck(this, AssociationSetter);

this.association = association;

switch (association.type) {
case "belongsTo":
Object.defineProperties(this, {
"ambiguous": {
get: this[ambiguous]
}
});
break;
case "hasOne":
case "hasMany":
Object.defineProperties(this, {
"dependent": {
get: this[dependent]
}
});
break;
}
}

_createClass(AssociationSetter, [{
key: "foreignName",
value: function foreignName(name) {
this.association.foreignName = name;
return this;
}
}, {
key: "where",
value: function where() {
for (var _len = arguments.length, options = Array(_len), _key = 0; _key < _len; _key++) {
options[_key] = arguments[_key];
}

this.association.where = options;
return this;
}
}, {
key: "andWhere",
value: function andWhere() {
this.association.andWhere = this.association.andWhere || [];

for (var _len2 = arguments.length, options = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
options[_key2] = arguments[_key2];
}

this.association.andWhere.push(options);
return this;
}
}, {
key: "through",
value: function through(associationName) {
this.association.through = associationName;
return this;
}
}, {
key: "as",
value: function as(associationName) {
this.association.as = associationName;
return this;
}
}, {
key: ambiguous,
value: function value() {
this.association.ambiguous = true;
}
}, {
key: dependent,
value: function value() {
this.association.dependent = true;
}
}]);

return AssociationSetter;
})();

exports["default"] = AssociationSetter;
module.exports = exports["default"];
80 changes: 37 additions & 43 deletions es5/lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _jargon = require("jargon");

Expand All @@ -24,11 +24,9 @@ var _modelFinderJs = require("./modelFinder.js");

var _modelFinderJs2 = _interopRequireDefault(_modelFinderJs);

var _modelJs = require("./model.js");

var _modelJs2 = _interopRequireDefault(_modelJs);

var Collection = (function (_Array) {
_inherits(Collection, _Array);

function Collection(initialData) {
_classCallCheck(this, Collection);

Expand Down Expand Up @@ -56,8 +54,6 @@ var Collection = (function (_Array) {
});
}

_inherits(Collection, _Array);

_createClass(Collection, [{
key: "push",
value: function push() {
Expand Down Expand Up @@ -90,7 +86,7 @@ var Collection = (function (_Array) {
modelName = model;
}

throw TypeError("The model " + modelName + " is not an instance of " + _this._modelConstructor.name + ", therefore, it cannot be pushed to this collection.");
throw new TypeError("The model " + modelName + " is not an instance of " + _this._modelConstructor.name + ", therefore, it cannot be pushed to this collection.");
}
}
}
Expand All @@ -101,48 +97,46 @@ var Collection = (function (_Array) {
value: function fetch(callback) {
var _this2 = this;

if (this.association) {
(function () {
var processWhereCondition = function processWhereCondition(value) {
if (typeof value === "string") {
var snakeCasedValue = (0, _jargon2["default"])(value).snake.toString();
return snakeCasedValue;
} else {
return value;
}
};

var modelFinder = new _modelFinderJs2["default"](_this2.association.constructor.database);
function processWhereCondition(value) {
if (typeof value === "string") {
var snakeCasedValue = (0, _jargon2["default"])(value).snake.toString();
return snakeCasedValue;
} else {
return value;
}
}

var query = modelFinder.find(_this2.association.constructor).where(_this2.association.foreignKey, "=", _this2.association.parent.id);
if (this.association) {
var modelFinder = new _modelFinderJs2["default"](this.association.constructor.database);

if (_this2.association.where) {
(function () {
var processedWhereConditions = _this2.association.where.map(processWhereCondition);
var self = _this2;
query.andWhere(function () {
var _this3 = this;
var query = modelFinder.find(this.association.constructor).where(this.association.foreignKey, "=", this.association.parent.id);

this.where.apply(this, _toConsumableArray(processedWhereConditions));
if (this.association.where) {
(function () {
var processedWhereConditions = _this2.association.where.map(processWhereCondition);
var self = _this2;
query.andWhere(function () {
var _this3 = this;

if (Array.isArray(self.association.andWhere)) {
self.association.andWhere.forEach(function (whereConditions) {
var processedAndWhereItem = whereConditions.map(processWhereCondition);
_this3.andWhere.apply(_this3, _toConsumableArray(processedAndWhereItem));
});
}
});
})();
}
this.where.apply(this, _toConsumableArray(processedWhereConditions));

query.results(function (error, models) {
_this2.splice(0, _this2.length);
models.forEach(function (model) {
_this2.push(model);
if (Array.isArray(self.association.andWhere)) {
self.association.andWhere.forEach(function (whereConditions) {
var processedAndWhereItem = whereConditions.map(processWhereCondition);
_this3.andWhere.apply(_this3, _toConsumableArray(processedAndWhereItem));
});
}
});
callback(error);
})();
}

query.results(function (error, models) {
_this2.splice(0, _this2.length);
models.forEach(function (model) {
_this2.push(model);
});
})();
callback(error);
});
} else {
throw new Error("Cannot fetch collection without an association set. Call Model.all instead.");
}
Expand Down
Loading

0 comments on commit 8913eab

Please sign in to comment.