simple-conf 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/simple-conf/loader.rb +17 -7
- data/lib/simple-conf/version.rb +1 -1
- data/spec/simple_conf_spec.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2QxYWZhN2FlNjc0ZTdmMzFiNDkwOTk5NTBiZWE1ZTIxNjMyYmYwMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzQ1MzY0ZjYyYzA0ZjljYmQ2MmQ4YWE3NGU0NDdiYmEwYmZkZTI2MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWVkZjZiNzQ4YWFkOWY4NjQ4YjlhYzcwNDgxZGJlY2FhZDNlZjRjODI4NDVm
|
10
|
+
YzQ1NGIwZDcxZGZmNDQyOTJlNDVjZmIxMDYxZWIyYjcwYmFhNmY5MzM1MmU2
|
11
|
+
M2ZhMjg4MTg1MGE2NjhmN2YzMzU5YmE0OTUzZDNjMzlmMzA5Mzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGUzZjg1MTlkYTUyYTAxOWEwNWZjOTFjNjBiMDYwZTgwMzZjNDk2NGUxMzI3
|
14
|
+
MjNkY2U3MWVlMzJkZDE0YjUyNDJmOWZiMWEzZDY5OTVhOWMzMmQ3M2Q0NzNk
|
15
|
+
NzZmNDJkMWMyNjk4MGQ4MDEwNzM4Y2JjMTcyNTgxMTkyMmI5N2I=
|
data/lib/simple-conf/loader.rb
CHANGED
@@ -12,7 +12,11 @@ module SimpleConf
|
|
12
12
|
attr_reader :keys
|
13
13
|
end
|
14
14
|
|
15
|
-
@keys =
|
15
|
+
@keys = Set.new
|
16
|
+
|
17
|
+
def keys
|
18
|
+
@keys.to_a
|
19
|
+
end
|
16
20
|
}
|
17
21
|
end
|
18
22
|
|
@@ -27,6 +31,10 @@ module SimpleConf
|
|
27
31
|
def load_file_by_rails_env(path)
|
28
32
|
yaml_file(path).fetch(Rails.env, {}).each_pair do |key, value|
|
29
33
|
set(key, value)
|
34
|
+
|
35
|
+
klass.class_eval %Q{
|
36
|
+
@keys << :#{key}
|
37
|
+
}
|
30
38
|
end if rails_environment_defined?
|
31
39
|
end
|
32
40
|
|
@@ -39,6 +47,10 @@ module SimpleConf
|
|
39
47
|
def load_file_by_klass_env(path)
|
40
48
|
yaml_file(path).fetch(klass.env, {}).each_pair do |key, value|
|
41
49
|
set(key, value)
|
50
|
+
|
51
|
+
klass.class_eval %Q{
|
52
|
+
@keys << :#{key}
|
53
|
+
}
|
42
54
|
end if klass.respond_to?(:env)
|
43
55
|
end
|
44
56
|
|
@@ -57,10 +69,10 @@ module SimpleConf
|
|
57
69
|
|
58
70
|
def underscore(camel_case_string)
|
59
71
|
camel_case_string.gsub(/::/, '/').
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
72
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
73
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
74
|
+
tr("-", "_").
|
75
|
+
downcase
|
64
76
|
end
|
65
77
|
|
66
78
|
def yaml_file(path)
|
@@ -76,8 +88,6 @@ module SimpleConf
|
|
76
88
|
class << self
|
77
89
|
attr_reader :#{key}
|
78
90
|
end
|
79
|
-
|
80
|
-
@keys.push(:#{key})
|
81
91
|
}
|
82
92
|
end
|
83
93
|
|
data/lib/simple-conf/version.rb
CHANGED
data/spec/simple_conf_spec.rb
CHANGED
@@ -69,6 +69,12 @@ describe SimpleConf do
|
|
69
69
|
it 'on include properties depenending on env method' do
|
70
70
|
expect(Settings.domain).to eq('test.example.com')
|
71
71
|
end
|
72
|
+
|
73
|
+
|
74
|
+
it 'should not include env keys' do
|
75
|
+
expect(Settings.keys).not_to include(:test)
|
76
|
+
expect(Settings.keys).to include(:domain)
|
77
|
+
end
|
72
78
|
end
|
73
79
|
|
74
80
|
describe SimpleConf do
|
@@ -125,12 +131,6 @@ describe SimpleConf do
|
|
125
131
|
expect(Options2).to respond_to(:group1)
|
126
132
|
expect(Options2).to respond_to(:group2)
|
127
133
|
end
|
128
|
-
|
129
|
-
it 'should have .keys for iterating by root keys of the configuration file' do
|
130
|
-
expect(Options2.keys.size).to eq(2)
|
131
|
-
expect(Options2.keys).to include(:group1)
|
132
|
-
expect(Options2.keys).to include(:group2)
|
133
|
-
end
|
134
134
|
end
|
135
135
|
|
136
136
|
describe SimpleConf do
|