Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchodeluxe committed Nov 6, 2016
2 parents 69825eb + 46d53ef commit 17ff947
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
10 changes: 5 additions & 5 deletions core/my/bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,13 @@ class Bootstrapper {
let schema_ids = result.rows.map((v) => { return v.id; });

let migrations = fs.readdirSync(MIGRATION_PATH).map((v) => {
if(v.indexOf('.') === 0) return {};
return {
id: parseInt(v.substr(0, v.indexOf('__'))),
migration: new (require(process.cwd() + '/' + MIGRATION_PATH + '/' + v))(db)
};
});

migrations = migrations.filter((v) => {
return schema_ids.indexOf(v.id) === -1;
}).filter((v) => {
return v.id && schema_ids.indexOf(v.id) === -1;
});

if (migrations.length === 0) {
Expand Down Expand Up @@ -245,12 +244,13 @@ class Bootstrapper {
let schema_ids = result.rows.map((v) => { return v.id; });

let migrations = fs.readdirSync(MIGRATION_PATH).map((v) => {
if(v.indexOf('.') === 0) return {};
return {
id: parseInt(v.substr(0, v.indexOf('__'))),
migration: new (require(process.cwd() + '/' + MIGRATION_PATH + '/' + v))(db)
};
}).filter((v) => {
return schema_ids.indexOf(v.id) !== -1;
return v.id && schema_ids.indexOf(v.id) !== -1;
}).reverse();

if (migrations.length === 0) {
Expand Down
34 changes: 26 additions & 8 deletions core/required/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,25 @@ class Model {

/**
* Creates a verifier. These run asynchronously, support multiple fields, and check every time you try to save a Model.
* @param {string} message The error message shown if a validation fails.
* @param {string} field The field applied to the verification.
* @param {string} message The error message shown if a verification fails.
* @param {function} fnAction The asynchronous verification method. The last argument passed is always a callback, and field names are determined by the argument names.
*/
static verifies(message, fnAction) {
static verifies(field, message, fnAction) {

// Legacy support
if (arguments.length === 2) {
fnAction = message;
message = field;
field = null;
}

if (!this.prototype.hasOwnProperty('_verificationsList')) {
this.prototype._verificationsList = [];
};

this.prototype._verificationsList.push({
field: field,
message: message,
action: fnAction,
fields: utilities.getFunctionParameters(fnAction).slice(0, -1)
Expand Down Expand Up @@ -1128,10 +1137,6 @@ class Model {
*/
__verify__(callback) {

if (this.hasErrors()) {
return callback.call(this, this.errorObject());
}

// Run through verifications in order they were added
async.series(
this._verificationsList.map(verification => {
Expand All @@ -1140,13 +1145,26 @@ class Model {
this,
verification.fields
.map(field => this.get(field))
.concat(bool => callback(bool ? null : new Error(verification.message)))
.concat(bool => {
if (bool) {
callback(null);
} else {
if (verification.field) {
this.setError(verification.field, verification.message);
callback(null);
} else {
callback(new Error(verification.message))
}
}
})
)
};
}),
(err) => {

if (err) {
if (this.hasErrors()) {
return callback.call(this, this.errorObject());
} else if (err) {
return callback.call(this, err);
}

Expand Down
1 change: 1 addition & 0 deletions core/required/model_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ModelFactory {

return fs
.readdirSync(dir)
.filter(filename => filename.indexOf('.') !== 0)
.map(filename => require(`${process.cwd()}/app/models/${filename}`))

}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodal",
"version": "0.12.8",
"version": "0.12.9",
"description": "An API Server and Framework for node.js",
"keywords": [
"framework",
Expand Down

0 comments on commit 17ff947

Please sign in to comment.