From 36b477df0f9bda4d153b674b3007ee087e44d67f Mon Sep 17 00:00:00 2001 From: Christian Fochler Date: Thu, 14 Dec 2017 05:00:04 +0100 Subject: remove unnecessary env key manipulation --- src/env.rs | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/env.rs b/src/env.rs index aec4de4..f25a62a 100644 --- a/src/env.rs +++ b/src/env.rs @@ -85,9 +85,6 @@ impl Source for Environment { } } - // Replace `separator` with `.` - key = key.replace(&self.separator, "."); - m.insert( key.to_lowercase(), Value::new(Some(&uri), ValueKind::String(value)), -- cgit v1.2.3 From c590f6cc3eca4a100bf769ef957f40ea43b1745c Mon Sep 17 00:00:00 2001 From: Christian Fochler Date: Sun, 28 Jan 2018 18:42:02 +0100 Subject: Revert "remove unnecessary env key manipulation" This reverts commit 36b477df0f9bda4d153b674b3007ee087e44d67f. --- src/env.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/env.rs b/src/env.rs index f25a62a..aec4de4 100644 --- a/src/env.rs +++ b/src/env.rs @@ -85,6 +85,9 @@ impl Source for Environment { } } + // Replace `separator` with `.` + key = key.replace(&self.separator, "."); + m.insert( key.to_lowercase(), Value::new(Some(&uri), ValueKind::String(value)), -- cgit v1.2.3 From 536f52fed4a22ed158681edce08211845abff985 Mon Sep 17 00:00:00 2001 From: Christian Fochler Date: Sun, 28 Jan 2018 21:16:21 +0100 Subject: make separator optional --- src/env.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/env.rs b/src/env.rs index aec4de4..5f7e92f 100644 --- a/src/env.rs +++ b/src/env.rs @@ -9,19 +9,16 @@ pub struct Environment { /// Optional prefix that will limit access to the environment to only keys that /// begin with the defined prefix. /// - /// A prefix, followed by `_` (the seperator), - /// is tested to be present on each key before its considered + /// A prefix is tested to be present on each key before its considered /// to be part of the source environment. /// - /// For example, the key `CONFIG_DEBUG` would become `DEBUG` with a prefix of `config`. + /// For example, the key `CONFIG_DEBUG` would become `DEBUG` with a prefix of `config_`. prefix: Option, - /// The character sequence that separates each key segment in an environment key pattern. + /// Optional character sequence that separates each key segment in an environment key pattern. /// Consider a nested configuration such as `redis.password`, a separator of `_` would allow /// an environment key of `REDIS_PASSWORD` to match. - /// - /// The default separator is `_`. - separator: String, + separator: Option, } impl Environment { @@ -36,13 +33,13 @@ impl Environment { } } - pub fn prefix(&mut self, s: String) -> &mut Self { - self.prefix = s.into(); + pub fn prefix(&mut self, s: &str) -> &mut Self { + self.prefix = Some(s.into()); self } - pub fn separator(&mut self, s: String) -> &mut Self { - self.separator = s; + pub fn separator(&mut self, s: &str) -> &mut Self { + self.separator = Some(s.into()); self } } @@ -51,7 +48,7 @@ impl Default for Environment { fn default() -> Environment { Environment { prefix: None, - separator: "_".into(), + separator: None, } } } @@ -65,9 +62,14 @@ impl Source for Environment { let mut m = HashMap::new(); let uri: String = "the environment".into(); - // Define a prefiux pattern to test and exclude from keys + let separator = match self.separator { + Some(ref separator) => separator, + _ => "" + }; + + // Define a prefix pattern to test and exclude from keys let prefix_pattern = match self.prefix { - Some(ref prefix) => Some(prefix.clone() + &self.separator), + Some(ref prefix) => Some(prefix.clone() + &separator), _ => None, }; @@ -76,7 +78,7 @@ impl Source for Environment { // Check for prefix if let Some(ref prefix_pattern) = prefix_pattern { - if key.to_lowercase().starts_with(prefix_pattern) { + if key.to_lowercase().starts_with(&prefix_pattern.to_lowercase()) { // Remove this prefix from the key key = key[prefix_pattern.len()..].to_string(); } else { @@ -85,8 +87,10 @@ impl Source for Environment { } } - // Replace `separator` with `.` - key = key.replace(&self.separator, "."); + // If separator is given replace with `.` + if !separator.is_empty() { + key = key.replace(separator, "."); + } m.insert( key.to_lowercase(), -- cgit v1.2.3 From 5ba6b7a437912ff40a216d3f99f963998b408911 Mon Sep 17 00:00:00 2001 From: Christian Fochler Date: Mon, 29 Jan 2018 08:05:59 +0100 Subject: add default prefix separator - no need to add '_' to the prefix --- src/env.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/env.rs b/src/env.rs index 5f7e92f..b26dc56 100644 --- a/src/env.rs +++ b/src/env.rs @@ -9,10 +9,10 @@ pub struct Environment { /// Optional prefix that will limit access to the environment to only keys that /// begin with the defined prefix. /// - /// A prefix is tested to be present on each key before its considered + /// A prefix with a separator of `_` is tested to be present on each key before its considered /// to be part of the source environment. /// - /// For example, the key `CONFIG_DEBUG` would become `DEBUG` with a prefix of `config_`. + /// For example, the key `CONFIG_DEBUG` would become `DEBUG` with a prefix of `config`. prefix: Option, /// Optional character sequence that separates each key segment in an environment key pattern. @@ -69,7 +69,7 @@ impl Source for Environment { // Define a prefix pattern to test and exclude from keys let prefix_pattern = match self.prefix { - Some(ref prefix) => Some(prefix.clone() + &separator), + Some(ref prefix) => Some(prefix.clone() + "_"), _ => None, }; -- cgit v1.2.3