injectable_dependencies 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/injectable_dependencies.rb +2 -3
- data/lib/injectable_dependencies/version.rb +1 -1
- data/spec/injectable_dependencies_spec.rb +29 -11
- 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: 8e5a62a3f85f8aa713eda4c0931e8f3274b26d92
|
4
|
+
data.tar.gz: 86d374a14c54ffd19d55960d03f7949580c78929
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d6040425e5bf06d404b3649fbe8776b5ed21fe5cf17977895723200956cce7bd123c8b2e2aa320162684e55d61cb9fb60ae0dace8761b5e49e1565322a28b1
|
7
|
+
data.tar.gz: 76a00acbd1367c1eab96f65e59b00343f472775709b813d5d71dccf4f3239bfa8fc14e6b67effdddeda45f94200634d1968f28113a1826c850a1c5759a4960ca
|
@@ -43,9 +43,8 @@ module InjectableDependencies
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def initialize(opts={})
|
46
|
-
|
47
|
-
|
48
|
-
end
|
46
|
+
dependencies = opts[:dependencies] || {}
|
47
|
+
initialize_dependencies(dependencies)
|
49
48
|
end
|
50
49
|
|
51
50
|
def initialize_dependencies(overrides = {})
|
@@ -42,6 +42,7 @@ describe InjectableDependencies do
|
|
42
42
|
it 'provides a default initializer that allows dependency overrides' do
|
43
43
|
dependant = dependent_class_with_default_initializer.new(:dependencies => {:bar => :bar_dependency})
|
44
44
|
expect(dependant.bar).to eq :bar_dependency
|
45
|
+
expect(dependant.foo).to be FooDependency
|
45
46
|
end
|
46
47
|
|
47
48
|
it 'does not persist dependencies between instances' do
|
@@ -61,20 +62,37 @@ describe InjectableDependencies do
|
|
61
62
|
end
|
62
63
|
|
63
64
|
context 'when a dependency is defined without a default implementation' do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
context 'when the dependent class has its own initializer' do
|
66
|
+
let(:dependent_class) {
|
67
|
+
Class.new do
|
68
|
+
include InjectableDependencies
|
69
|
+
dependency(:baz)
|
70
|
+
def initialize(dependencies = {})
|
71
|
+
initialize_dependencies(dependencies)
|
72
|
+
end
|
70
73
|
end
|
74
|
+
}
|
75
|
+
|
76
|
+
it 'raises an error if an implementation is not provided during dependency initialization' do
|
77
|
+
expect{ dependent_class.new }.to \
|
78
|
+
raise_error(InjectableDependencies::MissingImplementationError,
|
79
|
+
'No implementation was provided for dependency #baz')
|
71
80
|
end
|
72
|
-
|
81
|
+
end
|
73
82
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
83
|
+
context 'when the dependent class uses the default initializer' do
|
84
|
+
let(:dependent_class) {
|
85
|
+
Class.new do
|
86
|
+
include InjectableDependencies
|
87
|
+
dependency(:baz)
|
88
|
+
end
|
89
|
+
}
|
90
|
+
|
91
|
+
it 'raises an error if an implementation is not provided during dependency initialization' do
|
92
|
+
expect{ dependent_class.new }.to \
|
93
|
+
raise_error(InjectableDependencies::MissingImplementationError,
|
94
|
+
'No implementation was provided for dependency #baz')
|
95
|
+
end
|
78
96
|
end
|
79
97
|
end
|
80
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: injectable_dependencies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wilger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|