The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
2018-07-12 12:40:54 -04:00
example Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
lib Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
test Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
.gitignore Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
.travis.yml Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
analysis_options.yaml Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
CHANGELOG.md Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
LICENSE Initial commit 2016-04-21 19:36:59 -04:00
pubspec.yaml Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00
README.md Verified tests on Dart 1 + 2 2018-07-12 12:40:54 -04:00

configuration

Pub build status

Automatic YAML configuration loader for Angel.

About

Any web app needs different configuration for development and production. This plugin will search for a config/default.yaml file. If it is found, configuration from it is loaded into app.configuration. Then, it will look for a config/$ANGEL_ENV file. (i.e. config/development.yaml). If this found, all of its configuration be loaded, and will override anything loaded from the default.yaml file. This allows for your app to work under different conditions without you re-coding anything. :)

Installation

In pubspec.yaml:

dependencies:
    angel_configuration: ^1.0.0

Usage

Example Configuration

# Define normal YAML objects
some_key: foo
this_is_a_map:
  a_string: "string"
  another_string: "string"
  

You can also load configuration from the environment:

# Loaded from the environment
system_path: $PATH

If a .env file is present in your configuration directory, then it will be loaded before applying YAML configuration.

Server-side Call configuration(). The loaded configuration will be available in your application's configuration map, which means you can access them like normal instance members.

main() {
  print(app.foo == app.configuration['foo']); // true
}

An instance of Configuration will also be injected to your application, and it works the same way:

import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_configuration/angel_configuration.dart';
import 'package:file/local.dart';

main() async {
    var app = new Angel();
    var fileSystem = const LocalFileSystem();
    
    await app.configure(configuration(fileSystem)); // It's that easy!
    
    app.get('/foo', (Configuration config) {
      return config.some_key;
    });
}

configuration also accepts a sourceDirectory or overrideEnvironmentName parameter. The former will allow you to search in a directory other than config, and the latter lets you override $ANGEL_ENV by specifying a specific configuration name to look for (i.e. production).

This package uses package:merge_map internally, so existing configurations can be deeply merged.

Example:

# default.yaml
foo:
  bar: baz
  quux: hello
  
# production.yaml
foo:
  quux: goodbye
  yellow: submarine
  
# Propagates to:
foo:
  bar: baz
  quux: goodbye
  yellow: submarine