From 38f0bb0c3b7880e6938ad9399627338d3f2d3f6c Mon Sep 17 00:00:00 2001 From: Jason Roebuck Date: Wed, 9 Jul 2014 08:23:10 -0800 Subject: [PATCH 1/4] add environment property to python Config Adds `environment` property to Config when instantiated using `for_environment()` --- python/centroid.py | 1 + python/tests.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/python/centroid.py b/python/centroid.py index ee696df..4647fab 100644 --- a/python/centroid.py +++ b/python/centroid.py @@ -53,6 +53,7 @@ def _validate_unique_keys(self): def for_environment(self, env): env_json = self.raw_config[env] + env_json["environment"] = env actual_key = _get_actual_key('all', self.raw_config) if actual_key is None: diff --git a/python/tests.py b/python/tests.py index 6cf387c..3794fac 100644 --- a/python/tests.py +++ b/python/tests.py @@ -38,6 +38,11 @@ def test_readable_using_snake_case_property(self): config = Config(self._json_config) self.assertEqual(config.the_environment.the_key, "TheValue") + def test_environment_property_is_included(self): + config = Config(self._json_config) + environment_config = config.for_environment("theEnvironment") + self.assertEqual(environment_config.environment, "theEnvironment") + def test_environment_specific_config_is_included(self): config = Config(self._json_config) environment_config = config.for_environment("theEnvironment") From a76e908f2d6140e8435c9dc0c4127cb7b327271d Mon Sep 17 00:00:00 2001 From: Jason Roebuck Date: Wed, 9 Jul 2014 08:44:08 -0800 Subject: [PATCH 2/4] add environment property to ruby Config --- ruby/lib/centroid.rb | 1 + ruby/test/centroid_test.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/ruby/lib/centroid.rb b/ruby/lib/centroid.rb index 3ffdfde..aaf29f0 100644 --- a/ruby/lib/centroid.rb +++ b/ruby/lib/centroid.rb @@ -57,6 +57,7 @@ def to_s def for_environment(env) env_json = raw_config[env] + env_json["environment"] = env all_key = actual_key("all") if all_key.nil? Config.new(env_json) diff --git a/ruby/test/centroid_test.rb b/ruby/test/centroid_test.rb index c6091b1..14ead17 100644 --- a/ruby/test/centroid_test.rb +++ b/ruby/test/centroid_test.rb @@ -49,6 +49,12 @@ def test_readable_using_snake_case_property assert_equal(config.the_environment.the_key, "TheValue") end + def test_environment_property_is_included + config = Centroid::Config.new(json_config) + environment_config = config.for_environment("theEnvironment") + assert_equal(environment_config.environment, "theEnvironment") + end + def test_environment_specific_config_is_included config = Centroid::Config.new(json_config) environment_config = config.for_environment("theEnvironment") From 3268221828e075b68dbee58dfdfeb81d8b517149 Mon Sep 17 00:00:00 2001 From: Jason Roebuck Date: Wed, 9 Jul 2014 08:47:43 -0800 Subject: [PATCH 3/4] add environment property to dot-net Config --- dot-net/Centroid.Tests/ConfigTest.cs | 8 ++++++++ dot-net/Centroid/Config.cs | 1 + 2 files changed, 9 insertions(+) diff --git a/dot-net/Centroid.Tests/ConfigTest.cs b/dot-net/Centroid.Tests/ConfigTest.cs index 2d13cf5..aca6357 100644 --- a/dot-net/Centroid.Tests/ConfigTest.cs +++ b/dot-net/Centroid.Tests/ConfigTest.cs @@ -59,6 +59,14 @@ public void test_readable_using_snake_case_property() Assert.That(config.the_environment.the_key, Is.EqualTo("TheValue")); } + [Test] + public void test_environment_property_is_included() + { + var config = new Config(JsonConfig); + dynamic environmentConfig = config.ForEnvironment("theEnvironment"); + Assert.That(environmentConfig.environment, Is.EqualTo("theEnvironment")); + } + [Test] public void test_environment_specific_config_is_included() { diff --git a/dot-net/Centroid/Config.cs b/dot-net/Centroid/Config.cs index 1054f97..0194769 100644 --- a/dot-net/Centroid/Config.cs +++ b/dot-net/Centroid/Config.cs @@ -43,6 +43,7 @@ public bool ContainsKey(string key) public dynamic ForEnvironment(string environment) { var envConfig = GetContainer(environment); + envConfig["environment"] = environment; var allConfig = GetContainer("all"); if (allConfig == null) From 68c136968c80036e646b094863b4bb9ace8d6e76 Mon Sep 17 00:00:00 2001 From: Jason Roebuck Date: Thu, 10 Jul 2014 07:54:03 -0800 Subject: [PATCH 4/4] update changelog with environment property feature --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01b4c0d..dd1f475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +* Add `environment` property to config created with `ForEnvironment` - [#63](https://github.com/ResourceDataInc/Centroid/pull/63) * Deep merge support - [#56](https://github.com/ResourceDataInc/Centroid/pull/56) * Add `ContainsKey` method - [#50](https://github.com/ResourceDataInc/Centroid/pull/50) @@ -17,6 +18,7 @@ ### Features +* Add `environment` property to config created with `for_environment` - [#63](https://github.com/ResourceDataInc/Centroid/pull/63) * Deep merge support - [#56](https://github.com/ResourceDataInc/Centroid/pull/56) * Add `__contains__` support - [#50](https://github.com/ResourceDataInc/Centroid/pull/50) @@ -28,6 +30,7 @@ ### Features +* Add `environment` property to config created with `for_environment` - [#63](https://github.com/ResourceDataInc/Centroid/pull/63) * Deep merge support - [#56](https://github.com/ResourceDataInc/Centroid/pull/56) * Add `has_key?` method - [#50](https://github.com/ResourceDataInc/Centroid/pull/50)