centroid 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10f06b65f1456f1c80523a64b22127d10ab533da
4
- data.tar.gz: eae5193fb97114d3b0f763c99e23dd4a15446115
3
+ metadata.gz: 17dae74acaa307129c3a44df4923fd0eee4df0d9
4
+ data.tar.gz: 6e5b172c4094b07f90ebeccc7333e35373c8b354
5
5
  SHA512:
6
- metadata.gz: c17ec252c370dce8e8d4d8eaf23e1ba5e1f0c844cd08e52b2564b5e7b1d19f36f1b07581bb59d94a07397c543608a2d6b94b84f747cb171aa5c29f88e78dac14
7
- data.tar.gz: e2572359d37785b43f36a1739f86df98d267a8a4fc669f97e56f229a8cd09e8a245d86f0c28e8ad5b1135240e3fcad9d9de0135edf3ce34555ac440cd29d2cf8
6
+ metadata.gz: 292194f27184d2fae1e258c9554e8610ef3f41a20d38f841d18ffc4c540ce0c7e4823de7769224a876479eb3019a17b69362572ea8aa89469bd28ba70a8bad74
7
+ data.tar.gz: 95fdde661f2b0c77678c0501f63476f2a8737bdf3f2c7d0e1ab6baa16ac61609084380bb695b4afafc6e8d7a7e86e9f23b3664bfb2f1083cab15d5c6b8c7e35d
data/README.md CHANGED
@@ -44,11 +44,14 @@ In the `Config` instance, you can use the `for_environment` instance method to r
44
44
 
45
45
  If you specify an environment in `for_environment`, Centroid will merge the requested environment's configuration values with the values in *all*. Refer to [Examples in the Centroid document] (../README.md#examples) for information on creating an environment-based JSON configuration file.
46
46
 
47
+ To maintain environment awareness, this call adds an `environment` configuration value, unless your JSON contains an `environment` (case-insensitive) property already.
48
+
47
49
  With the following example, Centroid will merge the configuration for *prod* with the configuration for *all*; the result is then available from a new instance of `Config`.
48
50
 
49
51
  ```rb
50
52
  # for_enviroment.rb
51
53
  config = Centroid::Config.from_file("config.json").for_environment("prod")
54
+ environment = config.environment # => "prod"
52
55
  server = config.some_resource.server # => "resource-prod.local"
53
56
  solution_path = config.keys.ssh # => "path/to/id_rsa.pub"
54
57
  ```
data/centroid.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'centroid'
3
- s.version = '1.2.0'
3
+ s.version = '1.2.1'
4
4
  s.summary = 'A centralizaed paradigm to configuration management.'
5
5
  s.description = 'Centroid is a tool for loading configuration values declared in JSON, and accessing those configuration values using object properties.'
6
6
  s.author = 'Resource Data, Inc'
data/lib/centroid.rb CHANGED
@@ -59,14 +59,19 @@ module Centroid
59
59
 
60
60
  def for_environment(env)
61
61
  env_json = raw_config[env]
62
- env_json["environment"] = env
63
62
  all_key = actual_key("all")
64
63
  if all_key.nil?
65
- Config.new(env_json)
64
+ config = Config.new(env_json)
66
65
  else
67
66
  all_json = raw_config[all_key]
68
- Config.new(deep_merge(all_json, env_json))
67
+ config = Config.new(deep_merge(all_json, env_json))
69
68
  end
69
+
70
+ if !config.has_key?('environment')
71
+ config.raw_config['environment'] = env
72
+ end
73
+
74
+ config
70
75
  end
71
76
 
72
77
  def self.from_file(filename)
@@ -95,6 +95,18 @@ class ConfigTests < Test::Unit::TestCase
95
95
  assert_equal(config.shared, "production!")
96
96
  end
97
97
 
98
+ def test_environment_specific_config_has_environment_property
99
+ config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "All": {"Shared": "none"}}')
100
+ config = config.for_environment("Prod")
101
+ assert_equal(config.environment, "Prod")
102
+ end
103
+
104
+ def test_environment_specific_config_no_environment_property_if_has_environment_config_json
105
+ config = Centroid::Config.new('{"Prod": {"Environment": "production!"}, "All": {"Shared": "none"}}')
106
+ config = config.for_environment("Prod")
107
+ assert_equal(config.environment, "production!")
108
+ end
109
+
98
110
  def test_indexing_json_array
99
111
  config = Centroid::Config.new(json_config_with_array)
100
112
  assert_equal(config.the_array[0].the_key, "Value1")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Resource Data, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-13 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Centroid is a tool for loading configuration values declared in JSON,
14
14
  and accessing those configuration values using object properties.