pinball 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pinball.rb +0 -1
- data/lib/pinball/class.rb +5 -2
- data/lib/pinball/container.rb +1 -0
- data/lib/pinball/version.rb +1 -1
- data/spec/lib/pinball/class_spec.rb +48 -8
- 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: af1f43e30b5d803695302f7f5b4ad31895f6b616
|
4
|
+
data.tar.gz: 8baa4806fe830062b49a59ccee87a9e3ff7534c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 837f8c57fdd029c221460729d9a8760dff10e6a1f915f97d4e28f14d6482e0c58f7f6d220204346e22f419b3839a9d294066639463ec960509ffcf23204b9c85
|
7
|
+
data.tar.gz: 2ca5ec7ef6d0bd47b99f0520d89a7a7785ab061b25363b2454905defd793b326f69a2b320eae7dc0c2fd778311890e32df6adf64ad58a4707c094360b036f5e1
|
data/lib/pinball.rb
CHANGED
data/lib/pinball/class.rb
CHANGED
@@ -16,12 +16,15 @@ class Class
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
private
|
20
|
-
|
21
19
|
def check_pinball
|
22
20
|
unless self.is_a? Pinball
|
23
21
|
self.extend Pinball
|
24
22
|
self.send(:include, Pinball::Methods)
|
23
|
+
|
24
|
+
self.send(:define_singleton_method, :inherited) do |child|
|
25
|
+
child.instance_variable_set :@dependencies, self.dependencies
|
26
|
+
child.check_pinball
|
27
|
+
end
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/lib/pinball/container.rb
CHANGED
data/lib/pinball/version.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
require 'pinball'
|
3
3
|
|
4
|
-
|
5
|
-
define :baz, 0
|
6
|
-
define :bar, 0
|
7
|
-
end
|
4
|
+
|
8
5
|
|
9
6
|
describe Class do
|
7
|
+
before do
|
8
|
+
Pinball::Container.clear
|
9
|
+
|
10
|
+
Pinball::Container.configure do
|
11
|
+
define :baz, 0
|
12
|
+
define :bar, 1
|
13
|
+
define :egg, 2
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
10
18
|
let!(:foo) { Class.new }
|
11
|
-
|
19
|
+
|
12
20
|
describe '::inject' do
|
13
21
|
it 'responds to ::inject method' do
|
14
22
|
expect(foo.respond_to?(:inject)).to be_true
|
@@ -29,7 +37,7 @@ describe Class do
|
|
29
37
|
foo.inject :baz
|
30
38
|
foo.inject :bar
|
31
39
|
foo.inject :bar
|
32
|
-
expect(foo.
|
40
|
+
expect(foo.dependencies).to match_array([:baz, :bar])
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
@@ -40,12 +48,19 @@ describe Class do
|
|
40
48
|
end
|
41
49
|
|
42
50
|
it 'injects valid dependency' do
|
43
|
-
Pinball::Container.define :baz, 0
|
44
51
|
foo.class_inject :baz
|
45
52
|
expect(foo.baz).to eq(0)
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
56
|
+
describe '::dependencies' do
|
57
|
+
it 'returns list of dependencies' do
|
58
|
+
foo.inject :baz
|
59
|
+
foo.inject :bar
|
60
|
+
expect(foo.dependencies).to match_array([:baz, :bar])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
49
64
|
describe '#override_dependency' do
|
50
65
|
let!(:foo_instance) { foo.inject :baz ; foo.new }
|
51
66
|
|
@@ -54,7 +69,6 @@ describe Class do
|
|
54
69
|
it 'adds overridden dependency' do
|
55
70
|
subject
|
56
71
|
expect(foo_instance.overridden_dependencies[:baz]).not_to be_nil
|
57
|
-
#expect(foo_instance.baz).to eq(1)
|
58
72
|
end
|
59
73
|
|
60
74
|
it 'resolves overridden dependency' do
|
@@ -66,4 +80,30 @@ describe Class do
|
|
66
80
|
expect(subject).to eq(foo_instance)
|
67
81
|
end
|
68
82
|
end
|
83
|
+
|
84
|
+
context 'for subclass' do
|
85
|
+
let!(:foo) { Class.new { inject :baz ; inject :bar} }
|
86
|
+
let!(:fooo) { Class.new(foo) }
|
87
|
+
let!(:bazz) { Class.new{ inject :egg } }
|
88
|
+
|
89
|
+
let!(:foo_instance) { foo.new }
|
90
|
+
let!(:fooo_instance) { fooo.new }
|
91
|
+
|
92
|
+
describe '::dependencies' do
|
93
|
+
it 'returns ancestor\'s dependencies' do
|
94
|
+
expect(fooo.dependencies).to eq(foo.dependencies)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'injection in subclass' do
|
99
|
+
it 'returns dependency' do
|
100
|
+
expect(fooo_instance.baz).to eq(foo_instance.baz)
|
101
|
+
expect(fooo_instance.bar).to eq(foo_instance.bar)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'dependencies inherited only for descendants' do
|
105
|
+
expect(bazz.dependencies).to eq([:egg])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
69
109
|
end
|