dry-system 0.5.1 → 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: b9ae890ec18500bc5f87881eba9be29608959591
4
- data.tar.gz: fea3ad84ab881aa0d9f134f007b81ca265268cd1
3
+ metadata.gz: '085640c18c734b66700738f731ea66d0001cdc83'
4
+ data.tar.gz: a6c6835df5df05045cddbc41615a581c11c4ea1d
5
5
  SHA512:
6
- metadata.gz: 77ddf89e868fa4b6791d9d7dd56f03f2f6bfd2d062fbe59f08a29bb04d4416bd0fce3d45e351500e72460ca9814d6fe7faf42afdb6741a0eae23c907473b66bd
7
- data.tar.gz: 7d97e7c5435d6ca7e7fb25f3f86bb4f10ce386b42b218e9abf998a495e9a6a858847b8ff53fd06d7c0bad7c6bd720c1f346e71d1229956019d76ce9d6af4a37f
6
+ metadata.gz: 415e4f12b22eeb6e7f7b9f6f856b21953f1126b634d82cc17e9c3da3eab1f6aff30c261fddde7401495d6bccd1092fa7185a772031abf886732d913b1182aeee
7
+ data.tar.gz: 3082441096b4e4208f1db30d817a816a809026b3cd07886b417edfc77be235167c54cdd9e5de4336109b88daa2633cca1c122a3f8fcbac8cea6421a099a0c633
data/.travis.yml CHANGED
@@ -4,18 +4,17 @@ cache: bundler
4
4
  bundler_args: --without tools
5
5
  script:
6
6
  - bundle exec rake spec
7
+ after_success:
8
+ - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
7
9
  rvm:
8
10
  - 2.1
9
11
  - 2.2
10
12
  - 2.3.1
11
13
  - rbx
12
- - jruby-9000
13
- - ruby-head
14
- - jruby-head
14
+ - jruby-9.1.5.0
15
15
  matrix:
16
16
  allow_failures:
17
- - rvm: ruby-head
18
- - rvm: jruby-head
17
+ - rvm: rbx
19
18
  notifications:
20
19
  email: false
21
20
  webhooks:
data/CHANGELOG.md CHANGED
@@ -1,15 +1,24 @@
1
+ # 0.6.0 2016-02-02
2
+
3
+ ### Changed
4
+
5
+ * Lazy load components as they are resolved, rather than on injection (timriley)
6
+ * Perform registration even though component already required (blelump)
7
+
8
+ [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-system/compare/v0.5.1...v0.6.0)
9
+
1
10
  # 0.5.1 2016-08-23
2
11
 
3
12
  ### Fixed
4
13
 
5
14
  - Undefined locals or method calls will raise proper exceptions in Lifecycle DSL (aradunovic)
6
15
 
7
- [Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-component/compare/v0.5.0...v0.5.1)
16
+ [Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-system/compare/v0.5.0...v0.5.1)
8
17
 
9
18
  # 0.5.0 2016-08-15
10
19
 
11
20
  This is a major refactoring with better internal APIs and improved support
12
- for multi-container setups. As part of this release `dry-component` has been renamed to `dry-system`.
21
+ for multi-container setups. As part of this release `dry-system` has been renamed to `dry-system`.
13
22
 
14
23
  ### Added
15
24
 
@@ -32,15 +41,15 @@ for multi-container setups. As part of this release `dry-component` has been ren
32
41
  - Booting is now handled by `System::Booter` object configured in a container (solnic)
33
42
  - Importing containers is now handled by `System::Importer` object configured in a container (solnic)
34
43
 
35
- [Compare v0.4.3...v0.5.0](https://github.com/dry-rb/dry-component/compare/v0.4.3...v0.5.0)
44
+ [Compare v0.4.3...v0.5.0](https://github.com/dry-rb/dry-system/compare/v0.4.3...v0.5.0)
36
45
 
37
46
  # 0.4.3 - 2016-08-01
38
47
 
39
48
  ### Fixed
40
49
 
41
- - Return immediately from `Container.load_component` if the requested component key already exists in the container. This fixes a crash when requesting to load a manually registered component with a name that doesn't map to a filename (timriley in [#24](https://github.com/dry-rb/dry-component/pull/24))
50
+ - Return immediately from `Container.load_component` if the requested component key already exists in the container. This fixes a crash when requesting to load a manually registered component with a name that doesn't map to a filename (timriley in [#24](https://github.com/dry-rb/dry-system/pull/24))
42
51
 
43
- [Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-component/compare/v0.4.2...v0.4.3)
52
+ [Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-system/compare/v0.4.2...v0.4.3)
44
53
 
45
54
  # 0.4.2 - 2016-07-26
46
55
 
@@ -48,7 +57,7 @@ for multi-container setups. As part of this release `dry-component` has been ren
48
57
 
49
58
  - Ensure file components can be loaded when they're requested for the first time using their shorthand container identifier (i.e. with the container's default namespace removed) (timriley)
50
59
 
51
- [Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-component/compare/v0.4.1...v0.4.2)
60
+ [Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-system/compare/v0.4.1...v0.4.2)
52
61
 
53
62
  # 0.4.1 - 2016-07-26 [YANKED]
54
63
 
@@ -56,13 +65,13 @@ for multi-container setups. As part of this release `dry-component` has been ren
56
65
 
57
66
  - Require the 0.4.0 release of dry-auto_inject for the features below (in 0.4.0) to work properly (timriley)
58
67
 
59
- [Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-component/compare/v0.4.0...v0.4.1)
68
+ [Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-system/compare/v0.4.0...v0.4.1)
60
69
 
61
70
  # 0.4.0 - 2016-07-26 [YANKED]
62
71
 
63
72
  ### Added
64
73
 
65
- - Support for supplying a default namespace to a container, which is passed to the container's injector to allow for convenient shorthand access to registered objects in the same namespace (timriley in [#20](https://github.com/dry-rb/dry-component/pull/20))
74
+ - Support for supplying a default namespace to a container, which is passed to the container's injector to allow for convenient shorthand access to registered objects in the same namespace (timriley in [#20](https://github.com/dry-rb/dry-system/pull/20))
66
75
 
67
76
  ```ruby
68
77
  # Set up container with default namespace
@@ -86,14 +95,14 @@ for multi-container setups. As part of this release `dry-component` has been ren
86
95
  end
87
96
  ```
88
97
 
89
- - Support for supplying to options directly to dry-auto_inject's `Builder` via `Dry::Component::Container#injector(options)`. This allows you to provide dry-auto_inject customizations like your own container of injection strategies (timriley in [#20](https://github.com/dry-rb/dry-component/pull/20))
90
- - Support for accessing all available injector strategies, not just the defaults (e.g. `MyContainer.injector.some_custom_strategy`) (timriley in [#19](https://github.com/dry-rb/dry-component/pull/19))
98
+ - Support for supplying to options directly to dry-auto_inject's `Builder` via `Dry::Component::Container#injector(options)`. This allows you to provide dry-auto_inject customizations like your own container of injection strategies (timriley in [#20](https://github.com/dry-rb/dry-system/pull/20))
99
+ - Support for accessing all available injector strategies, not just the defaults (e.g. `MyContainer.injector.some_custom_strategy`) (timriley in [#19](https://github.com/dry-rb/dry-system/pull/19))
91
100
 
92
101
  ### Changed
93
102
 
94
- - Subclasses of `Dry::Component::Container` no longer have an `Injector` constant automatically defined within them. The recommended approach is to save your own injector object to a constant, which allows you to pass options to it at the same time, e.g. `MyApp::Import = MyApp::Container.injector(my_options)` (timriley in [#19](https://github.com/dry-rb/dry-component/pull/19))
103
+ - Subclasses of `Dry::Component::Container` no longer have an `Injector` constant automatically defined within them. The recommended approach is to save your own injector object to a constant, which allows you to pass options to it at the same time, e.g. `MyApp::Import = MyApp::Container.injector(my_options)` (timriley in [#19](https://github.com/dry-rb/dry-system/pull/19))
95
104
 
96
- [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-component/compare/v0.3.0...v0.4.0)
105
+ [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-system/compare/v0.3.0...v0.4.0)
97
106
 
98
107
  # 0.3.0 - 2016-06-18
99
108
 
@@ -105,20 +114,20 @@ Removed two pieces that are moving to dry-web:
105
114
  - Removed `Dry::Component::Config` and `options` setting from `Container` (timriley)
106
115
  - Changed `Component#configure` behavior so it can be run multiple times for configuration to be applied in multiple passes (timriley)
107
116
 
108
- [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-component/compare/v0.2.0...v0.3.0)
117
+ [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-system/compare/v0.2.0...v0.3.0)
109
118
 
110
119
  # 0.2.0 - 2016-06-13
111
120
 
112
121
  ### Changed
113
122
 
114
123
  - Component core directory is now `component/` by default (timriley)
115
- - Injector default stragegy is now whatever dry-auto_inject's default is (rather than hard-coding a particular default strategy for dry-component) (timriley)
124
+ - Injector default stragegy is now whatever dry-auto_inject's default is (rather than hard-coding a particular default strategy for dry-system) (timriley)
116
125
 
117
126
  ### Fixed
118
127
 
119
128
  - Fixed bug where specified auto-inject strategies were not respected (timriley)
120
129
 
121
- [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-component/compare/v0.1.0...v0.2.0)
130
+ [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-system/compare/v0.1.0...v0.2.0)
122
131
 
123
132
  # 0.1.0 - 2016-06-07
124
133
 
@@ -146,7 +155,7 @@ Removed two pieces that are moving to dry-web:
146
155
  * `Container.import_module` renamed to `.injector` (timriley)
147
156
  * Default injection strategy is now `kwargs`, courtesy of the new dry-auto_inject default (timriley)
148
157
 
149
- [Compare v0.0.2...v0.1.0](https://github.com/dry-rb/dry-component/compare/v0.0.2...v0.1.0)
158
+ [Compare v0.0.2...v0.1.0](https://github.com/dry-rb/dry-system/compare/v0.0.2...v0.1.0)
150
159
 
151
160
  # 0.0.2 - 2015-12-24
152
161
 
@@ -159,7 +168,7 @@ Removed two pieces that are moving to dry-web:
159
168
 
160
169
  * Container name is used to determine the name of its config file (solnic)
161
170
 
162
- [Compare v0.0.1...v0.0.2](https://github.com/dry-rb/dry-component/compare/v0.0.1...v0.0.2)
171
+ [Compare v0.0.1...v0.0.2](https://github.com/dry-rb/dry-system/compare/v0.0.1...v0.0.2)
163
172
 
164
173
  # 0.0.1 - 2015-12-24
165
174
 
data/dry-system.gemspec CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.add_runtime_dependency 'inflecto', '>= 0.0.2'
21
21
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
22
22
  spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
23
- spec.add_runtime_dependency 'dry-container', '~> 0.4'
23
+ spec.add_runtime_dependency 'dry-container', '~> 0.6'
24
24
  spec.add_runtime_dependency 'dry-auto_inject', '>= 0.4.0'
25
- spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
25
+ spec.add_runtime_dependency 'dry-configurable', '~> 0.2'
26
26
 
27
27
  spec.add_development_dependency 'bundler'
28
28
  spec.add_development_dependency 'rake'
@@ -1,10 +1,10 @@
1
1
  require 'pathname'
2
2
 
3
+ require 'dry-auto_inject'
3
4
  require 'dry-configurable'
4
5
  require 'dry-container'
5
6
 
6
7
  require 'dry/system/errors'
7
- require 'dry/system/injector'
8
8
  require 'dry/system/loader'
9
9
  require 'dry/system/booter'
10
10
  require 'dry/system/auto_registrar'
@@ -41,7 +41,7 @@ module Dry
41
41
  # * `:name` - a unique container identifier
42
42
  # * `:root` - a system root directory (defaults to `pwd`)
43
43
  # * `:system_dir` - directory name relative to root, where bootable components
44
- # can be defined in `boot` dir this defaults to `component`
44
+ # can be defined in `boot` dir this defaults to `system`
45
45
  #
46
46
  # @example
47
47
  # class MyApp < Dry::System::Container
@@ -372,7 +372,7 @@ module Dry
372
372
  #
373
373
  # @api public
374
374
  def injector(options = {})
375
- Injector.new(self, options: options)
375
+ Dry::AutoInject(self, options)
376
376
  end
377
377
 
378
378
  # Requires one or more files relative to the container's root
@@ -413,6 +413,13 @@ module Dry
413
413
  config.root
414
414
  end
415
415
 
416
+ # @api public
417
+ def resolve(key)
418
+ load_component(key) unless frozen?
419
+
420
+ super
421
+ end
422
+
416
423
  # @api private
417
424
  def load_paths
418
425
  @load_paths ||= []
@@ -451,7 +458,9 @@ module Dry
451
458
  raise FileNotFoundError, component
452
459
  end
453
460
 
454
- Kernel.require(component.path) && yield
461
+ Kernel.require(component.path)
462
+
463
+ yield
455
464
  end
456
465
 
457
466
  # @api private
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module System
3
- VERSION = '0.5.1'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.3'
4
- require 'codeclimate-test-reporter'
5
- CodeClimate::TestReporter.start
4
+ require 'simplecov'
5
+ SimpleCov.start
6
6
  end
7
7
 
8
8
  begin
@@ -34,13 +34,26 @@ RSpec.describe Dry::System::Container do
34
34
  end
35
35
 
36
36
  describe '.require_component' do
37
- it 'requires component file' do
38
- component = container.component('test/foo')
39
- required = false
40
- container.require_component(component) do
41
- required = true
37
+
38
+ shared_examples_for 'requireable' do
39
+ it 'requires component file' do
40
+ component = container.component('test/foo')
41
+ required = false
42
+ container.require_component(component) do
43
+ required = true
44
+ end
45
+ expect(required).to be(true)
46
+ end
47
+ end
48
+
49
+ it_behaves_like 'requireable'
50
+
51
+ context 'when already required' do
52
+ before do
53
+ Kernel.require('test/foo')
42
54
  end
43
- expect(required).to be(true)
55
+
56
+ it_behaves_like 'requireable'
44
57
  end
45
58
 
46
59
  it 'raises when file does not exist' do
@@ -49,15 +62,27 @@ RSpec.describe Dry::System::Container do
49
62
  Dry::System::FileNotFoundError, /test\.missing/
50
63
  )
51
64
  end
65
+
66
+ it 'returns for already registered components' do
67
+ component = container.component('test/foo')
68
+
69
+ registrar = -> {
70
+ container.register(component.identifier) { component.instance }
71
+ }
72
+
73
+ container.require_component(component, &registrar)
74
+
75
+ required = false
76
+ registrar = -> { required = true }
77
+ container.require_component(component, &registrar)
78
+ expect(required).to be(false)
79
+ end
52
80
  end
53
81
 
54
82
  describe '.load_component' do
55
83
  it 'loads and registers systems from configured load paths' do
56
84
  container.load_component('test.foo')
57
85
 
58
- expect(Test.const_defined?(:Foo)).to be(true)
59
- expect(Test.const_defined?(:Dep)).to be(true)
60
-
61
86
  expect(Test::Foo.new.dep).to be_instance_of(Test::Dep)
62
87
  end
63
88
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-23 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflecto
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.4'
61
+ version: '0.6'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.4'
68
+ version: '0.6'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: dry-auto_inject
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.1'
89
+ version: '0.2'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.1'
96
+ version: '0.2'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -170,7 +170,6 @@ files:
170
170
  - lib/dry/system/container.rb
171
171
  - lib/dry/system/errors.rb
172
172
  - lib/dry/system/importer.rb
173
- - lib/dry/system/injector.rb
174
173
  - lib/dry/system/lifecycle.rb
175
174
  - lib/dry/system/loader.rb
176
175
  - lib/dry/system/version.rb
@@ -219,7 +218,6 @@ files:
219
218
  - spec/unit/container/import_spec.rb
220
219
  - spec/unit/container/injector_spec.rb
221
220
  - spec/unit/container_spec.rb
222
- - spec/unit/injector_spec.rb
223
221
  - spec/unit/loader_spec.rb
224
222
  homepage: http://dry-rb.org/gems/dry-system
225
223
  licenses:
@@ -241,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
239
  version: '0'
242
240
  requirements: []
243
241
  rubyforge_project:
244
- rubygems_version: 2.5.1
242
+ rubygems_version: 2.6.9
245
243
  signing_key:
246
244
  specification_version: 4
247
245
  summary: Organize your code into reusable components
@@ -291,5 +289,4 @@ test_files:
291
289
  - spec/unit/container/import_spec.rb
292
290
  - spec/unit/container/injector_spec.rb
293
291
  - spec/unit/container_spec.rb
294
- - spec/unit/injector_spec.rb
295
292
  - spec/unit/loader_spec.rb
@@ -1,68 +0,0 @@
1
- require "dry-auto_inject"
2
-
3
- module Dry
4
- module System
5
- # Injection mixin builder
6
- #
7
- # Injector objects are created by containers and can be used to automatically
8
- # define object constructors where depedencies will be injected in.
9
- #
10
- # Main purpose of this object is to provide injection along with lazy-loading
11
- # of components on demand. This gives us a way to load components in
12
- # isolation from the rest of the system.
13
- #
14
- # @see [Container.injector]
15
- #
16
- # @api public
17
- class Injector < BasicObject
18
- # @api private
19
- attr_reader :container
20
-
21
- # @api private
22
- attr_reader :options
23
-
24
- # @api private
25
- attr_reader :injector
26
-
27
- # @api private
28
- def initialize(container, options: {}, strategy: :default)
29
- @container = container
30
- @options = options
31
- @injector = ::Dry::AutoInject(container, options).__send__(strategy)
32
- end
33
-
34
- # Create injection mixin for specified dependencies
35
- #
36
- # @example
37
- # require 'system/import'
38
- #
39
- # class UserRepo
40
- # include Import['persistence.db']
41
- # end
42
- #
43
- # @param [Array<String>] *deps Keys under which dependencies are registered
44
- #
45
- # @return [Dry::AutoInject::Injector]
46
- #
47
- # @api public
48
- def [](*deps)
49
- load_components(*deps)
50
- injector[*deps]
51
- end
52
-
53
- private
54
-
55
- # @api private
56
- def method_missing(name, *args, &block)
57
- ::Dry::System::Injector.new(container, options: options, strategy: name)
58
- end
59
-
60
- # @api private
61
- def load_components(*keys, **aliases)
62
- (keys + aliases.values).each do |key|
63
- container.load_component(key)
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,72 +0,0 @@
1
- RSpec.describe Dry::System::Injector do
2
- before do
3
- class Test::Container < Dry::System::Container
4
- configure do |config|
5
- config.root = SPEC_ROOT.join('fixtures/test').realpath
6
- end
7
-
8
- load_paths! 'lib'
9
- end
10
-
11
- Test::Inject = Test::Container.injector
12
- end
13
-
14
- it 'supports args injection by default' do
15
- obj = Class.new do
16
- include Test::Inject['test.dep']
17
- end.new
18
-
19
- expect(obj.dep).to be_a Test::Dep
20
- end
21
-
22
- it 'supports args injection with explicit method' do
23
- obj = Class.new do
24
- include Test::Inject.args['test.dep']
25
- end.new
26
-
27
- expect(obj.dep).to be_a Test::Dep
28
- end
29
-
30
- it 'supports hash injection' do
31
- obj = Class.new do
32
- include Test::Inject.hash['test.dep']
33
- end.new
34
-
35
- expect(obj.dep).to be_a Test::Dep
36
- end
37
-
38
- it 'support kwargs injection' do
39
- obj = Class.new do
40
- include Test::Inject.kwargs['test.dep']
41
- end.new
42
-
43
- expect(obj.dep).to be_a Test::Dep
44
- end
45
-
46
- it 'allows injection strategies to be swapped' do
47
- obj = Class.new do
48
- include Test::Inject.kwargs.hash['test.dep']
49
- end.new
50
-
51
- expect(obj.dep).to be_a Test::Dep
52
- end
53
-
54
- it 'supports aliases' do
55
- obj = Class.new do
56
- include Test::Inject['test.dep', foo: 'test.dep']
57
- end.new
58
-
59
- expect(obj.dep).to be_a Test::Dep
60
- expect(obj.foo).to be_a Test::Dep
61
- end
62
-
63
- context 'singleton' do
64
- it 'supports injection' do
65
- obj = Class.new do
66
- include Test::Inject[foo: 'test.singleton_dep']
67
- end.new
68
-
69
- expect(obj.foo).to be_a Test::SingletonDep
70
- end
71
- end
72
- end