dry-container 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 +4 -4
- data/README.md +9 -9
- data/dry-container.gemspec +1 -1
- data/lib/dry/container.rb +1 -1
- data/lib/dry/container/mixin.rb +15 -3
- data/lib/dry/container/registry.rb +1 -1
- data/lib/dry/container/resolver.rb +2 -2
- data/lib/dry/container/version.rb +1 -1
- data/spec/support/shared_examples/container.rb +3 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d4f9e38fad557846381e381d476b3d77b2a1526
|
4
|
+
data.tar.gz: 047627971b6952d362239444bca9bf8da6b5dcf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2baba42774a6c6baf3ea1a040ae74d1f0931789b00cfce9cfa288702a70b25bc17e344b45cd52a8d8c6269d6a5cb3f1a6735fe841e91e097a29b692e3a1e76bf
|
7
|
+
data.tar.gz: 640c1be2570fe6fbdda1cf380cf76071d3b4ba1b9bb5d5b9ca5af45eed8e0c310eafb991178c6ece3913734ad8e1cc2bd911f8b4fad3337b60e31b9d0386f494
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# dry-container <a href="https://gitter.im/
|
1
|
+
# dry-container <a href="https://gitter.im/dry-rb/chat" target="_blank">![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)</a>
|
2
2
|
|
3
3
|
<a href="https://rubygems.org/gems/dry-container" target="_blank">![Gem Version](https://badge.fury.io/rb/dry-container.svg)</a>
|
4
|
-
<a href="https://travis-ci.org/
|
5
|
-
<a href="https://gemnasium.com/
|
6
|
-
<a href="https://codeclimate.com/github/
|
7
|
-
<a href="http://inch-ci.org/github/
|
4
|
+
<a href="https://travis-ci.org/dry-rb/dry-container" target="_blank">![Build Status](https://travis-ci.org/dry-rb/dry-container.svg?branch=master)</a>
|
5
|
+
<a href="https://gemnasium.com/dry-rb/dry-container" target="_blank">![Dependency Status](https://gemnasium.com/dry-rb/dry-container.svg)</a>
|
6
|
+
<a href="https://codeclimate.com/github/dry-rb/dry-container" target="_blank">![Code Climate](https://codeclimate.com/github/dry-rb/dry-container/badges/gpa.svg)</a>
|
7
|
+
<a href="http://inch-ci.org/github/dry-rb/dry-container" target="_blank">![Documentation Status](http://inch-ci.org/github/dry-rb/dry-container.svg?branch=master&style=flat)</a>
|
8
8
|
|
9
9
|
A simple, configurable container implemented in Ruby
|
10
10
|
|
@@ -27,8 +27,8 @@ parrot.call("Hello World")
|
|
27
27
|
```ruby
|
28
28
|
User = Struct.new(:name, :email)
|
29
29
|
|
30
|
-
data_store =
|
31
|
-
ds[:users] =
|
30
|
+
data_store = Concurrent::Map.new.tap do |ds|
|
31
|
+
ds[:users] = Concurrent::Array.new
|
32
32
|
end
|
33
33
|
|
34
34
|
# Initialize container
|
@@ -69,7 +69,7 @@ container.resolve(:block)
|
|
69
69
|
# You can also register items under namespaces using the #namespace method
|
70
70
|
container.namespace('repositories') do
|
71
71
|
namespace('checkout') do
|
72
|
-
register('orders') {
|
72
|
+
register('orders') { Concurrent::Array.new }
|
73
73
|
end
|
74
74
|
end
|
75
75
|
container.resolve('repositories.checkout.orders')
|
@@ -78,7 +78,7 @@ container.resolve('repositories.checkout.orders')
|
|
78
78
|
# Or import a namespace
|
79
79
|
ns = Dry::Container::Namespace.new('repositories') do
|
80
80
|
namespace('authentication') do
|
81
|
-
register('users') {
|
81
|
+
register('users') { Concurrent::Array.new }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
container.import(ns)
|
data/dry-container.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
|
18
|
-
spec.add_runtime_dependency '
|
18
|
+
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
19
19
|
spec.add_runtime_dependency 'dry-configurable', '~> 0.1', '>= 0.1.3'
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler'
|
data/lib/dry/container.rb
CHANGED
data/lib/dry/container/mixin.rb
CHANGED
@@ -35,7 +35,7 @@ module Dry
|
|
35
35
|
setting :resolver, ::Dry::Container::Resolver.new
|
36
36
|
setting :namespace_separator, '.'
|
37
37
|
|
38
|
-
@_container = ::
|
38
|
+
@_container = ::Concurrent::Hash.new
|
39
39
|
|
40
40
|
def self.inherited(subclass)
|
41
41
|
subclass.instance_variable_set(:@_container, @_container.dup)
|
@@ -56,7 +56,7 @@ module Dry
|
|
56
56
|
attr_reader :_container
|
57
57
|
|
58
58
|
def initialize(*args, &block)
|
59
|
-
@_container = ::
|
59
|
+
@_container = ::Concurrent::Hash.new
|
60
60
|
super(*args, &block)
|
61
61
|
end
|
62
62
|
|
@@ -105,7 +105,19 @@ module Dry
|
|
105
105
|
def resolve(key)
|
106
106
|
config.resolver.call(_container, key)
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
|
+
# Resolve an item from the container
|
110
|
+
#
|
111
|
+
# @param [Mixed] key
|
112
|
+
# The key for the item you wish to resolve
|
113
|
+
#
|
114
|
+
# @return [Mixed]
|
115
|
+
#
|
116
|
+
# @api public
|
117
|
+
# @see Dry::Container::Mixin#resolve
|
118
|
+
def [](key)
|
119
|
+
resolve(key)
|
120
|
+
end
|
109
121
|
|
110
122
|
# Merge in the items of the other container
|
111
123
|
#
|
@@ -11,7 +11,7 @@ module Dry
|
|
11
11
|
|
12
12
|
# Register an item with the container to be resolved later
|
13
13
|
#
|
14
|
-
# @param [
|
14
|
+
# @param [Concurrent::Hash] container
|
15
15
|
# The container
|
16
16
|
# @param [Mixed] key
|
17
17
|
# The key to register the container item with (used to resolve)
|
@@ -6,7 +6,7 @@ module Dry
|
|
6
6
|
class Resolver
|
7
7
|
# Resolve an item from the container
|
8
8
|
#
|
9
|
-
# @param [
|
9
|
+
# @param [Concurrent::Hash] container
|
10
10
|
# The container
|
11
11
|
# @param [Mixed] key
|
12
12
|
# The key for the item you wish to resolve
|
@@ -27,7 +27,7 @@ module Dry
|
|
27
27
|
|
28
28
|
# Check whether an items is registered under the given key
|
29
29
|
#
|
30
|
-
# @param [
|
30
|
+
# @param [Concurrent::Hash] container
|
31
31
|
# The container
|
32
32
|
# @param [Mixed] key
|
33
33
|
# The key you wish to check for registration with
|
@@ -329,11 +329,13 @@ shared_examples 'a container' do
|
|
329
329
|
it 'keys can be stubbed' do
|
330
330
|
container.stub(:item, 'stub')
|
331
331
|
expect(container.resolve(:item)).to eql('stub')
|
332
|
+
expect(container[:item]).to eql('stub')
|
332
333
|
end
|
333
334
|
|
334
335
|
it 'only other keys remain accesible' do
|
335
336
|
container.stub(:item, 'stub')
|
336
337
|
expect(container.resolve(:foo)).to eql('bar')
|
338
|
+
expect(container[:foo]).to eql('bar')
|
337
339
|
end
|
338
340
|
|
339
341
|
it 'keys can be reverted back to their original value' do
|
@@ -341,6 +343,7 @@ shared_examples 'a container' do
|
|
341
343
|
container.unstub(:item)
|
342
344
|
|
343
345
|
expect(container.resolve(:item)).to eql('item')
|
346
|
+
expect(container[:item]).to eql('item')
|
344
347
|
end
|
345
348
|
|
346
349
|
describe 'with block argument' do
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
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-03-
|
11
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: concurrent-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dry-configurable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|