ioc 6.2.0 → 6.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ioc.gemspec +1 -1
- data/lib/ioc.rb +19 -9
- data/spec/ioc_spec.rb +8 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c62877ec0e92fac2a2297378168aa1686309e8b2
|
4
|
+
data.tar.gz: bf4cae27b6502b1204297b6b4a0629bc96b916c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a40d9523c1d6f54d833d0ab68e62fa469ddc107a724414eb2d5b05d04e35a417f2442fecb99d0342379f2dbba2060884e608611dfad2b220fdc0d897a44f0942
|
7
|
+
data.tar.gz: d24f6e44cc062c48f820bd39ec261334093796026e6dc7ea438e3e0cba6d39121c4af3ed9998b68a7dbf7c27a14b3491ac16299ba67e2f4acd4b91f447894e1d
|
data/ioc.gemspec
CHANGED
data/lib/ioc.rb
CHANGED
@@ -24,24 +24,34 @@ module IOC
|
|
24
24
|
if @services[key].is_a?(Proc)
|
25
25
|
@services[key].call(self)
|
26
26
|
else
|
27
|
-
dependencies = @services[key]
|
27
|
+
dependencies = get_dependencies(@services[key])
|
28
28
|
resolved_dependencies = dependencies.map{|dependency| resolve(dependency)}
|
29
29
|
@services[key].new(*resolved_dependencies)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def release
|
34
|
+
@cache = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def missing_dependencies
|
38
|
+
missing = []
|
39
|
+
class_services = @services.reject{|service| service.is_a?(Proc)}
|
40
|
+
class_services.values.each do |service|
|
41
|
+
dependencies = get_dependencies(service)
|
42
|
+
dependencies.each do |dependency|
|
43
|
+
unless @services.key?(dependency)
|
44
|
+
missing << dependency
|
45
|
+
end
|
38
46
|
end
|
39
47
|
end
|
40
|
-
|
48
|
+
missing.uniq
|
41
49
|
end
|
42
50
|
|
43
|
-
|
44
|
-
|
51
|
+
private
|
52
|
+
|
53
|
+
def get_dependencies(service)
|
54
|
+
service.instance_method(:initialize).parameters.map(&:last)
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
data/spec/ioc_spec.rb
CHANGED
@@ -44,21 +44,6 @@ describe IOC do
|
|
44
44
|
container.resolve(:myobject).must_equal(myobject)
|
45
45
|
end
|
46
46
|
|
47
|
-
it "can resolve services by type" do
|
48
|
-
container = IOC::Container.new
|
49
|
-
container.register(:engine, EngineFixture)
|
50
|
-
container.register(:motor, MotorFixture)
|
51
|
-
|
52
|
-
result = container.resolve_by_type(PropulsionFixture)
|
53
|
-
|
54
|
-
expected = [
|
55
|
-
container.resolve(:engine),
|
56
|
-
container.resolve(:motor)
|
57
|
-
]
|
58
|
-
|
59
|
-
result.must_equal(expected)
|
60
|
-
end
|
61
|
-
|
62
47
|
it "complains when resolving unknown service" do
|
63
48
|
container = IOC::Container.new
|
64
49
|
proc {
|
@@ -73,4 +58,12 @@ describe IOC do
|
|
73
58
|
container.register(:myclass, EngineFixture)
|
74
59
|
}.must_raise(IOC::DuplicateServiceError)
|
75
60
|
end
|
61
|
+
|
62
|
+
describe "#missing_dependencies" do
|
63
|
+
it "returns list of missing dependencies" do
|
64
|
+
container = IOC::Container.new
|
65
|
+
container.register(:car, CarFixture)
|
66
|
+
container.missing_dependencies.must_equal([:engine])
|
67
|
+
end
|
68
|
+
end
|
76
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ioc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Lott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|