From 76fe71a474a7e88a26f5ecd4fbe5e4b3396c3dff Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 4 May 2020 12:05:14 -0400 Subject: [PATCH] configuration: finish 2.2.0, update readme --- packages/configuration/README.md | 12 ++++++++++-- packages/configuration/lib/angel_configuration.dart | 2 +- packages/configuration/test/all_test.dart | 5 +++++ packages/configuration/test/config/development.yaml | 4 +++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/configuration/README.md b/packages/configuration/README.md index 74f13cae..7fa10919 100644 --- a/packages/configuration/README.md +++ b/packages/configuration/README.md @@ -38,9 +38,17 @@ You can also load configuration from the environment: system_path: $PATH ``` -If a `.env` file is present in your configuration directory, then it will be loaded before +If a `.env` file is present in your configuration directory (i.e. `config/.env`), then it will be loaded before applying YAML configuration. +You can also include values from one file into another: +```yaml +_include: + - "./include-prod.yaml" + - "./include-misc.yaml" +_include: "just-one-file.yaml" +``` + **Server-side** Call `configuration()`. The loaded configuration will be available in your application's `configuration` map. @@ -71,4 +79,4 @@ foo: bar: baz quux: goodbye yellow: submarine -``` \ No newline at end of file +``` diff --git a/packages/configuration/lib/angel_configuration.dart b/packages/configuration/lib/angel_configuration.dart index 3255016e..60b9f72a 100644 --- a/packages/configuration/lib/angel_configuration.dart +++ b/packages/configuration/lib/angel_configuration.dart @@ -21,7 +21,7 @@ Future _loadYamlFile(Map map, File yamlFile, Map env, var out = {}; - var configMap = config as Map; + var configMap = Map.of(config as Map); // Check for _include if (configMap.containsKey('_include')) { diff --git a/packages/configuration/test/all_test.dart b/packages/configuration/test/all_test.dart index 0a37635e..dcf7f4aa 100644 --- a/packages/configuration/test/all_test.dart +++ b/packages/configuration/test/all_test.dart @@ -33,6 +33,7 @@ Future main() async { 'angel': {'framework': 'cool'}, 'must_be_null': null, 'artist': 'Timberlake', + 'included': true, 'merge': {'map': true, 'hello': 'world'}, 'set_via': 'default', 'hello': 'world', @@ -40,6 +41,10 @@ Future main() async { }); }); + test('obeys included paths', () async { + expect(app.configuration['included'], true); + }); + test('can load based on ANGEL_ENV', () async { expect(app.configuration['hello'], equals('world')); expect(app.configuration['foo']['version'], equals('bar')); diff --git a/packages/configuration/test/config/development.yaml b/packages/configuration/test/config/development.yaml index 3c74cdd3..0c39f7d5 100644 --- a/packages/configuration/test/config/development.yaml +++ b/packages/configuration/test/config/development.yaml @@ -1,3 +1,5 @@ +_include: + - "./include.yaml" hello: world foo: - version: bar \ No newline at end of file + version: bar