From 6179476030c7a88fdf43841496390b7fe276687a Mon Sep 17 00:00:00 2001 From: Ritchie Date: Thu, 31 Oct 2013 10:06:43 -0700 Subject: [PATCH] Add app.dataSource() method --- docs/api.md | 2 +- lib/application.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/api.md b/docs/api.md index 4a101155..a3e93842 100644 --- a/docs/api.md +++ b/docs/api.md @@ -29,7 +29,7 @@ Initialize an application from an options object or a set of JSON and JavaScript 1. **DataSources** are created from an `options.dataSources` object or `datasources.json` in the current directory 2. **Models** are created from an `options.models` object or `models.json` in the current directory -3. Any JavaScript files in the `./models` and `./datasources` directories are required. +3. Any JavaScript files in the `./models` directory are loaded with `require()`. **Options** diff --git a/lib/application.js b/lib/application.js index 8ad838d5..61893d39 100644 --- a/lib/application.js +++ b/lib/application.js @@ -84,6 +84,16 @@ app.models = function () { return this._models; } +/** + * Define a DataSource. + */ + +app.dataSource = function (name, config) { + this.dataSources[name] = + this.dataSources[classify(name)] = + this.dataSources[camelize(name)] = dataSourcesFromConfig(config); +} + /** * Get all remote objects. */ @@ -185,9 +195,7 @@ app.boot = function(options) { // instantiate data sources forEachKeyedObject(dataSourceConfig, function(key, obj) { - app.dataSources[key] = - app.dataSources[classify(key)] = - app.dataSources[camelize(key)] = dataSourcesFromConfig(obj); + app.dataSource(key, obj); }); // instantiate models