Skip to content

Commit

Permalink
Cast env reference in config
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Persson committed Oct 16, 2015
1 parent 5240114 commit ad59d8a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/src/core/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,17 @@ class _Config implements Config {
return (value as String).replaceFirstMapped(matcher, (m) {
var envName = m[1];
var defaultValue = m[2];
return env(envName, defaultValue);
return _cast(env(envName, defaultValue));
});
}

Object _cast(String env) {
if (env == 'true') return true;
if (env == 'false') return false;
if (new RegExp(r'^\d+|\d*\.\d+$').hasMatch(env)) return num.parse(env);
return env;
}

call(String key, [defaultValue]) {
var value = this[key];
return (value == null) ? defaultValue : value;
Expand Down

0 comments on commit ad59d8a

Please sign in to comment.