ioc_rb 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/ioc_rb/bean_factory.rb +1 -1
- data/lib/ioc_rb/bean_metadata.rb +10 -6
- data/lib/ioc_rb/version.rb +1 -1
- data/spec/ioc_rb/inject_spec.rb +13 -3
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/ioc_rb/bean_factory.rb
CHANGED
@@ -57,9 +57,9 @@ class IocRb::BeanFactory
|
|
57
57
|
bean_class = bean_metadata.bean_class.split('::').inject(Object) do |mod, class_name|
|
58
58
|
mod.const_get(class_name)
|
59
59
|
end
|
60
|
+
bean_metadata.fetch_attrs!(bean_class)
|
60
61
|
end
|
61
62
|
bean = bean_metadata.instance ? bean_class.new : bean_class
|
62
|
-
|
63
63
|
if bean_metadata.has_factory_method?
|
64
64
|
set_bean_dependencies(bean, bean_metadata)
|
65
65
|
bean = bean.send(bean_metadata.factory_method)
|
data/lib/ioc_rb/bean_metadata.rb
CHANGED
@@ -24,18 +24,22 @@ class IocRb::BeanMetadata
|
|
24
24
|
@factory_method = options[:factory_method]
|
25
25
|
@attrs = []
|
26
26
|
|
27
|
-
|
28
|
-
@bean_class._iocrb_injectable_attrs.each do |attr, options|
|
29
|
-
options[:ref] ||= attr
|
30
|
-
@attrs << IocRb::BeanMetadata::Attribute.new(attr, options)
|
31
|
-
end
|
32
|
-
end
|
27
|
+
fetch_attrs!(@bean_class)
|
33
28
|
|
34
29
|
if block
|
35
30
|
Dsl.new(@attrs).instance_exec(&block)
|
36
31
|
end
|
37
32
|
end
|
38
33
|
|
34
|
+
def fetch_attrs!(klass)
|
35
|
+
if klass.respond_to?(:_iocrb_injectable_attrs)
|
36
|
+
klass._iocrb_injectable_attrs.each do |attr, options|
|
37
|
+
options[:ref] ||= attr
|
38
|
+
@attrs << IocRb::BeanMetadata::Attribute.new(attr, options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
39
43
|
def has_factory_method?
|
40
44
|
!!@factory_method
|
41
45
|
end
|
data/lib/ioc_rb/version.rb
CHANGED
data/spec/ioc_rb/inject_spec.rb
CHANGED
@@ -7,6 +7,10 @@ describe "Object.inject" do
|
|
7
7
|
inject :contacts_repository
|
8
8
|
inject :validator, ref: :contact_validator
|
9
9
|
end
|
10
|
+
class ContactBookService
|
11
|
+
inject :contacts_repository
|
12
|
+
inject :validator, ref: :contact_validator
|
13
|
+
end
|
10
14
|
class ContactsRepository
|
11
15
|
end
|
12
16
|
class ContactValidator
|
@@ -14,9 +18,10 @@ describe "Object.inject" do
|
|
14
18
|
|
15
19
|
let(:container) do
|
16
20
|
IocRb::Container.new do |c|
|
17
|
-
c.bean(:contacts_repository,
|
18
|
-
c.bean(:contact_validator,
|
19
|
-
c.bean(:contact_book,
|
21
|
+
c.bean(:contacts_repository, class: ContactsRepository)
|
22
|
+
c.bean(:contact_validator, class: ContactValidator)
|
23
|
+
c.bean(:contact_book, class: ContactBook)
|
24
|
+
c.bean(:contact_book_service, class: "ContactBookService")
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
@@ -25,6 +30,11 @@ describe "Object.inject" do
|
|
25
30
|
container[:contact_book].validator.should be_a(ContactValidator)
|
26
31
|
end
|
27
32
|
|
33
|
+
it "should lazy autowire dependencies for string class names" do
|
34
|
+
container[:contact_book_service].contacts_repository.should be_a(ContactsRepository)
|
35
|
+
container[:contact_book_service].validator.should be_a(ContactValidator)
|
36
|
+
end
|
37
|
+
|
28
38
|
it "should raise ArgumentError if non-symbol passed as dependency name" do
|
29
39
|
expect do
|
30
40
|
class SomeClass
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ioc_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Albert Gazizov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
prerelease: false
|
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
segments:
|
124
124
|
- 0
|
125
|
-
hash:
|
125
|
+
hash: 1078915959922104396
|
126
126
|
version: '0'
|
127
127
|
none: false
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
segments:
|
133
133
|
- 0
|
134
|
-
hash:
|
134
|
+
hash: 1078915959922104396
|
135
135
|
version: '0'
|
136
136
|
none: false
|
137
137
|
requirements: []
|