dry-container 0.5.0 → 0.6.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: 2f11ec3380a6ff086362780a67b687935cff8ddf
4
- data.tar.gz: 15db84953170fdc3f249d852d01d106f7a904f23
3
+ metadata.gz: 35fd3e8023c0220150dade45164cdefbe011633c
4
+ data.tar.gz: 4060a17b5831ef9c1fe7aa4440e0c34ef7d8fb4e
5
5
  SHA512:
6
- metadata.gz: f36ffd98d0c80ffd158e1554a09dd89919aeb7c780010a276118ad217db89d9ace865746c18b97321b6022d75dc5a4e46523d27927cd01ee182d0bb3b6b105b8
7
- data.tar.gz: 7b52ee74e85b40edad15d082ad5fc64a20a00947a8d97d472be013f4f98fe363be5c25f007cd6d089582d0302034b35ed0041ce843e276c896100a9775a2a14a
6
+ metadata.gz: 9e1f8876a5ea3cdb77b8516e1d85481ed86b58d70c8d41aa77d71c45fbf30bdd1b4c226a60a50a0795fde809934461a8c72ff6225b6a2b4b9bd6e468cb369709
7
+ data.tar.gz: bf68f2feb7608a30d851f69c7e370741a0cf2af50e539abe027cad53ce3714b7965b8964266b5e045fabb43fcdcb6f86f95b9398de874b8f7752cf4c56797558
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ bin/
6
6
  tmp/
7
7
  .idea/
8
8
  Gemfile.lock
9
+ spec/examples.txt
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --require spec_helper
3
- --order random
2
+ --require ./spec/spec_helper.rb
data/.travis.yml CHANGED
@@ -1,26 +1,29 @@
1
1
  language: ruby
2
- sudo: false
2
+ dist: trusty
3
+ sudo: required
3
4
  cache: bundler
4
5
  bundler_args: --without console
5
6
  script:
6
7
  - bundle exec rake spec
8
+ after_success:
9
+ - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
7
10
  rvm:
8
11
  - 2.0
9
12
  - 2.1
10
13
  - 2.2
11
- - rbx-2
14
+ - 2.3.1
15
+ - rbx-3
16
+ - jruby-9.1.5.0
12
17
  - ruby-head
13
18
  - jruby-head
14
19
  env:
15
20
  global:
16
21
  - JRUBY_OPTS='--dev -J-Xmx1024M'
22
+ - COVERAGE='true'
17
23
  matrix:
18
24
  allow_failures:
19
25
  - rvm: ruby-head
20
26
  - rvm: jruby-head
21
- include:
22
- - rvm: jruby-9.0.0.0
23
- before_install: rvm get master && rvm install jruby-9.0.0.0 && gem install bundler --no-ri --no-rdoc
24
27
  notifications:
25
28
  email: false
26
29
  webhooks:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Unreleased
2
+
3
+ ## Added
4
+
5
+ * `Dry::Container::Mixin#each` - provides a means of seeing what all is registered in the container ([jeremyf](https://github.com/jeremyf))
6
+
1
7
  ## v0.5.0
2
8
 
3
9
  ## Added
@@ -8,4 +14,4 @@
8
14
 
9
15
  * `required_ruby_version` set to `>= 2.0.0` ([artofhuman](https://github.com/artofhuman))
10
16
 
11
- [Compare v0.4.0...HEAD](https://github.com/dry-rb/dry-container/compare/v0.4.0...HEAD)
17
+ [Compare v0.4.0...HEAD](https://github.com/dry-rb/dry-container/compare/v0.4.0...v0.5.0)
data/Gemfile CHANGED
@@ -3,7 +3,10 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem 'codeclimate-test-reporter', platform: :rbx, require: false
6
+ platforms :mri do
7
+ gem 'codeclimate-test-reporter', require: false
8
+ gem 'simplecov', require: false
9
+ end
7
10
  end
8
11
 
9
12
  group :tools do
data/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  [![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-container.svg)][inch]
14
14
 
15
15
 
16
- A simple, configurable container implemented in Ruby
16
+ A simple, configurable container implemented in Ruby.
17
17
 
18
18
  ## Synopsis
19
19
 
@@ -29,6 +29,8 @@ parrot.call("Hello World")
29
29
  # => nil
30
30
  ```
31
31
 
32
+ See [Dry::AutoInject Usage](https://github.com/dry-rb/dry-auto_inject#usage) for additional details.
33
+
32
34
  ### Detailed Example
33
35
 
34
36
  ```ruby
@@ -48,20 +48,24 @@ module Dry
48
48
  end
49
49
  end
50
50
 
51
+ # @private
52
+ module Initializer
53
+ def initialize(*args, &block)
54
+ @_container = ::Concurrent::Hash.new
55
+ super
56
+ end
57
+ end
58
+
51
59
  # @private
52
60
  def self.included(base)
53
61
  base.class_eval do
54
62
  extend ::Dry::Configurable
63
+ prepend Initializer
55
64
 
56
65
  setting :registry, ::Dry::Container::Registry.new
57
66
  setting :resolver, ::Dry::Container::Resolver.new
58
67
  setting :namespace_separator, '.'
59
68
 
60
- def initialize(*args, &block)
61
- @_container = ::Concurrent::Hash.new
62
- super(*args, &block)
63
- end
64
-
65
69
  def config
66
70
  self.class.config
67
71
  end
@@ -179,6 +183,21 @@ module Dry
179
183
  self
180
184
  end
181
185
 
186
+ # Calls block once for each key/value pair in the container, passing the key and the registered item parameters.
187
+ #
188
+ # If no block is given, an enumerator is returned instead.
189
+ #
190
+ # @return [Enumerator]
191
+ #
192
+ # @api public
193
+ #
194
+ # @note In discussions with other developers, it was felt that being able to iterate over not just
195
+ # the registered keys, but to see what was registered would be very helpful. This is a step
196
+ # toward doing that.
197
+ def each(&block)
198
+ config.resolver.each(_container, &block)
199
+ end
200
+
182
201
  # Evaluate block and register items in namespace
183
202
  #
184
203
  # @param [Mixed] namespace
@@ -59,6 +59,20 @@ module Dry
59
59
  def each_key(container, &block)
60
60
  container.each_key(&block)
61
61
  end
62
+
63
+ # Calls block once for each key in container, passing the key and the registered item parameters.
64
+ #
65
+ # If no block is given, an enumerator is returned instead.
66
+ #
67
+ # @return Key, Value
68
+ #
69
+ # @api public
70
+ # @note In discussions with other developers, it was felt that being able to iterate over not just
71
+ # the registered keys, but to see what was registered would be very helpful. This is a step
72
+ # toward doing that.
73
+ def each(container, &block)
74
+ container.map { |key, value| [key, value.call] }.each(&block)
75
+ end
62
76
  end
63
77
  end
64
78
  end
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  class Container
3
3
  # @api public
4
- VERSION = '0.5.0'.freeze
4
+ VERSION = '0.6.0'.freeze
5
5
  end
6
6
  end
@@ -15,5 +15,18 @@ RSpec.describe Dry::Container::Mixin do
15
15
  let(:container) { klass.new }
16
16
 
17
17
  it_behaves_like 'a container'
18
+
19
+ context 'into a class with a custom .initialize method' do
20
+ let(:klass) do
21
+ Class.new do
22
+ include Dry::Container::Mixin
23
+ def initialize; end
24
+ end
25
+ end
26
+
27
+ it 'does not fail on missing member variable' do
28
+ expect { container.register :key, ->{} }.to_not raise_error
29
+ end
30
+ end
18
31
  end
19
32
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,87 @@
1
- # encoding: utf-8
1
+ if ENV['COVERAGE'] == 'true' && RUBY_ENGINE == 'ruby' && RUBY_VERSION == '2.3.1'
2
+ require 'simplecov'
2
3
 
3
- if RUBY_ENGINE == 'rbx'
4
- require 'codeclimate-test-reporter'
5
- CodeClimate::TestReporter.start
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ end
7
+ end
8
+
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.expect_with :rspec do |expectations|
12
+ # This option will default to `true` in RSpec 4. It makes the `description`
13
+ # and `failure_message` of custom matchers include text for helper methods
14
+ # defined using `chain`, e.g.:
15
+ # be_bigger_than(2).and_smaller_than(4).description
16
+ # # => "be bigger than 2 and smaller than 4"
17
+ # ...rather than:
18
+ # # => "be bigger than 2"
19
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
20
+ end
21
+
22
+ config.mock_with :rspec do |mocks|
23
+ # Prevents you from mocking or stubbing a method that does not exist on
24
+ # a real object. This is generally recommended, and will default to
25
+ # `true` in RSpec 4.
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+
29
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
30
+ # have no way to turn it off -- the option exists only for backwards
31
+ # compatibility in RSpec 3). It causes shared context metadata to be
32
+ # inherited by the metadata hash of host groups and examples, rather than
33
+ # triggering implicit auto-inclusion in groups with matching metadata.
34
+ config.shared_context_metadata_behavior = :apply_to_host_groups
35
+
36
+ # This allows you to limit a spec run to individual examples or groups
37
+ # you care about by tagging them with `:focus` metadata. When nothing
38
+ # is tagged with `:focus`, all examples get run. RSpec also provides
39
+ # aliases for `it`, `describe`, and `context` that include `:focus`
40
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
41
+ config.filter_run_when_matching :focus
42
+
43
+ # Allows RSpec to persist some state between runs in order to support
44
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
45
+ # you configure your source control system to ignore this file.
46
+ config.example_status_persistence_file_path = "spec/examples.txt"
47
+
48
+ # Limits the available syntax to the non-monkey patched syntax that is
49
+ # recommended. For more details, see:
50
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
51
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
52
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
53
+ config.disable_monkey_patching!
54
+
55
+ # This setting enables warnings. It's recommended, but in some cases may
56
+ # be too noisy due to issues in dependencies.
57
+ config.warnings = true
58
+
59
+ # Many RSpec users commonly either run the entire suite or an individual
60
+ # file, and it's useful to allow more verbose output when running an
61
+ # individual spec file.
62
+ if config.files_to_run.one?
63
+ # Use the documentation formatter for detailed output,
64
+ # unless a formatter has already been configured
65
+ # (e.g. via a command-line flag).
66
+ config.default_formatter = 'doc'
67
+ end
68
+
69
+ # Print the n slowest examples and example groups at the
70
+ # end of the spec run, to help surface which specs are running
71
+ # particularly slow.
72
+ config.profile_examples = 3
73
+
74
+ # Run specs in random order to surface order dependencies. If you find an
75
+ # order dependency and want to debug it, you can fix the order by providing
76
+ # the seed, which is printed after each run.
77
+ # --seed 1234
78
+ config.order = :random
79
+
80
+ # Seed global randomization in this process using the `--seed` CLI option.
81
+ # Setting this allows you to use `--seed` to deterministically reproduce
82
+ # test failures related to randomization by passing the same `--seed` value
83
+ # as the one that triggered the failure.
84
+ Kernel.srand config.seed
6
85
  end
7
86
 
8
87
  require 'dry/container'
@@ -1,4 +1,4 @@
1
- shared_examples 'a container' do
1
+ RSpec.shared_examples 'a container' do
2
2
  describe 'configuration' do
3
3
  describe 'registry' do
4
4
  describe 'default' do
@@ -359,6 +359,30 @@ shared_examples 'a container' do
359
359
  end
360
360
  end
361
361
 
362
+ describe '#each' do
363
+ let(:keys) { [:key_1, :key_2] }
364
+ let(:expected_key_value_pairs) { [['key_1', 'value_for_key_1'], ['key_2', 'value_for_key_2']] }
365
+ let!(:yielded_key_value_pairs) { [] }
366
+
367
+ before do
368
+ keys.each do |key|
369
+ container.register(key) { "value_for_#{key}" }
370
+ end
371
+ end
372
+
373
+ subject! do
374
+ container.each { |key, value| yielded_key_value_pairs << [key, value] }
375
+ end
376
+
377
+ it 'yields stringified versions of all registered keys to the block' do
378
+ expect(yielded_key_value_pairs).to match_array(expected_key_value_pairs)
379
+ end
380
+
381
+ it 'returns the container' do
382
+ is_expected.to eq(expected_key_value_pairs)
383
+ end
384
+ end
385
+
362
386
  describe 'namespace' do
363
387
  context 'when block does not take arguments' do
364
388
  before do
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.5.0
4
+ version: 0.6.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-08-31 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby