dry-config 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 +4 -4
- data/lib/dry/config/base.rb +24 -3
- data/lib/dry/config/version.rb +1 -1
- data/spec/dry/config/base_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39be9de9a8fa72ac20c65f44c1acd4841194e7a5
|
4
|
+
data.tar.gz: 100bf923f66e6192f928d9ba1aa5b281f1e5fb2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 552724072d2986a4cad3a0c7b79d8bf28b4fd7e4dade6f24f1d6436cf3d01ce10843a56ce34f95baaa272fed372ef4d2013a277c1545f3d907bebb99d87665c0
|
7
|
+
data.tar.gz: 05e2dd79945c529363d84f68ec023a4af07a2ac93ea8287a6f56adf03c4f6890ea9e12a30465d2c0e020039914854a5bbac6f5749e9dd69e4ef4435288322e84
|
data/lib/dry/config/base.rb
CHANGED
@@ -91,7 +91,7 @@ module Dry
|
|
91
91
|
file = File.open(filename, 'r:bom|utf-8')
|
92
92
|
contents = file.read
|
93
93
|
|
94
|
-
if
|
94
|
+
if interpolate?
|
95
95
|
# interpolate/substitute/expand ENV variables with the string contents before parsing
|
96
96
|
# bash - $VAR
|
97
97
|
contents = contents.gsub(/\$(\w+)/) { ENV[$1] }
|
@@ -106,10 +106,11 @@ module Dry
|
|
106
106
|
config = Psych.load(contents, filename)
|
107
107
|
|
108
108
|
raise "Failed to load #{filename}" if config.nil?
|
109
|
-
config = config.deep_symbolize if
|
109
|
+
config = config.deep_symbolize if symbolize?
|
110
110
|
config
|
111
111
|
end
|
112
112
|
|
113
|
+
|
113
114
|
def write_yaml_file(filename)
|
114
115
|
File.open(filename, 'w') do |file|
|
115
116
|
file.write(Psych.dump(@configuration))
|
@@ -124,7 +125,7 @@ module Dry
|
|
124
125
|
def clear
|
125
126
|
# clone a copy of the default
|
126
127
|
@configuration = {}.merge @default_configuration
|
127
|
-
@configuration.deep_symbolize if
|
128
|
+
@configuration.deep_symbolize if symbolize?
|
128
129
|
end
|
129
130
|
|
130
131
|
def method_missing(name, *args, &block)
|
@@ -133,6 +134,26 @@ module Dry
|
|
133
134
|
nil
|
134
135
|
end
|
135
136
|
|
137
|
+
# configuration hash delegation
|
138
|
+
def [] key
|
139
|
+
key = key.to_sym if symbolize?
|
140
|
+
@configuration[key]
|
141
|
+
end
|
142
|
+
|
143
|
+
# configuration hash delegation
|
144
|
+
def []=(key, value)
|
145
|
+
key = key.to_sym if symbolize?
|
146
|
+
@configuration[key] = value
|
147
|
+
end
|
148
|
+
|
149
|
+
def symbolize?
|
150
|
+
@options[:symbolize]
|
151
|
+
end
|
152
|
+
|
153
|
+
def interpolate?
|
154
|
+
@options[:interpolation]
|
155
|
+
end
|
156
|
+
|
136
157
|
private
|
137
158
|
|
138
159
|
def deep_merge!(target, overrides)
|
data/lib/dry/config/version.rb
CHANGED
@@ -43,6 +43,20 @@ describe Dry::Config::Base do
|
|
43
43
|
expect(acmeConfig.production).to be_nil
|
44
44
|
end
|
45
45
|
|
46
|
+
|
47
|
+
it 'hash delegation to setter/getter' do
|
48
|
+
acmeConfig.clear
|
49
|
+
acmeConfig.load!(nil, config_file_path)
|
50
|
+
expect(acmeConfig.symbolize?).to be_truthy
|
51
|
+
|
52
|
+
acmeConfig['foo'] = 'bar'
|
53
|
+
expect(acmeConfig.configuration['foo']).to be_nil # no symbolization on direct access
|
54
|
+
expect(acmeConfig['foo']).to eq 'bar' # symbolization based on options
|
55
|
+
|
56
|
+
expect(acmeConfig.configuration[:foo]).to eq 'bar' # setter symbolizes, this works
|
57
|
+
expect(acmeConfig[:foo]).to eq 'bar'
|
58
|
+
end
|
59
|
+
|
46
60
|
context 'when loading a single configuration file' do
|
47
61
|
|
48
62
|
it 'should read file with nil environment' do
|