encase 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjY0NjkwNmNhNzFmNjhiY2IyZmVhYjU2YjE4OGU2MTcwMTkxZmY0ZA==
4
+ Yjk2YzExZTNhODI3MzhkNjEzYjU4ZmJiODdmY2Y2ODZiNTFkMzQzMQ==
5
5
  data.tar.gz: !binary |-
6
- MjgzYTUxZjNmMTgxNTA1NTVlN2Y4MDA5MWExYmE2NjFkYmNlNGUzNw==
6
+ ODFiZDJkZjNmNWIyMmJjOWY4YzdmMDIxODgzMTMwZTkyNjE5MDk5OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDllY2FhYmFmZTQ2YTUxNWU4NDVlMTZlMjNmMmM4M2QwMTkzNzYzMjQ4Njk3
10
- ZWRkZDg4OWU5YzQxNWQ4YTQ0NjliZGY1MWQzNzZhYThmZjAzNzVmZmQxMjM5
11
- MzE1ZTY5ZGE3MjFmODRkM2Y3NjJiMzk3MDBjOTg3Y2YxODNmNmY=
9
+ NzVkMGZkYzM2NTFlYjYyZDFjMWQxYTZjNGYzNTUyZmE0NGYyYzc5YTkyOWQw
10
+ ODE4NThmZjQxYmJlMDE0ZTEyNTQ2ODA3ZWIwNTdlOTA4ZjBkNmMzZmU0MzU3
11
+ MTlkNjA4ZWFlZTZmZjVlOWI5ZWYzOTlhYjE4NTg2NGMxODE2Y2E=
12
12
  data.tar.gz: !binary |-
13
- YjIzNWQ5MmQ2YjM2Y2Y1N2M1M2JmOGNkNmMwNzQ0N2NmMmQ4MDhmZWFiNWZh
14
- ZmIzOTdiYzkzMjg0ZDRhYjU3MWY1MjgyN2U3MDk4MWE4NjA5ZmUxMzliZTY4
15
- ZGVkMjE4ZGExMGIwOTZhOGViMTk3ZTY5NmI2YmZkYmNjZjMwZjU=
13
+ MDc3NzRlOTE5NDMxNDcxZmQ1YzA3NzY5YjFjMTc0ZDBhOTZjZGFlNDIwOTI1
14
+ OWZkNjAwMmU3NzQ4ZTcxNmY2MTQ5NzM5Y2ZmZTAxNjJkZTQxOGNhNzQzMjRl
15
+ ZTc1NDA4ZDNkMjBmYjdmNTY0Y2U2MmZkODc2MjljNmUyMjI0YjA=
@@ -3,3 +3,4 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.0
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.1.1
4
+
5
+ * Fixes `needs` lookup where parent classes `needs` were not
6
+ visible to child classes.
7
+ * Adds support chaining to DSL.
8
+
3
9
  ### 0.1.0
4
10
 
5
11
  * Initial Release
data/README.md CHANGED
@@ -278,6 +278,7 @@ Encase has been tested to work on these platforms.
278
278
  * ruby 1.9.2
279
279
  * ruby 1.9.3
280
280
  * ruby 2.0.0
281
+ * ruby 2.1.0
281
282
 
282
283
  ## Contributing
283
284
 
@@ -16,7 +16,7 @@ module Encase
16
16
  def inject(object)
17
17
  klass = object.class
18
18
  if klass.respond_to?(:needs_to_inject)
19
- needs_to_inject = klass.needs_to_inject
19
+ needs_to_inject = find_needs_to_inject(klass)
20
20
  needs_to_inject.each do |need|
21
21
  object.instance_variable_set(
22
22
  "@#{need}", lookup(need)
@@ -32,30 +32,47 @@ module Encase
32
32
  end
33
33
  end
34
34
 
35
+ def find_needs_to_inject(klass)
36
+ needs = []
37
+ klass.ancestors.each do |ancestor|
38
+ if ancestor.respond_to?(:needs_to_inject) && !ancestor.needs_to_inject.nil?
39
+ needs.concat(ancestor.needs_to_inject)
40
+ end
41
+ end
42
+
43
+ needs
44
+ end
45
+
35
46
  def register(type, key, value, block)
36
47
  item = ContainerItemFactory.build(type, self)
37
48
  item.store(key, value || block)
38
49
  @items[key] = item
50
+ self
39
51
  end
40
52
 
41
53
  def unregister(key)
42
54
  @items.delete(key)
55
+ self
43
56
  end
44
57
 
45
58
  def clear
46
59
  @items.clear
60
+ self
47
61
  end
48
62
 
49
63
  def object(key, value = nil, &block)
50
64
  register('object', key, value, block)
65
+ self
51
66
  end
52
67
 
53
68
  def factory(key, value = nil, &block)
54
69
  register('factory', key, value, block)
70
+ self
55
71
  end
56
72
 
57
73
  def singleton(key, value = nil, &block)
58
74
  register('singleton', key, value, block)
75
+ self
59
76
  end
60
77
 
61
78
  def lookup(key)
@@ -71,6 +88,7 @@ module Encase
71
88
 
72
89
  def configure(&block)
73
90
  instance_exec(&block)
91
+ self
74
92
  end
75
93
 
76
94
  def child
@@ -1,3 +1,3 @@
1
1
  module Encase
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -155,6 +155,15 @@ module Encase
155
155
  expect(dummy.injected).to be_true
156
156
  end
157
157
 
158
+ it 'can chain calls' do
159
+ c = container.object(:a, 'foo')
160
+ c.object(:b, 'bar')
161
+ c.factory(:c, Object)
162
+ c = c.singleton(:d, Object)
163
+
164
+ expect(c).to eq(container)
165
+ end
166
+
158
167
  context 'Performance', :benchmark => true do
159
168
  require 'benchmark'
160
169
 
@@ -198,5 +207,40 @@ module Encase
198
207
  expect(runtime).to be < 0.1
199
208
  end
200
209
  end
210
+
211
+ context 'Needs with class inheritance' do
212
+ it 'can recognize needs in parent class' do
213
+ class MyGrandParent
214
+ include Encase
215
+ needs :a
216
+ end
217
+
218
+ class MyParent < MyGrandParent
219
+ include Encase
220
+ needs :b
221
+ end
222
+
223
+ class MyChild < MyParent
224
+ include Encase
225
+ needs :c
226
+ end
227
+
228
+ class MyGrandChild < MyChild
229
+ end
230
+
231
+ container.configure do
232
+ object :a, 'A'
233
+ object :b, 'B'
234
+ object :c, 'C'
235
+
236
+ factory :me, MyGrandChild
237
+ end
238
+
239
+ me = container.lookup(:me)
240
+ expect(me.a).to eq('A')
241
+ expect(me.b).to eq('B')
242
+ expect(me.c).to eq('C')
243
+ end
244
+ end
201
245
  end
202
246
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darshan Sawardekar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-16 00:00:00.000000000 Z
11
+ date: 2014-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler