ioc 6.3.0 → 6.3.1
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 +9 -3
- data/spec/ioc_spec.rb +5 -3
- 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: 550e95377f2d7c55428caecb1b664c0d25295a7a
|
4
|
+
data.tar.gz: 1e2b6f814f3f73680b080fa8b7d7eba8dbf830c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc548d109366734e551471965818a9b0a0e5658628f95863b9f5cb30d1021161cf33046af4070fc8dbd8848430ba68c930c39b06b51db920e826c25ca4dee224
|
7
|
+
data.tar.gz: c2bea3eedf2150087df8eb66fd94fd78e64cc69e803f556ec507d71d67d1063453c92d1cfbe221a62ea19968eabef66d281fbd3eb8caba76cb0367274f1b944f
|
data/ioc.gemspec
CHANGED
data/lib/ioc.rb
CHANGED
@@ -3,6 +3,7 @@ module IOC
|
|
3
3
|
class DuplicateServiceError < IOCError; end
|
4
4
|
class RegistrationError < IOCError; end
|
5
5
|
class UnknownServiceError < IOCError; end
|
6
|
+
class MissingDependenciesError < IOCError; end
|
6
7
|
|
7
8
|
class Container
|
8
9
|
def initialize
|
@@ -17,9 +18,10 @@ module IOC
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def resolve(key)
|
20
|
-
return @cache[key] if @cache.key?(key)
|
21
21
|
raise(UnknownServiceError, "Service '#{key}' not registered") unless @services.key?(key)
|
22
22
|
|
23
|
+
return @cache[key] if @cache.key?(key)
|
24
|
+
|
23
25
|
@cache[key] =
|
24
26
|
if @services[key].is_a?(Proc)
|
25
27
|
@services[key].call(self)
|
@@ -34,7 +36,7 @@ module IOC
|
|
34
36
|
@cache = {}
|
35
37
|
end
|
36
38
|
|
37
|
-
def
|
39
|
+
def validate!
|
38
40
|
missing = []
|
39
41
|
class_services = @services.reject{|service| service.is_a?(Proc)}
|
40
42
|
class_services.values.each do |service|
|
@@ -45,7 +47,11 @@ module IOC
|
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
48
|
-
missing.uniq
|
50
|
+
missing.uniq!
|
51
|
+
|
52
|
+
unless missing.empty?
|
53
|
+
raise(MissingDependenciesError, "missing dependencies: '#{missing.join(', ')}'")
|
54
|
+
end
|
49
55
|
end
|
50
56
|
|
51
57
|
private
|
data/spec/ioc_spec.rb
CHANGED
@@ -59,11 +59,13 @@ describe IOC do
|
|
59
59
|
}.must_raise(IOC::DuplicateServiceError)
|
60
60
|
end
|
61
61
|
|
62
|
-
describe "#
|
63
|
-
it "
|
62
|
+
describe "#validate!" do
|
63
|
+
it "complains if dependencies are missing" do
|
64
64
|
container = IOC::Container.new
|
65
65
|
container.register(:car, CarFixture)
|
66
|
-
|
66
|
+
proc {
|
67
|
+
container.validate!
|
68
|
+
}.must_raise(IOC::MissingDependenciesError)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
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.3.
|
4
|
+
version: 6.3.1
|
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-
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|