dry-configurable 0.4.0 → 0.5.0

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: ce548cd2fd8336b1a9aa14e96f4ad1a8b49709b1
4
- data.tar.gz: e67a56b52da574d789d50912ceb49162c3b68c4f
3
+ metadata.gz: e4cbef88b095851ec643863da9c0fd42cc5cf54f
4
+ data.tar.gz: bde6842ae91242766940d9304d6ac82c0ceaabec
5
5
  SHA512:
6
- metadata.gz: c81003e13f0ffe3ef45853a3692491c2c1f142ab3f9cde250adfd4064f68e06330f5281aca303013daf9ddd0e93e276d9f36a2a10122fb7ebb6fd461d305fdc0
7
- data.tar.gz: 0a64e0ce70d1577a537bbf44c6f4b97cb270d82c71ad0582f4fafa6734161308e0ee244a2a65233301d4f77ca49a515b98b02d4a729cae2053ca3444570a9fef
6
+ metadata.gz: f8233d5a3b57bda025a6cd5492f805201c7cdbc8695dc5c664fe6aef0f07bdb08a3732cc8ce5747ea01b0f0acdb3e9967760ee10a6d3f0f0c06ae0ddc621b76e
7
+ data.tar.gz: f865d739bd8f32ca49c208ca0291a463d71dfde39e67b7c8a85e4489150a8a3560b853d8093b9413859e3bbe24cfe43a888281c3f03b638053de860c1176df78
@@ -56,6 +56,26 @@ module Dry
56
56
  end
57
57
  end
58
58
  alias to_hash to_h
59
+
60
+ def [](name)
61
+ raise_unknown_setting_error(name) unless setting?(name)
62
+ public_send(name)
63
+ end
64
+
65
+ def []=(name, value)
66
+ raise_unknown_setting_error(name) unless setting?(name)
67
+ public_send("#{name}=", value)
68
+ end
69
+
70
+ private
71
+
72
+ def raise_unknown_setting_error(name)
73
+ raise ArgumentError, "+#{name}+ is not a setting name"
74
+ end
75
+
76
+ def setting?(name)
77
+ @config.key?(name.to_sym)
78
+ end
59
79
  end
60
80
  end
61
81
  end
@@ -9,7 +9,7 @@ module Dry
9
9
  attr_reader :name, :processor
10
10
 
11
11
  def initialize(name, value, processor)
12
- @name, @value, @processor = name, value, processor
12
+ @name, @value, @processor = name.to_sym, value, processor
13
13
  end
14
14
 
15
15
  def value
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  module Configurable
3
3
  # @api public
4
- VERSION = '0.4.0'.freeze
4
+ VERSION = '0.5.0'.freeze
5
5
  end
6
6
  end
@@ -5,6 +5,14 @@ RSpec.describe Dry::Configurable::Config::Value do
5
5
  let(:value) { 'test' }
6
6
  let(:processor) { ->(v) { v }}
7
7
 
8
+ describe '#initialize' do
9
+ it 'coerces string name to symbol' do
10
+ config = klass.new('db', value, processor)
11
+
12
+ expect(config.name).to eq(:db)
13
+ end
14
+ end
15
+
8
16
  describe '#name' do
9
17
  subject! { config.name }
10
18
 
@@ -128,4 +128,48 @@ RSpec.describe Dry::Configurable::Config do
128
128
  end
129
129
  end
130
130
  end
131
+
132
+ describe '#[]' do
133
+ it 'returns given setting' do
134
+ expect(config[:db]).to eq('sqlite:memory')
135
+ expect(config[:user]).to eq('root')
136
+ expect(config[:pass]).to be(nil)
137
+ end
138
+
139
+ it 'raises an ArgumentError when setting does not exist' do
140
+ expect { config[:unknown] }.to raise_error(
141
+ ArgumentError, '+unknown+ is not a setting name'
142
+ )
143
+ end
144
+
145
+ it 'accepts setting name as a string' do
146
+ expect(config['user']).to eq('root')
147
+ end
148
+ end
149
+
150
+ describe '#[]=' do
151
+ it 'sets given setting' do
152
+ expect { config[:db] = 'ineedm0ar' }.to change(config, :db)
153
+ .from('sqlite:memory')
154
+ .to('ineedm0ar:memory')
155
+ expect { config[:user] = 'whoami' }.to change(config, :user)
156
+ .from('root')
157
+ .to('whoami')
158
+ expect { config[:pass] = 'h4xz0rz' }.to change(config, :pass)
159
+ .from(nil)
160
+ .to('h4xz0rz')
161
+ end
162
+
163
+ it 'raises an ArgumentError when setting does not exist' do
164
+ expect { config[:unknown] = 'unknown' }.to raise_error(
165
+ ArgumentError, '+unknown+ is not a setting name'
166
+ )
167
+ end
168
+
169
+ it 'accepts setting name as a string' do
170
+ expect { config['user'] = 'whoami' }.to change(config, :user)
171
+ .from('root')
172
+ .to('whoami')
173
+ end
174
+ end
131
175
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-configurable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2016-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby