dry-component 0.3.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +66 -7
- data/dry-component.gemspec +3 -1
- data/lib/dry/component/container.rb +21 -11
- data/lib/dry/component/injector.rb +12 -27
- data/lib/dry/component/loader.rb +42 -19
- data/lib/dry/component/version.rb +1 -1
- data/spec/fixtures/namespaced_components/namespaced/bar.rb +5 -0
- data/spec/fixtures/namespaced_components/namespaced/foo.rb +4 -0
- data/spec/unit/container/auto_register_spec.rb +33 -9
- data/spec/unit/container/import_spec.rb +1 -1
- data/spec/unit/container/injector_spec.rb +29 -0
- data/spec/unit/container_spec.rb +1 -1
- data/spec/unit/injector_spec.rb +8 -6
- data/spec/unit/loader_spec.rb +6 -3
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62d04c04b930c78a211b75bbe2b12e81709d5d72
|
4
|
+
data.tar.gz: 4142d98f2cbea51f1d33f3864b8a952ede77416a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 461b2819291b294fca018c24f12e392ee1fe3e9272232b9b87c79f5031968d74d9f91a2a7e52935ebc4c59fb3ec8f33e103eeeb94160a0ce5cceea184c9492c1
|
7
|
+
data.tar.gz: 0441572d29a273a379388e6bfb2f7a6c31b94ffd55051a55ebdfe1b7eac35fb57004443334d632b5f2fa857099f16bdd38c72dbe44617c57b2277923db75f3cd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,57 @@
|
|
1
|
+
# 0.4.2 - 2016-07-26
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
- 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)
|
6
|
+
|
7
|
+
# 0.4.1 - 2016-07-26 [YANKED]
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
- Require the 0.4.0 release of dry-auto_inject for the features below (in 0.4.0) to work properly (timriley)
|
12
|
+
|
13
|
+
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-component/compare/v0.4.0...v0.4.1)
|
14
|
+
|
15
|
+
# 0.4.0 - 2016-07-26 [YANKED]
|
16
|
+
|
17
|
+
### Added
|
18
|
+
|
19
|
+
- 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))
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# Set up container with default namespace
|
23
|
+
module Admin
|
24
|
+
class Container < Dry::Component::Container
|
25
|
+
configure do |config|
|
26
|
+
config.root = Pathname.new(__dir__).join("../..")
|
27
|
+
config.default_namespace = "admin"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Import = Container.injector
|
32
|
+
end
|
33
|
+
|
34
|
+
module Admin
|
35
|
+
class CreateUser
|
36
|
+
# "users.repository" will resolve an Admin::Users::Repository instance,
|
37
|
+
# where previously you had to identify it as "admin.users.repository"
|
38
|
+
include Admin::Import["users.repository"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
- 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))
|
44
|
+
- 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))
|
45
|
+
|
46
|
+
### Changed
|
47
|
+
|
48
|
+
- 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))
|
49
|
+
|
50
|
+
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-component/compare/v0.3.0...v0.4.0)
|
51
|
+
|
1
52
|
# 0.3.0 - 2016-06-18
|
2
53
|
|
3
|
-
|
54
|
+
### Changed
|
4
55
|
|
5
56
|
Removed two pieces that are moving to dry-web:
|
6
57
|
|
@@ -8,20 +59,24 @@ Removed two pieces that are moving to dry-web:
|
|
8
59
|
- Removed `Dry::Component::Config` and `options` setting from `Container` (timriley)
|
9
60
|
- Changed `Component#configure` behavior so it can be run multiple times for configuration to be applied in multiple passes (timriley)
|
10
61
|
|
62
|
+
[Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-component/compare/v0.2.0...v0.3.0)
|
63
|
+
|
11
64
|
# 0.2.0 - 2016-06-13
|
12
65
|
|
13
|
-
|
66
|
+
### Changed
|
14
67
|
|
15
68
|
- Component core directory is now `component/` by default (timriley)
|
16
69
|
- Injector default stragegy is now whatever dry-auto_inject's default is (rather than hard-coding a particular default strategy for dry-component) (timriley)
|
17
70
|
|
18
|
-
|
71
|
+
### Fixed
|
19
72
|
|
20
73
|
- Fixed bug where specified auto-inject strategies were not respected (timriley)
|
21
74
|
|
75
|
+
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-component/compare/v0.1.0...v0.2.0)
|
76
|
+
|
22
77
|
# 0.1.0 - 2016-06-07
|
23
78
|
|
24
|
-
|
79
|
+
### Added
|
25
80
|
|
26
81
|
* Provide a dependency injector as an `Inject` constant inside any subclass of `Dry::Component::Container`. This injector supports all of `dry-auto_inject`'s default injection strategies, and will lazily load any dependencies as they are injected. It also supports arbitrarily switching strategies, so they can be used in different classes as required (e.g. `include MyComponent::Inject.args["dep"]`) (timriley)
|
27
82
|
* Support aliased dependency names when calling the injector object (e.g. `MyComponent::Inject[foo: "my_app.foo", bar: "another.thing"]`) (timriley)
|
@@ -36,7 +91,7 @@ Removed two pieces that are moving to dry-web:
|
|
36
91
|
end
|
37
92
|
```
|
38
93
|
|
39
|
-
|
94
|
+
### Changed
|
40
95
|
|
41
96
|
* `Container.boot` now only makes a simple `require` for the boot file (solnic)
|
42
97
|
* Container object is passed to `Container.finalize` blocks (solnic)
|
@@ -45,17 +100,21 @@ Removed two pieces that are moving to dry-web:
|
|
45
100
|
* `Container.import_module` renamed to `.injector` (timriley)
|
46
101
|
* Default injection strategy is now `kwargs`, courtesy of the new dry-auto_inject default (timriley)
|
47
102
|
|
103
|
+
[Compare v0.0.2...v0.1.0](https://github.com/dry-rb/dry-component/compare/v0.0.2...v0.1.0)
|
104
|
+
|
48
105
|
# 0.0.2 - 2015-12-24
|
49
106
|
|
50
|
-
|
107
|
+
### Added
|
51
108
|
|
52
109
|
* Containers have a `name` setting (solnic)
|
53
110
|
* Containers can be imported into one another (solnic)
|
54
111
|
|
55
|
-
|
112
|
+
### Changed
|
56
113
|
|
57
114
|
* Container name is used to determine the name of its config file (solnic)
|
58
115
|
|
116
|
+
[Compare v0.0.1...v0.0.2](https://github.com/dry-rb/dry-component/compare/v0.0.1...v0.0.2)
|
117
|
+
|
59
118
|
# 0.0.1 - 2015-12-24
|
60
119
|
|
61
120
|
First public release, extracted from rodakase project
|
data/dry-component.gemspec
CHANGED
@@ -15,9 +15,11 @@ 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.required_ruby_version = '>= 2.1.0'
|
19
|
+
|
18
20
|
spec.add_runtime_dependency 'inflecto', '>= 0.0.2'
|
19
21
|
spec.add_runtime_dependency 'dry-container', '~> 0.3', '>= 0.3.4'
|
20
|
-
spec.add_runtime_dependency 'dry-auto_inject', '
|
22
|
+
spec.add_runtime_dependency 'dry-auto_inject', '>= 0.4.0'
|
21
23
|
spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
|
22
24
|
|
23
25
|
spec.add_development_dependency 'bundler'
|
@@ -9,21 +9,19 @@ require 'dry/component/loader'
|
|
9
9
|
|
10
10
|
module Dry
|
11
11
|
module Component
|
12
|
+
FileNotFoundError = Class.new(StandardError)
|
13
|
+
|
12
14
|
class Container
|
13
15
|
extend Dry::Configurable
|
14
16
|
extend Dry::Container::Mixin
|
15
17
|
|
16
18
|
setting :name
|
19
|
+
setting :default_namespace
|
17
20
|
setting :root, Pathname.pwd.freeze
|
18
21
|
setting :core_dir, 'component'.freeze
|
19
22
|
setting :auto_register
|
20
23
|
setting :loader, Dry::Component::Loader
|
21
24
|
|
22
|
-
def self.inherited(subclass)
|
23
|
-
super
|
24
|
-
subclass.const_set :Inject, subclass.injector
|
25
|
-
end
|
26
|
-
|
27
25
|
def self.configure(&block)
|
28
26
|
super(&block)
|
29
27
|
|
@@ -63,8 +61,12 @@ module Dry
|
|
63
61
|
freeze
|
64
62
|
end
|
65
63
|
|
66
|
-
def self.
|
67
|
-
|
64
|
+
def self.loader
|
65
|
+
@loader ||= config.loader.new(config)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.injector(options = {})
|
69
|
+
Injector.new(self, options: options)
|
68
70
|
end
|
69
71
|
|
70
72
|
def self.auto_register!(dir, &_block)
|
@@ -72,7 +74,7 @@ module Dry
|
|
72
74
|
|
73
75
|
Dir["#{root}/#{dir}/**/*.rb"].each do |path|
|
74
76
|
component_path = path.to_s.gsub("#{dir_root}/", '').gsub('.rb', '')
|
75
|
-
|
77
|
+
loader.load(component_path).tap do |component|
|
76
78
|
next if key?(component.identifier)
|
77
79
|
|
78
80
|
Kernel.require component.path
|
@@ -121,7 +123,7 @@ module Dry
|
|
121
123
|
end
|
122
124
|
|
123
125
|
def self.load_component(key)
|
124
|
-
component =
|
126
|
+
component = loader.load(key)
|
125
127
|
src_key = component.namespaces[0]
|
126
128
|
|
127
129
|
if imports.key?(src_key)
|
@@ -133,7 +135,15 @@ module Dry
|
|
133
135
|
|
134
136
|
import_container(src_key, src_container)
|
135
137
|
else
|
136
|
-
|
138
|
+
begin
|
139
|
+
require_component(component) { |klass| register(key) { klass.new } }
|
140
|
+
rescue FileNotFoundError => e
|
141
|
+
if config.default_namespace
|
142
|
+
load_component("#{config.default_namespace}#{config.namespace_separator}#{component.identifier}")
|
143
|
+
else
|
144
|
+
raise e
|
145
|
+
end
|
146
|
+
end
|
137
147
|
end
|
138
148
|
end
|
139
149
|
|
@@ -144,7 +154,7 @@ module Dry
|
|
144
154
|
Kernel.require component.path
|
145
155
|
yield(component.constant) if block
|
146
156
|
else
|
147
|
-
fail
|
157
|
+
fail FileNotFoundError, "could not resolve require file for #{component.identifier}"
|
148
158
|
end
|
149
159
|
end
|
150
160
|
|
@@ -2,23 +2,21 @@ require "dry-auto_inject"
|
|
2
2
|
|
3
3
|
module Dry
|
4
4
|
module Component
|
5
|
-
class Injector
|
5
|
+
class Injector < BasicObject
|
6
6
|
# @api private
|
7
7
|
attr_reader :container
|
8
8
|
|
9
|
+
# @api private
|
10
|
+
attr_reader :options
|
11
|
+
|
9
12
|
# @api private
|
10
13
|
attr_reader :injector
|
11
14
|
|
12
15
|
# @api private
|
13
|
-
def initialize(container,
|
16
|
+
def initialize(container, options: {}, strategy: :default)
|
14
17
|
@container = container
|
15
|
-
@
|
16
|
-
@injector =
|
17
|
-
if strategy
|
18
|
-
Dry::AutoInject(container).send(strategy)
|
19
|
-
else
|
20
|
-
Dry::AutoInject(container)
|
21
|
-
end
|
18
|
+
@options = options
|
19
|
+
@injector = ::Dry::AutoInject(container, options).__send__(strategy)
|
22
20
|
end
|
23
21
|
|
24
22
|
# @api public
|
@@ -27,37 +25,24 @@ module Dry
|
|
27
25
|
injector[*deps]
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
strategies[:args]
|
33
|
-
end
|
34
|
-
|
35
|
-
# @api public
|
36
|
-
def hash
|
37
|
-
strategies[:hash]
|
28
|
+
def method_missing(name, *args, &block)
|
29
|
+
::Dry::Component::Injector.new(container, options: options, strategy: name)
|
38
30
|
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
strategies[:kwargs]
|
32
|
+
def respond_to?(name, include_private = false)
|
33
|
+
injector.respond_to?(name, include_private)
|
43
34
|
end
|
44
35
|
|
45
36
|
private
|
46
37
|
|
47
38
|
def load_components(*components)
|
48
39
|
components = components.dup
|
49
|
-
aliases = components.last.is_a?(Hash) ? components.pop : {}
|
40
|
+
aliases = components.last.is_a?(::Hash) ? components.pop : {}
|
50
41
|
|
51
42
|
(components + aliases.values).each do |key|
|
52
43
|
container.load_component(key) unless container.key?(key)
|
53
44
|
end
|
54
45
|
end
|
55
|
-
|
56
|
-
def strategies
|
57
|
-
@strategies ||= Hash.new do |cache, strategy|
|
58
|
-
cache[strategy] = self.class.new(container, strategy: strategy, strategies_cache: cache)
|
59
|
-
end
|
60
|
-
end
|
61
46
|
end
|
62
47
|
end
|
63
48
|
end
|
data/lib/dry/component/loader.rb
CHANGED
@@ -3,33 +3,56 @@ require 'inflecto'
|
|
3
3
|
module Dry
|
4
4
|
module Component
|
5
5
|
class Loader
|
6
|
-
|
7
|
-
|
6
|
+
class Component
|
7
|
+
attr_reader :loader
|
8
|
+
attr_reader :identifier, :path, :file
|
8
9
|
|
9
|
-
|
10
|
+
def initialize(loader, input)
|
11
|
+
@loader = loader
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
@identifier = input.to_s.gsub(loader.path_separator, loader.namespace_separator)
|
14
|
+
if loader.default_namespace
|
15
|
+
re = /^#{Regexp.escape(loader.default_namespace)}#{Regexp.escape(loader.namespace_separator)}/
|
16
|
+
@identifier = @identifier.sub(re, '')
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
@path = input.to_s.gsub(loader.namespace_separator, loader.path_separator)
|
20
|
+
@file = "#{path}.rb"
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
def namespaces
|
24
|
+
identifier.split(loader.namespace_separator).map(&:to_sym)
|
25
|
+
end
|
26
|
+
|
27
|
+
def constant
|
28
|
+
Inflecto.constantize(constant_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def instance(*args)
|
32
|
+
constant.new(*args)
|
33
|
+
end
|
24
34
|
|
25
|
-
|
26
|
-
|
35
|
+
private
|
36
|
+
|
37
|
+
def constant_name
|
38
|
+
Inflecto.camelize(path)
|
39
|
+
end
|
27
40
|
end
|
28
41
|
|
29
|
-
|
42
|
+
PATH_SEPARATOR = '/'.freeze
|
43
|
+
|
44
|
+
attr_reader :default_namespace
|
45
|
+
attr_reader :namespace_separator
|
46
|
+
attr_reader :path_separator
|
47
|
+
|
48
|
+
def initialize(config)
|
49
|
+
@default_namespace = config.default_namespace
|
50
|
+
@namespace_separator = config.namespace_separator
|
51
|
+
@path_separator = PATH_SEPARATOR
|
52
|
+
end
|
30
53
|
|
31
|
-
def
|
32
|
-
|
54
|
+
def load(component_path)
|
55
|
+
Component.new(self, component_path)
|
33
56
|
end
|
34
57
|
end
|
35
58
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'dry/component/container'
|
2
2
|
|
3
3
|
RSpec.describe Dry::Component::Container, '.auto_register!' do
|
4
|
-
context '
|
4
|
+
context 'standard loader' do
|
5
5
|
before do
|
6
6
|
class Test::Container < Dry::Component::Container
|
7
7
|
configure do |config|
|
@@ -18,15 +18,39 @@ RSpec.describe Dry::Component::Container, '.auto_register!' do
|
|
18
18
|
it { expect(Test::Container['bar.baz']).to be_an_instance_of(Bar::Baz) }
|
19
19
|
end
|
20
20
|
|
21
|
+
context 'standard loader with a default namespace configured' do
|
22
|
+
before do
|
23
|
+
class Test::Container < Dry::Component::Container
|
24
|
+
configure do |config|
|
25
|
+
config.root = SPEC_ROOT.join('fixtures').realpath
|
26
|
+
config.default_namespace = 'namespaced'
|
27
|
+
end
|
28
|
+
|
29
|
+
load_paths!('namespaced_components')
|
30
|
+
auto_register!('namespaced_components')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
specify { expect(Test::Container['bar']).to be_a(Namespaced::Bar) }
|
35
|
+
specify { expect(Test::Container['bar'].foo).to be_a(Namespaced::Foo) }
|
36
|
+
specify { expect(Test::Container['foo']).to be_a(Namespaced::Foo) }
|
37
|
+
end
|
38
|
+
|
21
39
|
context 'with a custom loader' do
|
22
40
|
before do
|
23
41
|
class Test::Loader < Dry::Component::Loader
|
24
|
-
|
25
|
-
|
42
|
+
class Component < Dry::Component::Loader::Component
|
43
|
+
def identifier
|
44
|
+
super + ".yay"
|
45
|
+
end
|
46
|
+
|
47
|
+
def instance(*args)
|
48
|
+
constant.respond_to?(:call) ? constant : constant.new(*args)
|
49
|
+
end
|
26
50
|
end
|
27
51
|
|
28
|
-
def
|
29
|
-
|
52
|
+
def load(component_path)
|
53
|
+
Component.new(self, component_path)
|
30
54
|
end
|
31
55
|
end
|
32
56
|
|
@@ -41,9 +65,9 @@ RSpec.describe Dry::Component::Container, '.auto_register!' do
|
|
41
65
|
end
|
42
66
|
end
|
43
67
|
|
44
|
-
it { expect(Test::Container['foo']).to be_an_instance_of(Foo) }
|
45
|
-
it { expect(Test::Container['bar']).to eq(Bar) }
|
46
|
-
it { expect(Test::Container['bar'].call).to eq("Welcome to my Moe's Tavern!") }
|
47
|
-
it { expect(Test::Container['bar
|
68
|
+
it { expect(Test::Container['foo.yay']).to be_an_instance_of(Foo) }
|
69
|
+
it { expect(Test::Container['bar.yay']).to eq(Bar) }
|
70
|
+
it { expect(Test::Container['bar.yay'].call).to eq("Welcome to my Moe's Tavern!") }
|
71
|
+
it { expect(Test::Container['bar.baz.yay']).to be_an_instance_of(Bar::Baz) }
|
48
72
|
end
|
49
73
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "dry/component/container"
|
2
|
+
|
3
|
+
RSpec.describe Dry::Component::Container, ".injector" do
|
4
|
+
context "injector_options provided" do
|
5
|
+
it "builds an injector with the provided options" do
|
6
|
+
Test::Foo = Class.new
|
7
|
+
|
8
|
+
Test::Container = Class.new(Dry::Component::Container) do
|
9
|
+
register "foo", Test::Foo.new
|
10
|
+
end
|
11
|
+
|
12
|
+
Test::Inject = Test::Container.injector(strategies: {
|
13
|
+
default: Dry::AutoInject::Strategies::Args,
|
14
|
+
australian: Dry::AutoInject::Strategies::Args
|
15
|
+
})
|
16
|
+
|
17
|
+
injected_class = Class.new do
|
18
|
+
include Test::Inject.australian["foo"]
|
19
|
+
end
|
20
|
+
|
21
|
+
obj = injected_class.new
|
22
|
+
expect(obj.foo).to be_a Test::Foo
|
23
|
+
|
24
|
+
another = Object.new
|
25
|
+
obj = injected_class.new(another)
|
26
|
+
expect(obj.foo).to eq another
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/unit/container_spec.rb
CHANGED
data/spec/unit/injector_spec.rb
CHANGED
@@ -7,11 +7,13 @@ RSpec.describe Dry::Component::Injector do
|
|
7
7
|
|
8
8
|
load_paths! "lib"
|
9
9
|
end
|
10
|
+
|
11
|
+
Test::Inject = Test::Container.injector
|
10
12
|
end
|
11
13
|
|
12
14
|
it "supports args injection by default" do
|
13
15
|
obj = Class.new do
|
14
|
-
include Test::
|
16
|
+
include Test::Inject["test.dep"]
|
15
17
|
end.new
|
16
18
|
|
17
19
|
expect(obj.dep).to be_a Test::Dep
|
@@ -19,7 +21,7 @@ RSpec.describe Dry::Component::Injector do
|
|
19
21
|
|
20
22
|
it "supports args injection with explicit method" do
|
21
23
|
obj = Class.new do
|
22
|
-
include Test::
|
24
|
+
include Test::Inject.args["test.dep"]
|
23
25
|
end.new
|
24
26
|
|
25
27
|
expect(obj.dep).to be_a Test::Dep
|
@@ -27,7 +29,7 @@ RSpec.describe Dry::Component::Injector do
|
|
27
29
|
|
28
30
|
it "supports hash injection" do
|
29
31
|
obj = Class.new do
|
30
|
-
include Test::
|
32
|
+
include Test::Inject.hash["test.dep"]
|
31
33
|
end.new
|
32
34
|
|
33
35
|
expect(obj.dep).to be_a Test::Dep
|
@@ -35,7 +37,7 @@ RSpec.describe Dry::Component::Injector do
|
|
35
37
|
|
36
38
|
it "support kwargs injection" do
|
37
39
|
obj = Class.new do
|
38
|
-
include Test::
|
40
|
+
include Test::Inject.kwargs["test.dep"]
|
39
41
|
end.new
|
40
42
|
|
41
43
|
expect(obj.dep).to be_a Test::Dep
|
@@ -43,7 +45,7 @@ RSpec.describe Dry::Component::Injector do
|
|
43
45
|
|
44
46
|
it "allows injection strategies to be swapped" do
|
45
47
|
obj = Class.new do
|
46
|
-
include Test::
|
48
|
+
include Test::Inject.kwargs.hash["test.dep"]
|
47
49
|
end.new
|
48
50
|
|
49
51
|
expect(obj.dep).to be_a Test::Dep
|
@@ -51,7 +53,7 @@ RSpec.describe Dry::Component::Injector do
|
|
51
53
|
|
52
54
|
it "supports aliases" do
|
53
55
|
obj = Class.new do
|
54
|
-
include Test::
|
56
|
+
include Test::Inject[foo: "test.dep"]
|
55
57
|
end.new
|
56
58
|
|
57
59
|
expect(obj.foo).to be_a Test::Dep
|
data/spec/unit/loader_spec.rb
CHANGED
@@ -40,20 +40,23 @@ RSpec.describe Dry::Component::Loader do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
let(:container) { Class.new(Dry::Component::Container) }
|
44
|
+
let(:loader) { Dry::Component::Loader.new(container.config) }
|
45
|
+
|
43
46
|
context 'from identifier as a symbol' do
|
44
|
-
subject(:component) {
|
47
|
+
subject(:component) { loader.load(:'test.bar') }
|
45
48
|
|
46
49
|
it_behaves_like 'a valid component'
|
47
50
|
end
|
48
51
|
|
49
52
|
context 'from identifier as a string' do
|
50
|
-
subject(:component) {
|
53
|
+
subject(:component) { loader.load('test.bar') }
|
51
54
|
|
52
55
|
it_behaves_like 'a valid component'
|
53
56
|
end
|
54
57
|
|
55
58
|
context 'from path' do
|
56
|
-
subject(:component) {
|
59
|
+
subject(:component) { loader.load('test/bar') }
|
57
60
|
|
58
61
|
it_behaves_like 'a valid component'
|
59
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
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-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inflecto
|
@@ -48,16 +48,16 @@ dependencies:
|
|
48
48
|
name: dry-auto_inject
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 0.4.0
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 0.4.0
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: dry-configurable
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,6 +152,8 @@ files:
|
|
152
152
|
- spec/fixtures/lazytest/lib/test/models.rb
|
153
153
|
- spec/fixtures/lazytest/lib/test/models/book.rb
|
154
154
|
- spec/fixtures/lazytest/lib/test/models/user.rb
|
155
|
+
- spec/fixtures/namespaced_components/namespaced/bar.rb
|
156
|
+
- spec/fixtures/namespaced_components/namespaced/foo.rb
|
155
157
|
- spec/fixtures/other/config/boot/bar.rb
|
156
158
|
- spec/fixtures/other/lib/test/dep.rb
|
157
159
|
- spec/fixtures/other/lib/test/foo.rb
|
@@ -169,6 +171,7 @@ files:
|
|
169
171
|
- spec/spec_helper.rb
|
170
172
|
- spec/unit/container/auto_register_spec.rb
|
171
173
|
- spec/unit/container/import_spec.rb
|
174
|
+
- spec/unit/container/injector_spec.rb
|
172
175
|
- spec/unit/container_spec.rb
|
173
176
|
- spec/unit/injector_spec.rb
|
174
177
|
- spec/unit/loader_spec.rb
|
@@ -184,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
187
|
requirements:
|
185
188
|
- - ">="
|
186
189
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
190
|
+
version: 2.1.0
|
188
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
192
|
requirements:
|
190
193
|
- - ">="
|
@@ -211,6 +214,8 @@ test_files:
|
|
211
214
|
- spec/fixtures/lazytest/lib/test/models.rb
|
212
215
|
- spec/fixtures/lazytest/lib/test/models/book.rb
|
213
216
|
- spec/fixtures/lazytest/lib/test/models/user.rb
|
217
|
+
- spec/fixtures/namespaced_components/namespaced/bar.rb
|
218
|
+
- spec/fixtures/namespaced_components/namespaced/foo.rb
|
214
219
|
- spec/fixtures/other/config/boot/bar.rb
|
215
220
|
- spec/fixtures/other/lib/test/dep.rb
|
216
221
|
- spec/fixtures/other/lib/test/foo.rb
|
@@ -228,6 +233,7 @@ test_files:
|
|
228
233
|
- spec/spec_helper.rb
|
229
234
|
- spec/unit/container/auto_register_spec.rb
|
230
235
|
- spec/unit/container/import_spec.rb
|
236
|
+
- spec/unit/container/injector_spec.rb
|
231
237
|
- spec/unit/container_spec.rb
|
232
238
|
- spec/unit/injector_spec.rb
|
233
239
|
- spec/unit/loader_spec.rb
|