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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0a151b6a0ce9ddb00755568ae644cb809e6f13a
4
- data.tar.gz: b842f2c2e9acacd61444d82fa411a03bd6769e47
3
+ metadata.gz: af1f43e30b5d803695302f7f5b4ad31895f6b616
4
+ data.tar.gz: 8baa4806fe830062b49a59ccee87a9e3ff7534c4
5
5
  SHA512:
6
- metadata.gz: 828227b6d3b7847301a7958d325e377ca2833c7f1e7eb55af04dfe16b1eed7d3c4615511fa74ca2bebfbb9e9b8792298828da307c481f30e45cbd402f98a095f
7
- data.tar.gz: b2d9c11f9848feb81f5ccf1b22933e84a5a413abb8fc2133854c6a46c8f362bb31da6afb544c95500181b19127efba41662ba915cd639d9d71acfe2c2321d52d
6
+ metadata.gz: 837f8c57fdd029c221460729d9a8760dff10e6a1f915f97d4e28f14d6482e0c58f7f6d220204346e22f419b3839a9d294066639463ec960509ffcf23204b9c85
7
+ data.tar.gz: 2ca5ec7ef6d0bd47b99f0520d89a7a7785ab061b25363b2454905defd793b326f69a2b320eae7dc0c2fd778311890e32df6adf64ad58a4707c094360b036f5e1
data/lib/pinball.rb CHANGED
@@ -15,7 +15,6 @@ module Pinball
15
15
 
16
16
  attr_reader :dependencies
17
17
 
18
-
19
18
  def new(*args)
20
19
  object = allocate
21
20
  Container.instance.inject(object)
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
@@ -30,6 +30,7 @@ module Pinball
30
30
  end
31
31
 
32
32
  def initialize
33
+
33
34
  @items = {}
34
35
  end
35
36
 
@@ -1,3 +1,3 @@
1
1
  module Pinball
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -1,14 +1,22 @@
1
1
  require 'spec_helper.rb'
2
2
  require 'pinball'
3
3
 
4
- Pinball::Container.configure do
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.instance_variable_get('@dependencies')).to match_array([:baz, :bar])
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Sinyavsky