Support modular railway

This commit is contained in:
Anatoliy Chakkaev 2012-05-03 02:15:09 +04:00
parent 7d748e9c02
commit 2b67400525
2 changed files with 8 additions and 4 deletions

View File

@ -5,10 +5,10 @@ exports.Schema = require('./lib/schema').Schema;
exports.AbstractClass = require('./lib/abstract-class').AbstractClass;
exports.Validatable = require('./lib/validatable').Validatable;
exports.init = function () {
exports.init = function (root) {
if (!global.railway) return;
railway.orm = exports;
require('./lib/railway');
require('./lib/railway')(root);
};
try {

View File

@ -4,7 +4,9 @@ var Schema = railway.orm.Schema;
railway.orm._schemas = [];
var confFile = app.root + '/config/database.json';
module.exports = function init(root) {
var confFile = (root || app.root) + '/config/database.json';
var config;
if (path.existsSync(confFile)) {
@ -25,7 +27,7 @@ railway.orm._schemas.push(schema);
context = prepareContext(schema);
// run schema first
var schemaFile = app.root + '/db/schema.';
var schemaFile = (root || app.root) + '/db/schema.';
if (path.existsSync(schemaFile + 'js')) {
schemaFile += 'js';
} else if (path.existsSync(schemaFile + 'coffee')) {
@ -173,3 +175,5 @@ function prepareContext(defSchema, done) {
return r;
}
}
};