cconfig 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99118dcdb7cbe21b54f559dd45bb67ea1d7ce435
4
- data.tar.gz: ba1e90f4309e857b07475d582140d9408d83c8b8
3
+ metadata.gz: 5ea447e81e322d1bf22dddca71e18e2eab21760d
4
+ data.tar.gz: 003941dd51eebfa38fea464be15f861bcc49f28c
5
5
  SHA512:
6
- metadata.gz: 9978dcbd2a24382e8c0ce84b9bd88eb33356ca1f6a8ae34a6d8089098a0e2386e7fcc3af93c4a80ca5951dbc917b3c322b87a62d1589efcac7dba546a80f5f49
7
- data.tar.gz: 9e560a472e040ed024af2031ed35981953fd77e6e58dbc7296f7ab2e972226299381607b79500a96963d18a94971c6a1a2c865d2d6415758643c1a26bad8031a
6
+ metadata.gz: 841ebc1ec251e9490865f5e7f918ef38051402898e604b3b8e2c93ed42fbb2c74609a1b6f39b344d367ad779892e29440840eb218c3a11f122adcea105d98aeb
7
+ data.tar.gz: 2a18d68a5ea16c626e1d245549d67425c4fe6a0c301e6476f032f562730c3e7484e36acfb8935a5c8d4f8c90a604951013866f9d25e47a4620b3368f33af60bc
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.1
4
+
5
+ - Fixed crash on nested values on the `#enabled?` method. See [#3](https://github.com/mssola/cconfig/issues/3).
6
+ - The `prefix` argument from the constructor now takes a default
7
+ (`cconfig`). This will make things more predictable I hope.
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  - Added the `disabled?` method, which is a shorthand for `enabled?`.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cconfig (1.0.0)
4
+ cconfig (1.1.1)
5
5
  safe_yaml (~> 1.0.0, >= 1.0.0)
6
6
 
7
7
  GEM
@@ -30,14 +30,14 @@ module CConfig
30
30
 
31
31
  # Instantiate an object with `default` as the path to the default
32
32
  # configuration, `local` as the alternate file, and `prefix` as the prefix
33
- # for environment variables.
33
+ # for environment variables. The `prefix` will take "cconfig" as the default.
34
34
  #
35
35
  # Note: the `local` value will be discarded in favor of the
36
36
  # `#{prefix}_LOCAL_CONFIG_PATH` environment variable if it was set.
37
37
  def initialize(default:, local:, prefix:)
38
38
  @default = default
39
- @local = ENV["#{prefix.upcase}_LOCAL_CONFIG_PATH"] || local
40
- @prefix = prefix
39
+ @prefix = prefix || "cconfig"
40
+ @local = ENV["#{@prefix.upcase}_LOCAL_CONFIG_PATH"] || local
41
41
  end
42
42
 
43
43
  # Returns a hash with the app configuration contained in it.
@@ -31,14 +31,16 @@ module CConfig
31
31
  # b:
32
32
  # enabled: true
33
33
  def enabled?(feature)
34
- objs = feature.split(".")
35
- if objs.length == 2
36
- return false if !self[objs[0]][objs[1]] || self[objs[0]][objs[1]].empty?
37
- self[objs[0]][objs[1]]["enabled"].eql?(true)
38
- else
39
- return false if !self[feature] || self[feature].empty?
40
- self[feature]["enabled"].eql?(true)
34
+ cur = self
35
+ parts = feature.split(".")
36
+
37
+ parts.each do |part|
38
+ cur = cur[part]
39
+ return false if !cur || cur.empty?
40
+ return true if cur.key?("enabled") && cur["enabled"].eql?(true)
41
41
  end
42
+
43
+ false
42
44
  end
43
45
 
44
46
  # Returns true if the given feature is disabled or doesn't exist. This is
@@ -19,5 +19,5 @@
19
19
 
20
20
  module CConfig
21
21
  # The current version of CConfig.
22
- VERSION = "1.1.0".freeze
22
+ VERSION = "1.1.1".freeze
23
23
  end
@@ -84,9 +84,10 @@ describe CConfig::Config do
84
84
  # the local.yml file.
85
85
  base = File.join(File.dirname(__FILE__), "fixtures")
86
86
  local = File.join(base, "bad.yml")
87
- ENV["TEST_LOCAL_CONFIG_PATH"] = File.join(base, "local.yml")
87
+ ENV["CCONFIG_LOCAL_CONFIG_PATH"] = File.join(base, "local.yml")
88
88
 
89
- cfg = ::CConfig::Config.new(default: "config.yml", local: local, prefix: "test")
89
+ # Passing nil to the prefix on purpose (see SUSE/Portus#1379)
90
+ cfg = ::CConfig::Config.new(default: "config.yml", local: local, prefix: nil)
90
91
  expect { cfg.fetch }.not_to raise_error
91
92
  end
92
93
  end
@@ -65,4 +65,14 @@ describe ::CConfig::HashUtils do
65
65
  expect(cfg["ldap"]["count"]).to eq 2 # env
66
66
  expect(cfg["ldap"]["string"]).to eq "string" # env
67
67
  end
68
+
69
+ # See issue #3
70
+ it "does not crash on nested default that doesn't exist" do
71
+ cfg = ConfigMock.new.strict_merge_with_env_test(default: default, local: local, prefix: "test")
72
+
73
+ cfg.extend(::CConfig::HashUtils::Extensions)
74
+ expect(cfg.enabled?("gravatar")).to be_truthy
75
+ expect(cfg.enabled?("oauth.google_oauth2")).to be_falsey
76
+ expect(cfg.enabled?("something.that.does.not.exist")).to be_falsey
77
+ end
68
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mssola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.6.12
158
+ rubygems_version: 2.4.8
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Configuration management for container-aware applications.