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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e3d3bf439e6c3bd3b03269a0b1b078df324550a
4
- data.tar.gz: 43daf4430f1496b7444becd4619db45a1f5c47ea
3
+ metadata.gz: 8d4f9e38fad557846381e381d476b3d77b2a1526
4
+ data.tar.gz: 047627971b6952d362239444bca9bf8da6b5dcf9
5
5
  SHA512:
6
- metadata.gz: 3eb73cfbddb9a59a929c1e6a27dc5087830c48733077f584f77cc974c72a0f5661ae2a42d78899ecec9c3e9bba3ddb134bffae771442258a8fa8eb31b08e61a8
7
- data.tar.gz: ec5253b3eb128f50420befe89f40a9855b22a60638fb323a9fba34f16a7744dfa5eaab1a5522e6442b682de3863022445839376da96c4f193c0cc7ce5817f423
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/dryrb/chat" target="_blank">![Join the chat at https://gitter.im/dryrb/chat](https://badges.gitter.im/Join%20Chat.svg)</a>
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/dryrb/dry-container" target="_blank">![Build Status](https://travis-ci.org/dryrb/dry-container.svg?branch=master)</a>
5
- <a href="https://gemnasium.com/dryrb/dry-container" target="_blank">![Dependency Status](https://gemnasium.com/dryrb/dry-container.svg)</a>
6
- <a href="https://codeclimate.com/github/dryrb/dry-container" target="_blank">![Code Climate](https://codeclimate.com/github/dryrb/dry-container/badges/gpa.svg)</a>
7
- <a href="http://inch-ci.org/github/dryrb/dry-container" target="_blank">![Documentation Status](http://inch-ci.org/github/dryrb/dry-container.svg?branch=master&style=flat)</a>
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 = ThreadSafe::Cache.new.tap do |ds|
31
- ds[:users] = ThreadSafe::Array.new
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') { ThreadSafe::Array.new }
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') { ThreadSafe::Array.new }
81
+ register('users') { Concurrent::Array.new }
82
82
  end
83
83
  end
84
84
  container.import(ns)
@@ -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 'thread_safe'
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
@@ -1,4 +1,4 @@
1
- require 'thread_safe'
1
+ require 'concurrent'
2
2
  require 'dry-configurable'
3
3
  require 'dry/container/error'
4
4
  require 'dry/container/item'
@@ -35,7 +35,7 @@ module Dry
35
35
  setting :resolver, ::Dry::Container::Resolver.new
36
36
  setting :namespace_separator, '.'
37
37
 
38
- @_container = ::ThreadSafe::Hash.new
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 = ::ThreadSafe::Hash.new
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
- alias [] resolve
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 [ThreadSafe::Hash] container
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 [ThreadSafe::Hash] container
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 [ThreadSafe::Hash] container
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
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  class Container
3
3
  # @api public
4
- VERSION = '0.3.0'.freeze
4
+ VERSION = '0.3.1'.freeze
5
5
  end
6
6
  end
@@ -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.0
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-07 00:00:00.000000000 Z
11
+ date: 2016-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thread_safe
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