ioc 6.2.0 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/ioc.gemspec +1 -1
  3. data/lib/ioc.rb +19 -9
  4. data/spec/ioc_spec.rb +8 -15
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 298698e6855ba0747c2e2cf86289b06486adef52
4
- data.tar.gz: 2d0bd0acb98c8cc6084d847c46a1a8fca9fcf301
3
+ metadata.gz: c62877ec0e92fac2a2297378168aa1686309e8b2
4
+ data.tar.gz: bf4cae27b6502b1204297b6b4a0629bc96b916c0
5
5
  SHA512:
6
- metadata.gz: 803e90589929c05c4f8abc1c319504d7ea9a14c145b00d5b1569942b25c57a99471cecd029b324d7f479584848350c48ad9397ad45e55a981559f8b0bbd9f8cc
7
- data.tar.gz: 08124d69e007ca26e12a1befb10c29f7415b4ac667b10d071d8a55dd1d9ca42759b21fa2b694d09cea2a80b838ac06c74bac2bd83095a0171092782a499b2efd
6
+ metadata.gz: a40d9523c1d6f54d833d0ab68e62fa469ddc107a724414eb2d5b05d04e35a417f2442fecb99d0342379f2dbba2060884e608611dfad2b220fdc0d897a44f0942
7
+ data.tar.gz: d24f6e44cc062c48f820bd39ec261334093796026e6dc7ea438e3e0cba6d39121c4af3ed9998b68a7dbf7c27a14b3491ac16299ba67e2f4acd4b91f447894e1d
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "ioc"
5
- spec.version = "6.2.0"
5
+ spec.version = "6.3.0"
6
6
  spec.authors = ["Erik Lott"]
7
7
  spec.email = ["erik.lott@kodio.io"]
8
8
  spec.summary = "Minimal dependency injection container for Ruby"
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].instance_method(:initialize).parameters.map(&:last)
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 resolve_by_type(type)
34
- resolved_services = []
35
- @services.each do |key, service|
36
- if service <= type
37
- resolved_services << resolve(key)
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
- resolved_services
48
+ missing.uniq
41
49
  end
42
50
 
43
- def release
44
- @cache = {}
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
@@ -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.2.0
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-30 00:00:00.000000000 Z
11
+ date: 2015-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler