ioc 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ioc/container.rb +5 -15
- data/lib/ioc/version.rb +2 -2
- data/spec/ioc_spec.rb +1 -31
- 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: 870b95c905301c1b57ce0709dace5b4d1974ce57
|
4
|
+
data.tar.gz: 7c9f78022bdf6a1c3fa9cdd3773d2052a0c88a76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d65414dc5bfd8a28b67d6302151f1cedb1f15db580daf9fc5bdd2fb034dfe6807e118418286f646619959cd08272bdf79c879c06ad5c51a143d91424f86f4b
|
7
|
+
data.tar.gz: 32494aecb6e48f566b7cae7867ca137e682796af7bd5e1d9f4ea6a229c118c9295a3f5318baf91800f08e20c3bfcbb1dbcb7c243c184f6282c2b7d01ff5152ed
|
data/lib/ioc/container.rb
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
module IOC
|
2
2
|
class Container
|
3
|
-
|
4
|
-
|
5
|
-
installers = options[:installers] || []
|
6
|
-
parent = options[:parent]
|
7
|
-
container = new(parent)
|
8
|
-
[*installers].inject(container) do |c, installer|
|
3
|
+
def self.install(*installers)
|
4
|
+
[*installers].inject(new) do |c, installer|
|
9
5
|
installer.install(c)
|
10
6
|
c
|
11
7
|
end
|
12
8
|
end
|
13
9
|
|
14
|
-
def initialize
|
15
|
-
@resolver_factory = resolver_factory
|
10
|
+
def initialize
|
16
11
|
@resolvers = {}
|
17
12
|
@cache = {}
|
18
|
-
@parent = parent || Container
|
19
13
|
end
|
20
14
|
|
21
15
|
def register(name, object, options={})
|
22
16
|
raise(DuplicateRegistration, "Service '#{name}' has already been registered") if @resolvers.key?(name)
|
23
|
-
@resolvers[name] =
|
17
|
+
@resolvers[name] = ResolverFactory.new_instance(name, object, self, options)
|
24
18
|
end
|
25
19
|
|
26
20
|
def resolve(name)
|
@@ -32,11 +26,7 @@ module IOC
|
|
32
26
|
end
|
33
27
|
|
34
28
|
def resolver(name)
|
35
|
-
@resolvers[name] ||
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.resolver(name)
|
39
|
-
raise(UnknownService, "Service '#{name}' has not been registered")
|
29
|
+
@resolvers[name] || raise(UnknownService, "Service '#{name}' has not been registered")
|
40
30
|
end
|
41
31
|
end
|
42
32
|
end
|
data/lib/ioc/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module IOC
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "1.0.0"
|
3
|
+
end
|
data/spec/ioc_spec.rb
CHANGED
@@ -165,36 +165,6 @@ describe IOC::Container do
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
-
context 'when parent ioc container is assigned' do
|
169
|
-
it 'can traverse parent container to resolve object' do
|
170
|
-
parent = new_container
|
171
|
-
child = new_container(parent)
|
172
|
-
|
173
|
-
my_object = stub
|
174
|
-
parent.register(:myobj, my_object, :as => :instance)
|
175
|
-
child.resolve(:myobj).must_equal(my_object)
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'cannot travers sibling containers to resolve object' do
|
179
|
-
parent = new_container
|
180
|
-
son = new_container(parent)
|
181
|
-
daughter = new_container(parent)
|
182
|
-
|
183
|
-
my_object = stub
|
184
|
-
daughter.register(:myobj, my_object, :as => :instance)
|
185
|
-
proc { son.resolve(:myobj) }.must_raise(IOC::UnknownService)
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'cannot be traversed by parent container' do
|
189
|
-
parent = new_container
|
190
|
-
child = new_container(parent)
|
191
|
-
|
192
|
-
my_object = stub
|
193
|
-
child.register(:myobj, my_object, :as => :instance)
|
194
|
-
proc { parent.resolve(:myobj) }.must_raise(IOC::UnknownService)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
168
|
it 'can register components using an installer' do
|
199
169
|
installer_class = Class.new do
|
200
170
|
def self.install(c)
|
@@ -202,7 +172,7 @@ describe IOC::Container do
|
|
202
172
|
end
|
203
173
|
end
|
204
174
|
|
205
|
-
container = IOC::Container.install(
|
175
|
+
container = IOC::Container.install(installer_class)
|
206
176
|
container.resolve(:myobj).must_equal('I was resolved')
|
207
177
|
end
|
208
178
|
|
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: 0.
|
4
|
+
version: 1.0.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: 2014-02-
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|