dependency_injection 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/examples/alias_definitions.rb +19 -0
- data/examples/alias_definitions.yml +8 -0
- data/examples/configurator_usage.rb +27 -0
- data/examples/configurator_usage.yml +10 -0
- data/examples/lazy_load_object.rb +37 -0
- data/examples/lazy_load_object.yml +8 -0
- data/examples/yaml_configuration_file.rb +1 -1
- data/examples/{services.yml → yaml_configuration_file.yml} +0 -0
- data/lib/dependency_injection/alias_definition.rb +14 -0
- data/lib/dependency_injection/container.rb +9 -2
- data/lib/dependency_injection/definition.rb +12 -1
- data/lib/dependency_injection/lazy_definition.rb +12 -0
- data/lib/dependency_injection/loaders/yaml.rb +17 -1
- data/lib/dependency_injection/proxy_object.rb +11 -0
- data/lib/dependency_injection/version.rb +1 -1
- data/test/dependency_injection/loaders/test_yaml.rb +63 -12
- data/test/dependency_injection/test_alias_definition.rb +15 -0
- data/test/dependency_injection/test_container.rb +24 -3
- data/test/dependency_injection/test_definition.rb +37 -0
- data/test/dependency_injection/test_lazy_definition.rb +13 -0
- data/test/dependency_injection/test_proxy_object.rb +15 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2116ad6a0f9eb9fef58b268cd9413aa4fd8177c3
|
4
|
+
data.tar.gz: ed1755da4b8037d366fc95c3693c86ac9b346b28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab60bdcc326a550b133d8406c459d072670af4f259a50eb5cc5c1c9edf33b671d6e544f1871e27b88e90027befeb0477c1c681e43a3f6de7a0ec52f2a913110a
|
7
|
+
data.tar.gz: 770dcddd3fe38639736abae27599ef504934050f29b3766ca79efba18b5fbcdb0c5c56ffda141485f2d52fb6990060073ac657f61be6fbd7a440af6ff3c97223
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dependency_injection/container'
|
2
|
+
require 'dependency_injection/loaders/yaml'
|
3
|
+
|
4
|
+
c = DependencyInjection::Container.new
|
5
|
+
loader = DependencyInjection::Loaders::Yaml.new(c)
|
6
|
+
loader.load(File.join(File.dirname(File.expand_path(__FILE__)), 'alias_definitions.yml'))
|
7
|
+
|
8
|
+
class Mailer
|
9
|
+
attr_accessor :transport
|
10
|
+
|
11
|
+
def send_mail(message)
|
12
|
+
puts "mail sent via #{self.transport}: #{message}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
puts c.get('my.mailer').class
|
17
|
+
# => Mailer
|
18
|
+
puts c.get('aliased.mailer').class
|
19
|
+
# => Mailer
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'dependency_injection/container'
|
2
|
+
require 'dependency_injection/loaders/yaml'
|
3
|
+
|
4
|
+
c = DependencyInjection::Container.new
|
5
|
+
loader = DependencyInjection::Loaders::Yaml.new(c)
|
6
|
+
loader.load(File.join(File.dirname(File.expand_path(__FILE__)), 'configurator_usage.yml'))
|
7
|
+
|
8
|
+
class MailerConfigurator
|
9
|
+
def initialize(transport)
|
10
|
+
@transport = transport
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure(mailer)
|
14
|
+
mailer.transport = @transport
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Mailer
|
19
|
+
attr_accessor :transport
|
20
|
+
|
21
|
+
def send_mail(message)
|
22
|
+
puts "mail sent via #{self.transport}: #{message}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
c.get('my.mailer').send_mail('Hello World')
|
27
|
+
# mail sent via sendmail: Hello World
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'dependency_injection/container'
|
2
|
+
require 'dependency_injection/loaders/yaml'
|
3
|
+
|
4
|
+
c = DependencyInjection::Container.new
|
5
|
+
loader = DependencyInjection::Loaders::Yaml.new(c)
|
6
|
+
loader.load(File.join(File.dirname(File.expand_path(__FILE__)), 'lazy_load_object.yml'))
|
7
|
+
|
8
|
+
class NewsletterManager
|
9
|
+
def initialize(mailer)
|
10
|
+
@mailer = mailer
|
11
|
+
end
|
12
|
+
|
13
|
+
def send_mail(message)
|
14
|
+
puts 'newletter'
|
15
|
+
@mailer.send_mail(message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Mailer
|
20
|
+
def initialize
|
21
|
+
puts 'mailer loaded'
|
22
|
+
end
|
23
|
+
|
24
|
+
def send_mail(message)
|
25
|
+
puts "mail sent via: #{message}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
puts c.get('my.mailer').class
|
30
|
+
# => ProxyObject
|
31
|
+
puts c.get('my.newsletter_manager').class
|
32
|
+
# => NewsletterManager
|
33
|
+
|
34
|
+
c.get('my.newsletter_manager').send_mail('Hello World')
|
35
|
+
# => newsletter
|
36
|
+
# mailer loaded
|
37
|
+
# mail sent : Hello World
|
@@ -3,7 +3,7 @@ require 'dependency_injection/loaders/yaml'
|
|
3
3
|
|
4
4
|
c = DependencyInjection::Container.new
|
5
5
|
loader = DependencyInjection::Loaders::Yaml.new(c)
|
6
|
-
loader.load(File.join(File.dirname(File.expand_path(__FILE__)), '
|
6
|
+
loader.load(File.join(File.dirname(File.expand_path(__FILE__)), 'yaml_configuration_file.yml'))
|
7
7
|
|
8
8
|
class NewsletterManager
|
9
9
|
def initialize(mailer)
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DependencyInjection
|
2
|
+
class AliasDefinition
|
3
|
+
attr_accessor :alias_definition_name
|
4
|
+
|
5
|
+
def initialize(alias_definition_name, container)
|
6
|
+
@container = container
|
7
|
+
self.alias_definition_name = alias_definition_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def object
|
11
|
+
@container.get(self.alias_definition_name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'dependency_injection/alias_definition'
|
1
2
|
require 'dependency_injection/definition'
|
3
|
+
require 'dependency_injection/lazy_definition'
|
2
4
|
|
3
5
|
module DependencyInjection
|
4
6
|
class Container
|
@@ -19,8 +21,13 @@ module DependencyInjection
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
def register(name, klass_name)
|
23
|
-
|
24
|
+
def register(name, klass_name, lazy=false)
|
25
|
+
definition = lazy ? LazyDefinition.new(klass_name, self) : Definition.new(klass_name, self)
|
26
|
+
@definitions[name] =definition
|
27
|
+
end
|
28
|
+
|
29
|
+
def register_alias(name, alias_definition_name)
|
30
|
+
@definitions[name] = AliasDefinition.new(alias_definition_name, self)
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
@@ -2,7 +2,7 @@ require 'active_support/core_ext/string/inflections'
|
|
2
2
|
|
3
3
|
module DependencyInjection
|
4
4
|
class Definition
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :arguments, :configurator, :klass_name, :method_calls
|
6
6
|
|
7
7
|
def initialize(klass_name, container)
|
8
8
|
@container = container
|
@@ -21,6 +21,12 @@ module DependencyInjection
|
|
21
21
|
self
|
22
22
|
end
|
23
23
|
|
24
|
+
def add_configurator(name, method_name)
|
25
|
+
self.configurator = [name, method_name]
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
24
30
|
def add_method_call(method_name, *arguments)
|
25
31
|
self.method_calls[method_name] = arguments
|
26
32
|
|
@@ -36,6 +42,11 @@ module DependencyInjection
|
|
36
42
|
|
37
43
|
@object = self.klass.new(*resolve(self.arguments))
|
38
44
|
self.method_calls.each { |method_name, arguments| @object.send(method_name, *resolve(arguments)) }
|
45
|
+
if self.configurator
|
46
|
+
name, method_name = self.configurator
|
47
|
+
configurator_object = resolve([name]).first
|
48
|
+
configurator_object.send(method_name, @object)
|
49
|
+
end
|
39
50
|
|
40
51
|
@object
|
41
52
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'dependency_injection/definition'
|
2
|
+
require 'dependency_injection/proxy_object'
|
3
|
+
|
4
|
+
module DependencyInjection
|
5
|
+
class LazyDefinition < Definition
|
6
|
+
def object
|
7
|
+
return @proxy_object if @proxy_object
|
8
|
+
|
9
|
+
@proxy_object = ProxyObject.new { super }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -15,6 +15,10 @@ module DependencyInjection
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
+
def add_aliased_service(name, aliased_service_name)
|
19
|
+
@container.register_alias(name, aliased_service_name)
|
20
|
+
end
|
21
|
+
|
18
22
|
def add_parameters(parameters)
|
19
23
|
parameters.each { |name, value| @container.add_parameter(name, value) }
|
20
24
|
end
|
@@ -24,8 +28,20 @@ module DependencyInjection
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def add_service(name, parameters)
|
27
|
-
|
31
|
+
if parameters['alias']
|
32
|
+
add_aliased_service(name, parameters['alias'])
|
33
|
+
else
|
34
|
+
add_standard_service(name, parameters)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_standard_service(name, parameters)
|
39
|
+
lazy_load = parameters['lazy'] || false
|
40
|
+
definition = @container.register(name, parameters['class'], lazy_load)
|
28
41
|
definition.add_arguments(*parameters['arguments']) if parameters['arguments']
|
42
|
+
if (configurator = parameters['configurator'])
|
43
|
+
definition.add_configurator(configurator[0], configurator[1])
|
44
|
+
end
|
29
45
|
if parameters['calls']
|
30
46
|
parameters['calls'].each { |method_name, arguments| definition.add_method_call(method_name, *arguments) }
|
31
47
|
end
|
@@ -35,6 +35,12 @@ class TestYaml < Minitest::Test
|
|
35
35
|
@yaml_loader.load('services.yml')
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_adding_aliased_service
|
39
|
+
@container.expects(:register_alias).with('my_alias', 'my_definition')
|
40
|
+
|
41
|
+
@yaml_loader.send(:add_aliased_service, 'my_alias', 'my_definition')
|
42
|
+
end
|
43
|
+
|
38
44
|
def test_adding_parameters
|
39
45
|
@container.expects(:add_parameter).with('key_1', 'value_1')
|
40
46
|
@container.expects(:add_parameter).with('key_2', 'value_2')
|
@@ -50,39 +56,84 @@ class TestYaml < Minitest::Test
|
|
50
56
|
'key_2' => { 'param_1' => 'value_1' }})
|
51
57
|
end
|
52
58
|
|
53
|
-
def
|
59
|
+
def test_adding_service_without_alias_parameters
|
60
|
+
@yaml_loader.expects(:add_aliased_service).never
|
61
|
+
@yaml_loader.expects(:add_standard_service).with('my_definition', { 'class' => 'MyKlass' })
|
62
|
+
|
63
|
+
@yaml_loader.send(:add_service, 'my_definition', { 'class' => 'MyKlass' })
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_adding_service_with_alias_parameters
|
67
|
+
@yaml_loader.expects(:add_aliased_service).with('my_alias', 'my_definition')
|
68
|
+
@yaml_loader.expects(:add_standard_service).never
|
69
|
+
|
70
|
+
@yaml_loader.send(:add_service, 'my_alias', { 'alias' => 'my_definition' })
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_adding_standard_service_as_lazy
|
74
|
+
@container.expects(:register).with('my_lazy_definition', 'MyLazyDefinition', true)
|
75
|
+
@yaml_loader.send(:add_standard_service, 'my_lazy_definition', { 'class' => 'MyLazyDefinition', 'lazy' => true })
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_adding_standard_service_as_not_lazy
|
79
|
+
@container.expects(:register).with('my_definition', 'MyDefinition', false)
|
80
|
+
@yaml_loader.send(:add_standard_service, 'my_definition', { 'class' => 'MyDefinition', 'lazy' => false })
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_adding_standard_service_with_default_lazy_value
|
84
|
+
@container.expects(:register).with('my_definition', 'MyDefinition', false)
|
85
|
+
@yaml_loader.send(:add_standard_service, 'my_definition', { 'class' => 'MyDefinition' })
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_adding_standard_service_without_parameters
|
54
89
|
definition = mock
|
55
|
-
@container.stubs(:register).with('key_1', 'MyKlass').returns(definition)
|
90
|
+
@container.stubs(:register).with('key_1', 'MyKlass', false).returns(definition)
|
56
91
|
definition.expects(:add_arguments).never
|
57
92
|
|
58
|
-
@yaml_loader.send(:
|
93
|
+
@yaml_loader.send(:add_standard_service, 'key_1', { 'class' => 'MyKlass' })
|
59
94
|
end
|
60
95
|
|
61
|
-
def
|
96
|
+
def test_adding_standard_service_with_parameters
|
62
97
|
definition = mock
|
63
|
-
@container.stubs(:register).with('key_1', 'MyKlass').returns(definition)
|
98
|
+
@container.stubs(:register).with('key_1', 'MyKlass', false).returns(definition)
|
64
99
|
definition.expects(:add_arguments).with('arg_1', 'arg_2')
|
65
100
|
|
66
|
-
@yaml_loader.send(:
|
101
|
+
@yaml_loader.send(:add_standard_service, 'key_1', { 'class' => 'MyKlass', 'arguments' => ['arg_1', 'arg_2'] })
|
67
102
|
end
|
68
103
|
|
69
|
-
def
|
104
|
+
def test_adding_standard_service_without_method_calls
|
70
105
|
definition = mock
|
71
|
-
@container.stubs(:register).with('key_1', 'MyKlass').returns(definition)
|
106
|
+
@container.stubs(:register).with('key_1', 'MyKlass', false).returns(definition)
|
72
107
|
definition.expects(:add_method_call).never
|
73
108
|
|
74
|
-
@yaml_loader.send(:
|
109
|
+
@yaml_loader.send(:add_standard_service, 'key_1', { 'class' => 'MyKlass' })
|
75
110
|
end
|
76
111
|
|
77
|
-
def
|
112
|
+
def test_adding_standard_service_with_method_calls
|
78
113
|
definition = mock
|
79
|
-
@container.stubs(:register).with('key_1', 'MyKlass').returns(definition)
|
114
|
+
@container.stubs(:register).with('key_1', 'MyKlass', false).returns(definition)
|
80
115
|
definition.expects(:add_method_call).with('method_1', 'arg_1')
|
81
116
|
definition.expects(:add_method_call).with('method_2', 'arg_1', 'arg_2')
|
82
117
|
definition.expects(:add_method_call).with('method_3', %w(arg_1 arg_2))
|
83
118
|
|
84
|
-
@yaml_loader.send(:
|
119
|
+
@yaml_loader.send(:add_standard_service, 'key_1', { 'class' => 'MyKlass', 'calls' => { 'method_1' => ['arg_1'],
|
85
120
|
'method_2' => ['arg_1', 'arg_2'],
|
86
121
|
'method_3' => [['arg_1', 'arg_2']] }})
|
87
122
|
end
|
123
|
+
|
124
|
+
def test_adding_standard_service_without_configurator
|
125
|
+
definition = mock
|
126
|
+
@container.stubs(:register).with('key_1', 'MyKlass', false).returns(definition)
|
127
|
+
definition.expects(:add_configurator).never
|
128
|
+
|
129
|
+
@yaml_loader.send(:add_standard_service, 'key_1', { 'class' => 'MyKlass' })
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_adding_standard_service_with_configurator
|
133
|
+
definition = mock
|
134
|
+
@container.stubs(:register).with('key_1', 'MyKlass', false).returns(definition)
|
135
|
+
definition.expects(:add_configurator).with('ConfiguratorKlass', 'method_name')
|
136
|
+
|
137
|
+
@yaml_loader.send(:add_standard_service, 'key_1', { 'class' => 'MyKlass', 'configurator' => ['ConfiguratorKlass', 'method_name'] })
|
138
|
+
end
|
88
139
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'dependency_injection/alias_definition'
|
3
|
+
|
4
|
+
class TestAliasDefinition < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@container = mock
|
7
|
+
@alias_definition = DependencyInjection::AliasDefinition.new('my_definition', @container)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_getting_object_to_container
|
11
|
+
@container.expects(:get).with('my_definition')
|
12
|
+
|
13
|
+
@alias_definition.object
|
14
|
+
end
|
15
|
+
end
|
@@ -3,13 +3,17 @@ require 'dependency_injection/container'
|
|
3
3
|
|
4
4
|
class TestContainer < Minitest::Test
|
5
5
|
def setup
|
6
|
-
@container
|
7
|
-
@
|
8
|
-
@
|
6
|
+
@container = DependencyInjection::Container.new
|
7
|
+
@alias = mock
|
8
|
+
@another_alias = mock
|
9
|
+
@final_object = mock
|
10
|
+
@definition = mock
|
9
11
|
@definition.stubs(:object).returns(@final_object)
|
10
12
|
@another_definition = mock
|
11
13
|
DependencyInjection::Definition.stubs(:new).with('MyDefinition', @container).returns(@definition)
|
12
14
|
DependencyInjection::Definition.stubs(:new).with('MyOtherDefinition', @container).returns(@another_definition)
|
15
|
+
DependencyInjection::AliasDefinition.stubs(:new).with('my_definition', @container).returns(@alias)
|
16
|
+
DependencyInjection::AliasDefinition.stubs(:new).with('my_other_definition', @container).returns(@another_alias)
|
13
17
|
end
|
14
18
|
|
15
19
|
def test_adding_new_parameter
|
@@ -40,6 +44,11 @@ class TestContainer < Minitest::Test
|
|
40
44
|
assert_equal({ 'my_definition' => @definition }, @container.definitions)
|
41
45
|
end
|
42
46
|
|
47
|
+
def test_registering_a_lazy_definition
|
48
|
+
DependencyInjection::LazyDefinition.stubs(:new).with('MyLazyDefinition', @container)
|
49
|
+
@container.register('my_lazy_definition', 'MyLazyDefinition', true)
|
50
|
+
end
|
51
|
+
|
43
52
|
def test_registering_a_class_return_a_definition_object
|
44
53
|
assert_equal(@definition, @container.register('my_definition', 'MyDefinition'))
|
45
54
|
end
|
@@ -51,4 +60,16 @@ class TestContainer < Minitest::Test
|
|
51
60
|
@container.register('my_definition', 'MyOtherDefinition')
|
52
61
|
assert_equal({ 'my_definition' => @another_definition }, @container.definitions)
|
53
62
|
end
|
63
|
+
|
64
|
+
def test_registering_an_alias_returns_an_alias_definition_object
|
65
|
+
assert_equal(@alias, @container.register_alias('my_alias', 'my_definition'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_registering_an_already_existing_alias_definition_replace_it
|
69
|
+
@container.register_alias('my_alias', 'my_definition')
|
70
|
+
assert_equal({ 'my_alias' => @alias }, @container.definitions)
|
71
|
+
|
72
|
+
@container.register_alias('my_alias', 'my_other_definition')
|
73
|
+
assert_equal({ 'my_alias' => @another_alias }, @container.definitions)
|
74
|
+
end
|
54
75
|
end
|
@@ -35,6 +35,16 @@ class TestDefinition < Minitest::Test
|
|
35
35
|
assert_equal(%w(first second third), @definition.arguments)
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_adding_configurator
|
39
|
+
@definition.add_configurator('ConfiguratorKlass', 'method_name')
|
40
|
+
|
41
|
+
assert_equal(%w(ConfiguratorKlass method_name), @definition.configurator)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_adding_configurator_returns_definition_object
|
45
|
+
assert_equal(@definition, @definition.add_configurator('ConfiguratorKlass', 'method_name'))
|
46
|
+
end
|
47
|
+
|
38
48
|
def test_adding_a_method_call_without_parameters
|
39
49
|
@definition.add_method_call('my_method')
|
40
50
|
|
@@ -93,6 +103,33 @@ class TestDefinition < Minitest::Test
|
|
93
103
|
@definition.object
|
94
104
|
end
|
95
105
|
|
106
|
+
def test_getting_object_without_configurator
|
107
|
+
configurator_object = mock
|
108
|
+
final_object = mock
|
109
|
+
final_class = mock
|
110
|
+
@definition.stubs(:klass).returns(final_class)
|
111
|
+
@definition.stubs(:resolve).with([]).returns([])
|
112
|
+
@definition.stubs(:resolve).with(['ConfiguratorKlass']).returns([configurator_object])
|
113
|
+
configurator_object.expects(:send).never
|
114
|
+
final_class.stubs(:new).with.returns(final_object)
|
115
|
+
|
116
|
+
@definition.object
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_getting_object_with_configurator
|
120
|
+
configurator_object = mock
|
121
|
+
final_object = mock
|
122
|
+
final_class = mock
|
123
|
+
@definition.stubs(:klass).returns(final_class)
|
124
|
+
@definition.stubs(:resolve).with([]).returns([])
|
125
|
+
@definition.stubs(:resolve).with(['ConfiguratorKlass']).returns([configurator_object])
|
126
|
+
@definition.add_configurator('ConfiguratorKlass', 'method_name')
|
127
|
+
configurator_object.expects(:send).with('method_name', final_object)
|
128
|
+
final_class.stubs(:new).with.returns(final_object)
|
129
|
+
|
130
|
+
@definition.object
|
131
|
+
end
|
132
|
+
|
96
133
|
def test_resolving_first_container_parameters
|
97
134
|
changed_arguments = mock
|
98
135
|
arguments = mock
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'dependency_injection/lazy_definition'
|
3
|
+
|
4
|
+
class TestLazyDefinition < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@container = mock
|
7
|
+
@lazy_definition = DependencyInjection::LazyDefinition.new('MyKlass', @container)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_getting_object_returns_a_proxy_object
|
11
|
+
assert_equal(DependencyInjection::ProxyObject, @lazy_definition.object.class)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'dependency_injection/proxy_object'
|
3
|
+
|
4
|
+
class TestProxyObject < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@object = mock
|
7
|
+
@proxy_object = DependencyInjection::ProxyObject.new { @object }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_calling_a_method_existing_on_object
|
11
|
+
@object.expects(:existing_method).with('arg_1', 'arg_2')
|
12
|
+
|
13
|
+
@proxy_object.existing_method('arg_1', 'arg_2')
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dependency_injection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Disneur
|
@@ -39,18 +39,30 @@ files:
|
|
39
39
|
- README.md
|
40
40
|
- Rakefile
|
41
41
|
- dependency_injection.gemspec
|
42
|
+
- examples/alias_definitions.rb
|
43
|
+
- examples/alias_definitions.yml
|
42
44
|
- examples/basic_usage.rb
|
45
|
+
- examples/configurator_usage.rb
|
46
|
+
- examples/configurator_usage.yml
|
43
47
|
- examples/global_container_parameter.rb
|
44
48
|
- examples/inject_a_reference_to_another_dependency.rb
|
45
|
-
- examples/
|
49
|
+
- examples/lazy_load_object.rb
|
50
|
+
- examples/lazy_load_object.yml
|
46
51
|
- examples/yaml_configuration_file.rb
|
52
|
+
- examples/yaml_configuration_file.yml
|
53
|
+
- lib/dependency_injection/alias_definition.rb
|
47
54
|
- lib/dependency_injection/container.rb
|
48
55
|
- lib/dependency_injection/definition.rb
|
56
|
+
- lib/dependency_injection/lazy_definition.rb
|
49
57
|
- lib/dependency_injection/loaders/yaml.rb
|
58
|
+
- lib/dependency_injection/proxy_object.rb
|
50
59
|
- lib/dependency_injection/version.rb
|
51
60
|
- test/dependency_injection/loaders/test_yaml.rb
|
61
|
+
- test/dependency_injection/test_alias_definition.rb
|
52
62
|
- test/dependency_injection/test_container.rb
|
53
63
|
- test/dependency_injection/test_definition.rb
|
64
|
+
- test/dependency_injection/test_lazy_definition.rb
|
65
|
+
- test/dependency_injection/test_proxy_object.rb
|
54
66
|
- test/test_helper.rb
|
55
67
|
homepage: https://github.com/kdisneur/dependency_injection-ruby
|
56
68
|
licenses:
|
@@ -78,6 +90,9 @@ specification_version: 4
|
|
78
90
|
summary: Dependency Injection system for Ruby
|
79
91
|
test_files:
|
80
92
|
- test/dependency_injection/loaders/test_yaml.rb
|
93
|
+
- test/dependency_injection/test_alias_definition.rb
|
81
94
|
- test/dependency_injection/test_container.rb
|
82
95
|
- test/dependency_injection/test_definition.rb
|
96
|
+
- test/dependency_injection/test_lazy_definition.rb
|
97
|
+
- test/dependency_injection/test_proxy_object.rb
|
83
98
|
- test/test_helper.rb
|