From 1b1c190de4aca54a20f225d4c82642cda2a3ec9a Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 11 Mar 2019 11:17:44 -0400 Subject: [PATCH] Add AngelEnv class --- lib/src/core/env.dart | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/src/core/env.dart diff --git a/lib/src/core/env.dart b/lib/src/core/env.dart new file mode 100644 index 00000000..fa0860ca --- /dev/null +++ b/lib/src/core/env.dart @@ -0,0 +1,27 @@ +import 'dart:io'; + +/// A constant instance of [AngelEnv]. +const AngelEnv angelEnv = const AngelEnv(); + +/// Queries the environment's `ANGEL_ENV` value. +class AngelEnv { + final String _customValue; + + /// You can optionally provide a custom value, in order to override the system's + /// value. + const AngelEnv([this._customValue]); + + /// Returns the value of the `ANGEL_ENV` variable; defaults to `'development'`. + String get value => + (_customValue ?? Platform.environment['ANGEL_ENV'] ?? 'development') + .toLowerCase(); + + /// Returns whether the [value] is `'development'`. + bool get isDevelopment => value == 'development'; + + /// Returns whether the [value] is `'production'`. + bool get isProduction => value == 'production'; + + /// Returns whether the [value] is `'staging'`. + bool get isStaging => value == 'staging'; +}