conf_loader 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/conf_loader/version.rb +1 -1
- data/lib/conf_loader.rb +30 -2
- data/spec/fixtures/simple.yml +6 -1
- data/spec/integration/conf_loader_spec.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0faf9108d7e238f50b273199aaffa4170995a137
|
4
|
+
data.tar.gz: 19433f3f3b1595f0f1f1ed2f1c05bb8b381ff9de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8598f2926e6902f67cf6b9e4332cb1d90d7246dea1d64ed81257290223473cc25af0128314b846322f80b379016b06b752760bd5656936e5a37d8ac0e0edc50c
|
7
|
+
data.tar.gz: 9f2b2b29c155fd56514fdb7a113794f6cd60e3d3f37501439fdbb5e55a042b2fe793018cc1e33091d9478a42e4ba146c2003cda97d16ec7ef15541c1fcd46220
|
data/lib/conf_loader/version.rb
CHANGED
data/lib/conf_loader.rb
CHANGED
@@ -6,6 +6,7 @@ require 'erb'
|
|
6
6
|
#
|
7
7
|
class ConfLoader
|
8
8
|
EnvironmentNotFoundError = Class.new(KeyError)
|
9
|
+
ValueNotDefinedError = Class.new(KeyError)
|
9
10
|
|
10
11
|
# Load given conf file
|
11
12
|
#
|
@@ -24,13 +25,19 @@ class ConfLoader
|
|
24
25
|
|
25
26
|
if environments.has_key?(env)
|
26
27
|
hash = environments[env]
|
27
|
-
|
28
|
+
|
29
|
+
check_value_presence(
|
30
|
+
guarantee_key_presence(Symbolizer.symbolize(hash))
|
31
|
+
)
|
28
32
|
else
|
29
33
|
raise EnvironmentNotFoundError,
|
30
34
|
"Configuration for `#{env}` not found at path #{path}"
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
38
|
+
|
39
|
+
private_class_method
|
40
|
+
|
34
41
|
def self.guarantee_key_presence(hash)
|
35
42
|
hash.default_proc = proc do |h, k|
|
36
43
|
raise KeyError, "#{k} not defined"
|
@@ -38,5 +45,26 @@ class ConfLoader
|
|
38
45
|
hash
|
39
46
|
end
|
40
47
|
|
41
|
-
|
48
|
+
def self.check_value_presence(hash)
|
49
|
+
errors = check_values_not_empty(hash)
|
50
|
+
if errors.empty?
|
51
|
+
hash
|
52
|
+
else
|
53
|
+
raise ValueNotDefinedError, errors.join(', ')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.check_values_not_empty(hash)
|
58
|
+
hash.inject([]) do |acc, (key, value)|
|
59
|
+
errors =
|
60
|
+
if value.is_a?(Hash)
|
61
|
+
check_values_not_empty(value)
|
62
|
+
elsif value.to_s.empty?
|
63
|
+
["#{key} value not defined"]
|
64
|
+
else
|
65
|
+
[]
|
66
|
+
end
|
67
|
+
acc + errors
|
68
|
+
end
|
69
|
+
end
|
42
70
|
end
|
data/spec/fixtures/simple.yml
CHANGED
@@ -9,4 +9,9 @@ production:
|
|
9
9
|
flexible:
|
10
10
|
foo: <%= ENV['FOO'] %>
|
11
11
|
var_with_default_not_in_env: <%= ENV['SOME_VAR_NOT_IN_ENV'] || 'default_value' %>
|
12
|
-
var_with_default_in_env: <%= ENV['FOO'] || 'default_value' %>
|
12
|
+
var_with_default_in_env: <%= ENV['FOO'] || 'default_value' %>
|
13
|
+
|
14
|
+
invalid:
|
15
|
+
empty_value: ''
|
16
|
+
nested_field:
|
17
|
+
nested_empty_value: ''
|
@@ -58,4 +58,14 @@ describe ConfLoader do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
context 'with empty config value' do
|
62
|
+
let(:conf) { described_class.load(path, 'invalid') }
|
63
|
+
|
64
|
+
it 'raises ValueNotDefinedError' do
|
65
|
+
expect{conf}.to raise_error(
|
66
|
+
described_class::ValueNotDefinedError,
|
67
|
+
'empty_value value not defined, nested_empty_value value not defined'
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
61
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conf_loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Indrek Juhkam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: symbolizer
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.6.7
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Helps to load conf files in SaleMove ecosystem
|