ioc 6.3.0 → 6.3.1

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 +9 -3
  4. data/spec/ioc_spec.rb +5 -3
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c62877ec0e92fac2a2297378168aa1686309e8b2
4
- data.tar.gz: bf4cae27b6502b1204297b6b4a0629bc96b916c0
3
+ metadata.gz: 550e95377f2d7c55428caecb1b664c0d25295a7a
4
+ data.tar.gz: 1e2b6f814f3f73680b080fa8b7d7eba8dbf830c5
5
5
  SHA512:
6
- metadata.gz: a40d9523c1d6f54d833d0ab68e62fa469ddc107a724414eb2d5b05d04e35a417f2442fecb99d0342379f2dbba2060884e608611dfad2b220fdc0d897a44f0942
7
- data.tar.gz: d24f6e44cc062c48f820bd39ec261334093796026e6dc7ea438e3e0cba6d39121c4af3ed9998b68a7dbf7c27a14b3491ac16299ba67e2f4acd4b91f447894e1d
6
+ metadata.gz: cc548d109366734e551471965818a9b0a0e5658628f95863b9f5cb30d1021161cf33046af4070fc8dbd8848430ba68c930c39b06b51db920e826c25ca4dee224
7
+ data.tar.gz: c2bea3eedf2150087df8eb66fd94fd78e64cc69e803f556ec507d71d67d1063453c92d1cfbe221a62ea19968eabef66d281fbd3eb8caba76cb0367274f1b944f
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "ioc"
5
- spec.version = "6.3.0"
5
+ spec.version = "6.3.1"
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
@@ -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 missing_dependencies
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
@@ -59,11 +59,13 @@ describe IOC do
59
59
  }.must_raise(IOC::DuplicateServiceError)
60
60
  end
61
61
 
62
- describe "#missing_dependencies" do
63
- it "returns list of missing dependencies" do
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
- container.missing_dependencies.must_equal([:engine])
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.0
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-05-31 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler