dry-container 0.7.0 → 0.7.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
  SHA256:
3
- metadata.gz: d9983b02db6de06274a1233f9bfa5c0e8ab2c9df34fc15f2f801619912335265
4
- data.tar.gz: d34942c991fcee5e85e67fb7b345105726ed28a3fd0ef04524514b37739b8f4e
3
+ metadata.gz: 89386cb5792215d73c4b754921c1f5df7111f7d76a87f4fe7ad2777fd8c71abf
4
+ data.tar.gz: 24008af254d6531e665d49292f20c7ae7b483d67f97838b5c460df1d203f9987
5
5
  SHA512:
6
- metadata.gz: fab850d709bbcc1f22ee2b50c4dc59aa79773ce7bcdec40278aa7ac2a0df4780a3b2f82bb409a711de6a13a69a92a2bf591ff326df992129f9afcd4578403242
7
- data.tar.gz: 1f258852df4376546fbf2ce5ee1cabb14d97d6e434c9c94df5568c689aae2debbd4406d2f657703901a0001caa73df1850475fc532579395d1895efb2be3dc76
6
+ metadata.gz: 89350f42cdabd64616241d100c760c385f53bc0a9ba3baf662b575b34beaed06ca33d4fce40f8497a72505b0fda28ee9cc9874dbed3ee91df02363517d0a8f13
7
+ data.tar.gz: af233252c5c04f68650c89ed65079028bc4a7a8636134c132379c60af13d1b2719fd77784931204864b3ce9e43b49bdc905034f84e59d90f7d885afc69638919
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ tmp/
7
7
  .idea/
8
8
  Gemfile.lock
9
9
  spec/examples.txt
10
+ pkg/
@@ -8,11 +8,14 @@ script:
8
8
  after_success:
9
9
  - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
10
10
  rvm:
11
- - 2.3.8
12
- - 2.4.5
13
- - 2.5.3
14
- - 2.6.1
15
- - jruby-9.2.5.0
11
+ - 2.4.6
12
+ - 2.5.5
13
+ - 2.6.3
14
+ - jruby-9.2.7.0
15
+ - truffleruby
16
+ matrix:
17
+ allow_failures:
18
+ - rvm: truffleruby
16
19
  env:
17
20
  global:
18
21
  - JRUBY_OPTS='--dev -J-Xmx1024M'
@@ -1,3 +1,11 @@
1
+ ## v0.7.1 - 2019-06-07
2
+
3
+ ## Fixed
4
+
5
+ * Added `Mixin#dup` and `Mixin#clone`, now copies don't share underlying containers (flash-gordon)
6
+
7
+ [Compare v0.7.0...0.7.1](https://github.com/dry-rb/dry-container/compare/v0.7.0...v0.7.1)
8
+
1
9
  ## v0.7.0 - 2019-02-05
2
10
 
3
11
  ## Changed
@@ -40,9 +48,9 @@
40
48
 
41
49
  * Handling container items was generalized in [#34](https://github.com/dry-rb/dry-container/pull/34) ([GabrielMalakias](https://github.com/GabrielMalakias))
42
50
 
43
- [Compare v0.6.0...HEAD](https://github.com/dry-rb/dry-container/compare/v0.6.0...v0.7.0)
51
+ [Compare v0.6.0...0.7.0](https://github.com/dry-rb/dry-container/compare/v0.6.0...v0.7.0)
44
52
 
45
- ## v0.6.0 - 2019-12-09
53
+ ## v0.6.0 - 2016-12-09
46
54
 
47
55
  ## Added
48
56
 
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- [gitter]: https://gitter.im/dry-rb/chat
2
1
  [gem]: https://rubygems.org/gems/dry-container
3
2
  [travis]: https://travis-ci.org/dry-rb/dry-container
4
3
  [maintainability]: https://codeclimate.com/github/dry-rb/dry-container/maintainability
5
4
  [test_coverage]: https://codeclimate.com/github/dry-rb/dry-container/test_coverage
6
5
  [inch]: http://inch-ci.org/github/dry-rb/dry-container
6
+ [chat]: https://dry-rb.zulipchat.com
7
7
 
8
- # dry-container [![Join the Gitter chat](https://badges.gitter.im/Join%20Chat.svg)][gitter]
8
+ # dry-container [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
9
 
10
10
  [![Gem Version](https://img.shields.io/gem/v/dry-container.svg)][gem]
11
11
  [![Build Status](https://img.shields.io/travis/dry-rb/dry-container.svg)][travis]
@@ -211,12 +211,17 @@ module Dry
211
211
  end
212
212
 
213
213
  decorator = with
214
+ memoize = original.is_a?(Item::Memoizable)
214
215
 
215
216
  if decorator.is_a?(Class)
216
- register(key, decorator.new(original.call))
217
+ decorated = -> { decorator.new(original.call) }
218
+ elsif decorator.respond_to?(:call)
219
+ decorated = -> { decorator.call(original.call) }
217
220
  else
218
- register(key, decorator)
221
+ raise Error, "Decorator needs to be a Class or responds to the `call` method"
219
222
  end
223
+
224
+ register(key, memoize: memoize, &decorated)
220
225
  end
221
226
 
222
227
  # Evaluate block and register items in namespace
@@ -265,6 +270,22 @@ module Dry
265
270
  def _container
266
271
  @_container
267
272
  end
273
+
274
+ # @api public
275
+ def dup
276
+ copy = super
277
+ copy.instance_variable_set(:@_container, _container.dup)
278
+ copy
279
+ end
280
+
281
+ # @api public
282
+ def clone
283
+ copy = super
284
+ unless copy.frozen?
285
+ copy.instance_variable_set(:@_container, _container.dup)
286
+ end
287
+ copy
288
+ end
268
289
  end
269
290
  end
270
291
  end
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  class Container
3
3
  # @api public
4
- VERSION = '0.7.0'.freeze
4
+ VERSION = '0.7.1'.freeze
5
5
  end
6
6
  end
@@ -1,3 +1,5 @@
1
+ # require 'pathname'
2
+
1
3
  if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
2
4
  require 'yaml'
3
5
  rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
@@ -387,16 +387,41 @@ RSpec.shared_examples 'a container' do
387
387
  require 'delegate'
388
388
 
389
389
  let(:key) { :key }
390
+ let(:decorated_class_spy) { spy(:decorated_class_spy) }
391
+ let(:decorated_class) { Class.new }
390
392
 
391
393
  context 'for callable item' do
392
394
  before do
393
- container.register(key) { "value" }
395
+ allow(decorated_class_spy).to receive(:new) { decorated_class.new }
396
+ container.register(key, memoize: memoize) { decorated_class_spy.new }
394
397
  container.decorate(key, with: SimpleDelegator)
395
398
  end
396
399
 
397
- it 'expected to be an instance of SimpleDelegator' do
398
- expect(container.resolve(key)).to be_instance_of(SimpleDelegator)
399
- expect(container.resolve(key).__getobj__).to eql("value")
400
+ context 'memoize false' do
401
+ let(:memoize) { false }
402
+
403
+ it 'does not call the block until the key is resolved' do
404
+ expect(decorated_class_spy).not_to have_received(:new)
405
+ container.resolve(key)
406
+ expect(decorated_class_spy).to have_received(:new)
407
+ end
408
+
409
+ specify do
410
+ expect(container[key]).to be_instance_of(SimpleDelegator)
411
+ expect(container[key].__getobj__).to be_instance_of(decorated_class)
412
+ expect(container[key]).not_to be(container[key])
413
+ expect(container[key].__getobj__).not_to be(container[key].__getobj__)
414
+ end
415
+ end
416
+
417
+ context 'memoize true' do
418
+ let(:memoize) { true }
419
+
420
+ specify do
421
+ expect(container[key]).to be_instance_of(SimpleDelegator)
422
+ expect(container[key].__getobj__).to be_instance_of(decorated_class)
423
+ expect(container[key]).to be(container[key])
424
+ end
400
425
  end
401
426
  end
402
427
 
@@ -411,6 +436,23 @@ RSpec.shared_examples 'a container' do
411
436
  expect(container.resolve(key).__getobj__.call).to eql("value")
412
437
  end
413
438
  end
439
+
440
+ context 'with an instance as a decorator' do
441
+ let(:decorator) do
442
+ double.tap do |decorator|
443
+ allow(decorator).to receive(:call) { |input| "decorated #{input}" }
444
+ end
445
+ end
446
+
447
+ before do
448
+ container.register(key) { "value" }
449
+ container.decorate(key, with: decorator)
450
+ end
451
+
452
+ it 'expected to pass original value to decorator#call method' do
453
+ expect(container.resolve(key)).to eq("decorated value")
454
+ end
455
+ end
414
456
  end
415
457
 
416
458
  describe 'namespace' do
@@ -574,4 +616,23 @@ RSpec.shared_examples 'a container' do
574
616
  expect(container.freeze).to be(container)
575
617
  end
576
618
  end
619
+
620
+ describe '.dup' do
621
+ it "returns a copy that doesn't share registered keys with the parent" do
622
+ container.dup.register(:foo, 'bar')
623
+ expect(container.key?(:foo)).to be false
624
+ end
625
+ end
626
+
627
+ describe '.clone' do
628
+ it "returns a copy that doesn't share registered keys with the parent" do
629
+ container.clone.register(:foo, 'bar')
630
+ expect(container.key?(:foo)).to be false
631
+ end
632
+
633
+ it 're-uses frozen container' do
634
+ expect(container.freeze.clone).to be_frozen
635
+ expect(container.clone._container).to be(container._container)
636
+ end
637
+ end
577
638
  end
metadata CHANGED
@@ -1,30 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-05 00:00:00.000000000 Z
11
+ date: 2019-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.0'
19
- name: concurrent-ruby
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - "~>"
@@ -33,9 +34,8 @@ dependencies:
33
34
  - - ">="
34
35
  - !ruby/object:Gem::Version
35
36
  version: 0.1.3
36
- name: dry-configurable
37
- prerelease: false
38
37
  type: :runtime
38
+ prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
@@ -45,48 +45,48 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.1.3
47
47
  - !ruby/object:Gem::Dependency
48
+ name: bundler
48
49
  requirement: !ruby/object:Gem::Requirement
49
50
  requirements:
50
51
  - - ">="
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
- name: bundler
54
- prerelease: false
55
54
  type: :development
55
+ prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
+ name: rake
62
63
  requirement: !ruby/object:Gem::Requirement
63
64
  requirements:
64
65
  - - ">="
65
66
  - !ruby/object:Gem::Version
66
67
  version: '0'
67
- name: rake
68
- prerelease: false
69
68
  type: :development
69
+ prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
+ name: rspec
76
77
  requirement: !ruby/object:Gem::Requirement
77
78
  requirements:
78
79
  - - ">="
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
- name: rspec
82
- prerelease: false
83
82
  type: :development
83
+ prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
- description:
89
+ description:
90
90
  email:
91
91
  - andyholland1991@aol.com
92
92
  executables: []
@@ -129,7 +129,7 @@ homepage: https://github.com/dry-rb/dry-container
129
129
  licenses:
130
130
  - MIT
131
131
  metadata: {}
132
- post_install_message:
132
+ post_install_message:
133
133
  rdoc_options: []
134
134
  require_paths:
135
135
  - lib
@@ -144,9 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.7.6
149
- signing_key:
147
+ rubygems_version: 3.0.3
148
+ signing_key:
150
149
  specification_version: 4
151
150
  summary: A simple container intended for use as an IoC container
152
151
  test_files: