ioc 4.0.0 → 4.1.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/container.rb +3 -1
- data/spec/container_spec.rb +10 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beb7d05c11433d3fd20a45084e0c41ff64f166cf
|
4
|
+
data.tar.gz: cb699ee843c95a790b4af1b16d547f7d4e21ad79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0a1c1617334862a57ae5e65e86d8cd23ad7aaeae8b47b0b5f9ae5e3b450ddd4e16fa8999d055b9a227d3f630be94715424e3d0112ec0d663fc8e8543266d82e
|
7
|
+
data.tar.gz: 2f4aeb3e70503c3746ba63f5eb71870be9a17567be715ba4f091551d25cf9733e644ba290e62f753e8c41d7acc059e0bb5cc20e02dcc85b835e7e9d35f65fadb
|
data/ioc.gemspec
CHANGED
data/lib/ioc/container.rb
CHANGED
@@ -4,10 +4,12 @@ require "ioc/unresolvable_container"
|
|
4
4
|
|
5
5
|
module IOC
|
6
6
|
class Container
|
7
|
-
def initialize(parent=UnresolvableContainer.new)
|
7
|
+
def initialize(parent=UnresolvableContainer.new, &block)
|
8
8
|
@services = {}
|
9
9
|
@cache = {}
|
10
10
|
@parent = parent
|
11
|
+
|
12
|
+
self.instance_eval(&block) if block_given?
|
11
13
|
end
|
12
14
|
|
13
15
|
def register(service_name, klass=nil, &block)
|
data/spec/container_spec.rb
CHANGED
@@ -102,8 +102,16 @@ describe IOC::Container do
|
|
102
102
|
child_container.resolve(:myobject).must_equal(myobject)
|
103
103
|
end
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
it "can be initialized with a block" do
|
106
|
+
myobject = "a string object"
|
107
|
+
container = define_container do
|
108
|
+
register(:myobject){|c| myobject }
|
109
|
+
end
|
110
|
+
container.resolve(:myobject).must_equal(myobject)
|
111
|
+
end
|
112
|
+
|
113
|
+
def define_container(*args, &block)
|
114
|
+
IOC::Container.new(*args, &block)
|
107
115
|
end
|
108
116
|
|
109
117
|
def define_class_with_engine_dependency
|