dry-container 0.2.4 → 0.2.5

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: b9d5dcf90fab6c72fb271675c0f9b503de608c99
4
- data.tar.gz: 8badbe2f97c47f1c35c58fa3ce5b0c96a33d1028
3
+ metadata.gz: d052fd82bb7597ea5b8c8b35a2c26b4900f16b02
4
+ data.tar.gz: 47681932e60338aa93f70417de441d8bc21f52d7
5
5
  SHA512:
6
- metadata.gz: f77c0db7d4dbdb22072d9bb19930d14841a2bd970996f66d7791a5443669674c770f03f7e4019986197c7bb6fdd24a554387e6716e6d778b38bf768bbaaa2df0
7
- data.tar.gz: 3a813c8425288428f7cb963ff1f16222b094c4ebcda8db8cd3aeb3a8216e2532bf081e492bda49c4171bee7a178a3267889cb34c7c44b00e940e43c9d05440b5
6
+ metadata.gz: 6ae27a601b7e9ff4574761c43de2328d9ce58c467cd121ef9509b66977a1e171894f3694a4bb8e0308428fc6d33b37519b03ccdac598d9f9b1c142e2fa5409e3
7
+ data.tar.gz: ff561063839573816a19f1a96a813dda03bb2eea833c7d964c9b2725e79f2047994f72fe1cb05638c0b9c53e9faba56762e78345667eaa2c1331f42354dc1035
@@ -106,6 +106,19 @@ module Dry
106
106
  config.resolver.call(_container, key)
107
107
  end
108
108
  alias_method :[], :resolve
109
+
110
+ # Check whether an items is registered under the given key
111
+ #
112
+ # @param [Mixed] key
113
+ # The key you wish to check for registration with
114
+ #
115
+ # @return [Bool]
116
+ #
117
+ # @api public
118
+ def key?(key)
119
+ config.resolver.key?(_container, key)
120
+ end
121
+
109
122
  # Evaluate block and register items in namespace
110
123
  #
111
124
  # @param [Mixed] namespace
@@ -32,6 +32,7 @@ module Dry
32
32
  if container.key?(key)
33
33
  fail Error, "There is already an item registered with the key #{key.inspect}"
34
34
  else
35
+ key = key.is_a?(::String) ? key.dup.freeze : key
35
36
  container[key] = ::Dry::Container::Item.new(item, options)
36
37
  end
37
38
  end
@@ -24,6 +24,20 @@ module Dry
24
24
 
25
25
  item.call
26
26
  end
27
+
28
+ # Check whether an items is registered under the given key
29
+ #
30
+ # @param [ThreadSafe::Hash] container
31
+ # The container
32
+ # @param [Mixed] key
33
+ # The key you wish to check for registration with
34
+ #
35
+ # @return [Bool]
36
+ #
37
+ # @api public
38
+ def key?(container, key)
39
+ container.key?(key)
40
+ end
27
41
  end
28
42
  end
29
43
  end
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  class Container
3
3
  # @api public
4
- VERSION = '0.2.4'.freeze
4
+ VERSION = '0.2.5'.freeze
5
5
  end
6
6
  end
@@ -116,6 +116,7 @@ shared_examples 'a container' do
116
116
  it 'registers and resolves an object' do
117
117
  container.register(:item) { 'item' }
118
118
 
119
+ expect(container.key?(:item)).to be true
119
120
  expect(container.resolve(:item)).to eq('item')
120
121
  end
121
122
  end
@@ -133,6 +134,7 @@ shared_examples 'a container' do
133
134
  it 'registers and resolves a proc' do
134
135
  container.register(:item, call: false) { 'item' }
135
136
 
137
+ expect(container.key?(:item)).to be true
136
138
  expect(container.resolve(:item).call).to eq('item')
137
139
  expect(container[:item].call).to eq('item')
138
140
  end
@@ -145,6 +147,7 @@ shared_examples 'a container' do
145
147
  it 'registers and resolves an object' do
146
148
  container.register(:item, proc { 'item' })
147
149
 
150
+ expect(container.key?(:item)).to be true
148
151
  expect(container.resolve(:item)).to eq('item')
149
152
  expect(container[:item]).to eq('item')
150
153
  end
@@ -154,6 +157,7 @@ shared_examples 'a container' do
154
157
  it 'registers and resolves a proc' do
155
158
  container.register(:item, proc { |item| item })
156
159
 
160
+ expect(container.key?(:item)).to be true
157
161
  expect(container.resolve(:item).call('item')).to eq('item')
158
162
  expect(container[:item].call('item')).to eq('item')
159
163
  end
@@ -164,6 +168,7 @@ shared_examples 'a container' do
164
168
  it 'registers and resolves a proc' do
165
169
  container.register(:item, proc { 'item' }, call: false)
166
170
 
171
+ expect(container.key?(:item)).to be true
167
172
  expect(container.resolve(:item).call).to eq('item')
168
173
  expect(container[:item].call).to eq('item')
169
174
  end
@@ -176,6 +181,7 @@ shared_examples 'a container' do
176
181
  item = 'item'
177
182
  container.register(:item, item)
178
183
 
184
+ expect(container.key?(:item)).to be true
179
185
  expect(container.resolve(:item)).to be(item)
180
186
  expect(container[:item]).to be(item)
181
187
  end
@@ -186,6 +192,7 @@ shared_examples 'a container' do
186
192
  item = -> { 'test' }
187
193
  container.register(:item, item, call: false)
188
194
 
195
+ expect(container.key?(:item)).to be true
189
196
  expect(container.resolve(:item)).to eq(item)
190
197
  expect(container[:item]).to eq(item)
191
198
  end
@@ -202,6 +209,7 @@ shared_examples 'a container' do
202
209
 
203
210
  describe 'resolving with a key that has not been registered' do
204
211
  it do
212
+ expect(container.key?(:item)).to be false
205
213
  expect { container.resolve(:item) }.to raise_error(Dry::Container::Error)
206
214
  end
207
215
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-19 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_safe
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.4.5.1
135
+ rubygems_version: 2.4.5
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: A simple container intended for use as an IoC container
@@ -141,3 +141,4 @@ test_files:
141
141
  - spec/integration/mixin_spec.rb
142
142
  - spec/spec_helper.rb
143
143
  - spec/support/shared_examples/container.rb
144
+ has_rdoc: