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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe732b8904f1e9a3fa01f901618ea841b24fa35e
4
- data.tar.gz: b5bd5f10972da2af169f21c71c12d174e8d3c2ce
3
+ metadata.gz: 39be9de9a8fa72ac20c65f44c1acd4841194e7a5
4
+ data.tar.gz: 100bf923f66e6192f928d9ba1aa5b281f1e5fb2d
5
5
  SHA512:
6
- metadata.gz: ff0a71be24d0dc6f7c119030976cb11f144baf87a3d8fc6e1ccae28038d03794fb8b83de62d1c87475518da52840f7609f0aa0e952df025a717850e25ac7eb05
7
- data.tar.gz: fdaaf9786d8ac6bc104e97f1999946010540473aea18922b0ea480e3d03ff7ab6f4a745cf4b82444ab36b150060fe63a8074ae40409dcda62e08cdcc31d422dc
6
+ metadata.gz: 552724072d2986a4cad3a0c7b79d8bf28b4fd7e4dade6f24f1d6436cf3d01ce10843a56ce34f95baaa272fed372ef4d2013a277c1545f3d907bebb99d87665c0
7
+ data.tar.gz: 05e2dd79945c529363d84f68ec023a4af07a2ac93ea8287a6f56adf03c4f6890ea9e12a30465d2c0e020039914854a5bbac6f5749e9dd69e4ef4435288322e84
@@ -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 @options[:interpolation]
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 @options[:symbolize]
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 @options[:symbolize]
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)
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Config
3
- VERSION = '1.2.0'
3
+ VERSION = '1.2.1'
4
4
  end
5
5
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-config
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
  - Kevin Ross