Skip to content

Commit

Permalink
make use of sails.util._ than global _
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Apr 16, 2015
1 parent e00ecd0 commit 5666e08
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Expand Up @@ -24,6 +24,7 @@ module.exports = function(grunt) {
},
all: [
'Gruntfile.js',
'index.js',
'lib/**/*.js',
'test/**/*.js'
]
Expand Down
60 changes: 32 additions & 28 deletions index.js
@@ -1,3 +1,6 @@
'use strict';

//dependencies
var path = require('path');
var libPath = path.join(__dirname, 'lib');

Expand All @@ -20,37 +23,13 @@ var validate = require(path.join(libPath, 'validate'));
* @param {Object} sails a sails application instance
*/
module.exports = function(sails) {
return {
initialize: function(done) {
var eventsToWaitFor = [];
//wait for orm
//and pub sub
//to be loaded
//for validation to be
//able to apply its patch
if (sails.hooks.orm) {
eventsToWaitFor.push('hook:orm:loaded');
}
if (sails.hooks.pubsub) {
eventsToWaitFor.push('hook:pubsub:loaded');
}

sails
.after(eventsToWaitFor, function() {
//bind custom errors logic
//and let sails to continue
patch();

done();
});
}
};

//patch sails model
//to add custom errors message
//logic
function patch() {
sails.util._(sails.models)
sails
.util
._(sails.models)
.forEach(function(model) {
//bind path validate
//on concrete models
Expand Down Expand Up @@ -78,7 +57,32 @@ module.exports = function(sails) {

}
});
};
}

return {
initialize: function(done) {
var eventsToWaitFor = [];
//wait for orm
//and pub sub
//to be loaded
//for validation to be
//able to apply its patch
if (sails.hooks.orm) {
eventsToWaitFor.push('hook:orm:loaded');
}
if (sails.hooks.pubsub) {
eventsToWaitFor.push('hook:pubsub:loaded');
}

sails
.after(eventsToWaitFor, function() {
//bind custom errors logic
//and let sails to continue
patch();

done();
});
}
};

};

0 comments on commit 5666e08

Please sign in to comment.