Skip to content

Commit

Permalink
refactor(migration): Make check for promise more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
wzrdtales committed Jan 27, 2016
1 parent 01032a4 commit 76bc832
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ var Promise = require('bluebird');
var lpad = require('./util').lpad;
var Class = require('./class');

function isPromise( probe ) {

return probe instanceof Promise || ( probe && probe.then &&
probe.constructor && probe.constructor.name === 'Promise' );
}

function formatPath(dir, name) {
return path.join(dir, name);
}
Expand Down Expand Up @@ -75,7 +81,7 @@ var Skeleton = Class.extend({
migration = require(this.path).up.apply(this, params);

if( migration === null ) migration = Promise.resolve();
if( migration instanceof Promise ) {
if( isPromise( migration ) ) {

migration
.then(function() {
Expand Down Expand Up @@ -118,7 +124,7 @@ var Skeleton = Class.extend({
migration = require(this.path).down.apply(this, params);

if( migration === null ) migration = Promise.resolve();
if( migration instanceof Promise ) {
if( isPromise( migration ) ) {

migration
.then(function() {
Expand Down

0 comments on commit 76bc832

Please sign in to comment.