dry-component 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/dry/component/container.rb +8 -20
- data/lib/dry/component/version.rb +1 -1
- data/spec/spec_helper.rb +0 -4
- data/spec/unit/container/auto_register_spec.rb +1 -2
- data/spec/unit/container_spec.rb +2 -2
- metadata +2 -5
- data/lib/dry/component/config.rb +0 -23
- data/spec/unit/config_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f3c7bc83200152d244ec311a77affb840f5340f
|
4
|
+
data.tar.gz: e437ce4b730ce49d617fbc86a4bc46f089a1df1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ce61aa0a4bc7e95f486adfe712b4f73a585631d5dba1e2e441ecbef99aef9da82a49039c605ec6651bad6db3d285320ec4fd97f74db3dd5bb66630fc402a468
|
7
|
+
data.tar.gz: c095e172c4af2ffeff3056eddaea8bd0281244cea470379738dc73e943978d18223a4c12b82beafa904692e7758c5661f379370617b069b4cb6669d89b7939ab
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
# 0.3.0 - 2016-06-18
|
2
|
+
|
3
|
+
## Changed
|
4
|
+
|
5
|
+
Removed two pieces that are moving to dry-web:
|
6
|
+
|
7
|
+
- Removed `env` setting from `Container` (timriley)
|
8
|
+
- Removed `Dry::Component::Config` and `options` setting from `Container` (timriley)
|
9
|
+
- Changed `Component#configure` behavior so it can be run multiple times for configuration to be applied in multiple passes (timriley)
|
10
|
+
|
1
11
|
# 0.2.0 - 2016-06-13
|
2
12
|
|
3
13
|
## Changed
|
4
14
|
|
15
|
+
- Component core directory is now `component/` by default (timriley)
|
5
16
|
- Injector default stragegy is now whatever dry-auto_inject's default is (rather than hard-coding a particular default strategy for dry-component) (timriley)
|
6
17
|
|
7
18
|
## Fixed
|
@@ -1,23 +1,22 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'inflecto'
|
3
3
|
|
4
|
+
require 'dry-configurable'
|
4
5
|
require 'dry-container'
|
5
6
|
|
6
7
|
require 'dry/component/injector'
|
7
8
|
require 'dry/component/loader'
|
8
|
-
require 'dry/component/config'
|
9
9
|
|
10
10
|
module Dry
|
11
11
|
module Component
|
12
12
|
class Container
|
13
|
+
extend Dry::Configurable
|
13
14
|
extend Dry::Container::Mixin
|
14
15
|
|
15
|
-
setting :env
|
16
16
|
setting :name
|
17
17
|
setting :root, Pathname.pwd.freeze
|
18
18
|
setting :core_dir, 'component'.freeze
|
19
19
|
setting :auto_register
|
20
|
-
setting :options
|
21
20
|
setting :loader, Dry::Component::Loader
|
22
21
|
|
23
22
|
def self.inherited(subclass)
|
@@ -25,18 +24,11 @@ module Dry
|
|
25
24
|
subclass.const_set :Inject, subclass.injector
|
26
25
|
end
|
27
26
|
|
28
|
-
def self.configure(
|
29
|
-
|
30
|
-
|
31
|
-
super() do |config|
|
32
|
-
yield(config) if block
|
33
|
-
config.options = Config.load(root, config.name, env)
|
34
|
-
end
|
27
|
+
def self.configure(&block)
|
28
|
+
super(&block)
|
35
29
|
|
36
30
|
load_paths!(config.core_dir)
|
37
31
|
|
38
|
-
@configured = true
|
39
|
-
|
40
32
|
self
|
41
33
|
end
|
42
34
|
|
@@ -51,18 +43,10 @@ module Dry
|
|
51
43
|
end
|
52
44
|
end
|
53
45
|
|
54
|
-
def self.options
|
55
|
-
config.options
|
56
|
-
end
|
57
|
-
|
58
46
|
def self.finalize(name, &block)
|
59
47
|
finalizers[name] = proc { block.(self) }
|
60
48
|
end
|
61
49
|
|
62
|
-
def self.configured?
|
63
|
-
@configured
|
64
|
-
end
|
65
|
-
|
66
50
|
def self.finalize!(&_block)
|
67
51
|
yield(self) if block_given?
|
68
52
|
|
@@ -171,9 +155,13 @@ module Dry
|
|
171
155
|
def self.load_paths!(*dirs)
|
172
156
|
dirs.map(&:to_s).each do |dir|
|
173
157
|
path = root.join(dir)
|
158
|
+
|
159
|
+
next if load_paths.include?(path)
|
160
|
+
|
174
161
|
load_paths << path
|
175
162
|
$LOAD_PATH.unshift(path.to_s)
|
176
163
|
end
|
164
|
+
|
177
165
|
self
|
178
166
|
end
|
179
167
|
|
data/spec/spec_helper.rb
CHANGED
@@ -40,11 +40,10 @@ RSpec.describe Dry::Component::Container, '.auto_register!' do
|
|
40
40
|
auto_register!('components')
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it { expect(Test::Container['foo']).to be_an_instance_of(Foo) }
|
45
45
|
it { expect(Test::Container['bar']).to eq(Bar) }
|
46
46
|
it { expect(Test::Container['bar'].call).to eq("Welcome to my Moe's Tavern!") }
|
47
47
|
it { expect(Test::Container['bar-baz']).to be_an_instance_of(Bar::Baz) }
|
48
48
|
end
|
49
|
-
|
50
49
|
end
|
data/spec/unit/container_spec.rb
CHANGED
@@ -120,10 +120,10 @@ RSpec.describe Dry::Component::Container do
|
|
120
120
|
|
121
121
|
it 'passes container to the finalizer block' do
|
122
122
|
class Test::Container < Dry::Component::Container
|
123
|
-
configure { |c| c.
|
123
|
+
configure { |c| c.name = :awesome }
|
124
124
|
|
125
125
|
finalize(:foo) do |container|
|
126
|
-
register(:w00t, container.config.
|
126
|
+
register(:w00t, container.config.name)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
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.3.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-06-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inflecto
|
@@ -134,7 +134,6 @@ files:
|
|
134
134
|
- dry-component.gemspec
|
135
135
|
- lib/dry-component.rb
|
136
136
|
- lib/dry/component.rb
|
137
|
-
- lib/dry/component/config.rb
|
138
137
|
- lib/dry/component/container.rb
|
139
138
|
- lib/dry/component/injector.rb
|
140
139
|
- lib/dry/component/loader.rb
|
@@ -168,7 +167,6 @@ files:
|
|
168
167
|
- spec/fixtures/test/lib/test/models/book.rb
|
169
168
|
- spec/fixtures/test/lib/test/models/user.rb
|
170
169
|
- spec/spec_helper.rb
|
171
|
-
- spec/unit/config_spec.rb
|
172
170
|
- spec/unit/container/auto_register_spec.rb
|
173
171
|
- spec/unit/container/import_spec.rb
|
174
172
|
- spec/unit/container_spec.rb
|
@@ -228,7 +226,6 @@ test_files:
|
|
228
226
|
- spec/fixtures/test/lib/test/models/book.rb
|
229
227
|
- spec/fixtures/test/lib/test/models/user.rb
|
230
228
|
- spec/spec_helper.rb
|
231
|
-
- spec/unit/config_spec.rb
|
232
229
|
- spec/unit/container/auto_register_spec.rb
|
233
230
|
- spec/unit/container/import_spec.rb
|
234
231
|
- spec/unit/container_spec.rb
|
data/lib/dry/component/config.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Dry
|
4
|
-
module Component
|
5
|
-
class Config
|
6
|
-
def self.load(root, name, env)
|
7
|
-
path = root.join('config').join("#{name}.yml")
|
8
|
-
|
9
|
-
return {} unless File.exist?(path)
|
10
|
-
|
11
|
-
yaml = YAML.load_file(path)
|
12
|
-
|
13
|
-
Class.new do
|
14
|
-
extend Dry::Configurable
|
15
|
-
|
16
|
-
yaml.fetch(env.to_s).each do |key, value|
|
17
|
-
setting key.downcase.to_sym, ENV.fetch(key, value)
|
18
|
-
end
|
19
|
-
end.config
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/spec/unit/config_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'dry/component/container'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Component::Config do
|
4
|
-
before do
|
5
|
-
class Test::App < Dry::Component::Container
|
6
|
-
configure do |config|
|
7
|
-
config.name = :application
|
8
|
-
config.root = SPEC_ROOT.join('fixtures/test').realpath
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class Test::SubApp < Dry::Component::Container
|
13
|
-
configure do |config|
|
14
|
-
config.name = :subapp
|
15
|
-
config.root = SPEC_ROOT.join('fixtures/test').realpath
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'loads config under component name' do
|
21
|
-
expect(Test::App.options.foo).to eql('bar')
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'allows different components to have different configurations' do
|
25
|
-
expect(Test::SubApp.options.bar).to eql('baz')
|
26
|
-
end
|
27
|
-
end
|