alki 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +1 -1
  4. data/alki.gemspec +3 -0
  5. data/config/dsls.rb +4 -0
  6. data/lib/alki/assembly.rb +43 -0
  7. data/lib/alki/assembly_executor.rb +137 -0
  8. data/lib/alki/assembly_handler_base.rb +19 -0
  9. data/lib/alki/dsls/assembly.rb +24 -0
  10. data/lib/alki/dsls/assembly_type.rb +48 -0
  11. data/lib/alki/dsls/assembly_type_dsl.rb +21 -0
  12. data/lib/alki/dsls/assembly_types/assembly.rb +84 -0
  13. data/lib/alki/dsls/assembly_types/group.rb +46 -0
  14. data/lib/alki/dsls/assembly_types/load.rb +37 -0
  15. data/lib/alki/dsls/assembly_types/overlay.rb +9 -0
  16. data/lib/alki/dsls/assembly_types/service.rb +25 -0
  17. data/lib/alki/dsls/service.rb +22 -0
  18. data/lib/alki/test.rb +38 -18
  19. data/lib/alki/version.rb +1 -1
  20. data/lib/alki.rb +27 -21
  21. data/test/feature/create_package_test.rb +4 -3
  22. data/test/fixtures/example/config/{package.rb → assembly.rb} +5 -2
  23. data/test/fixtures/example/config/handlers.rb +1 -1
  24. data/test/fixtures/example/lib/example.rb +1 -1
  25. data/test/fixtures/example/lib/switch_handler.rb +2 -2
  26. data/test/fixtures/tlogger/config/assembly.rb +10 -0
  27. data/test/fixtures/tlogger/lib/tlogger.rb +3 -0
  28. data/test/integration/dsls/assembly_test.rb +28 -0
  29. data/test/integration/dsls/assembly_type_test.rb +58 -0
  30. data/test/integration/dsls/service_dsl_test.rb +57 -0
  31. metadata +69 -21
  32. data/lib/alki/class_builder.rb +0 -41
  33. data/lib/alki/dsl_builder.rb +0 -43
  34. data/lib/alki/group_builder.rb +0 -25
  35. data/lib/alki/group_dsl.rb +0 -98
  36. data/lib/alki/loader.rb +0 -32
  37. data/lib/alki/package.rb +0 -33
  38. data/lib/alki/package_builder.rb +0 -2
  39. data/lib/alki/package_executor.rb +0 -120
  40. data/lib/alki/package_processor.rb +0 -167
  41. data/lib/alki/standard_package.rb +0 -19
  42. data/lib/alki/util.rb +0 -35
  43. data/test/integration/class_builder_test.rb +0 -130
  44. data/test/integration/loader_test.rb +0 -36
  45. data/test/unit/package_processor_test.rb +0 -319
@@ -1,319 +0,0 @@
1
- require_relative '../test_helper'
2
- require 'alki/package_processor'
3
-
4
- describe Alki::PackageProcessor do
5
- def pkg(pkg,overrides ={})
6
- {
7
- type: :package,
8
- children: pkg,
9
- overrides: overrides
10
- }
11
- end
12
- def group(children={})
13
- {
14
- type: :group,
15
- children: children
16
- }
17
- end
18
- def svc(sym)
19
- {
20
- type: :service,
21
- block: -> { sym }
22
- }
23
- end
24
- def factory(sym)
25
- {
26
- type: :factory,
27
- block: -> { sym }
28
- }
29
- end
30
- before do
31
- @pe = Alki::PackageProcessor.new
32
- @pkg1 = {
33
- a: svc(:orig1_a),
34
- b: svc(:orig1_b),
35
- c: group
36
- }
37
- @desc = {
38
- a: group(
39
- test: svc(:a_test)
40
- ),
41
- b: svc(:b),
42
- test: svc(:test),
43
- pkg1: pkg(
44
- @pkg1,
45
- b: svc(:orig1_b_or)
46
- )
47
- }
48
- end
49
-
50
- describe :lookup do
51
- it 'should identify services and return their block and a scope' do
52
- pkg = {
53
- a: svc(:a)
54
- }
55
- result = @pe.lookup(pkg,[:a])
56
- result[:type].must_equal :service
57
- result[:block].call.must_equal :a
58
- result[:scope].must_be_instance_of Hash
59
- end
60
-
61
- it 'should identify factory and return their block and a scope' do
62
- pkg = {
63
- a: factory(:a)
64
- }
65
- result = @pe.lookup(pkg,[:a])
66
- result[:type].must_equal :factory
67
- result[:block].call.must_equal :a
68
- result[:scope].must_be_instance_of Hash
69
- end
70
-
71
- it 'should identify groups and return their children' do
72
- pkg2 = {
73
- e: svc(:e)
74
- }
75
- pkg = {
76
- a: svc(:a),
77
- b: group(
78
- c: svc(:c),
79
- d: pkg(
80
- pkg2,
81
- f: svc(:f)
82
- )
83
- ),
84
- }
85
- @pe.lookup(pkg,[]).must_equal(
86
- type: :group, children: {a: [:a], b: [:b]})
87
- @pe.lookup(pkg,[:b]).must_equal(
88
- type: :group, children: {c: [:b,:c],d: [:b,:d]})
89
- @pe.lookup(pkg,[:b,:d]).must_equal(
90
- type: :group, children: {e: [:b,:d,:e],f: [:b,:d,:f]})
91
- @pe.lookup(pkg,[:b,:d,:orig]).must_equal(
92
- type: :group, children: {e: [:b,:d,:orig,:e]})
93
- end
94
- end
95
-
96
- describe :lookup_scope do
97
- def scope(pkg,path)
98
- @pe.lookup(pkg,path)[:scope]
99
- end
100
-
101
- it 'should contain a root item for the tree root' do
102
- pkg = {
103
- a: svc(:a)
104
- }
105
- scope(pkg,[:a]).must_equal(root: [],a: [:a])
106
- end
107
-
108
- it 'should return all visible items for the given context' do
109
- pkg = {
110
- a: svc(:a),
111
- b: group(
112
- c: svc(:c),
113
- d: svc(:d),
114
- )
115
- }
116
- scope(pkg,[:b,:c]).must_equal(root: [], a: [:a], b: [:b], c: [:b,:c], d: [:b,:d])
117
- end
118
-
119
- it 'should respect shadowing of symbols' do
120
- pkg = {
121
- a: svc(:a),
122
- b: group(
123
- a: svc(:a),
124
- c: svc(:c),
125
- )
126
- }
127
- scope(pkg,[:b,:c]).must_equal(root: [], a: [:b,:a], b: [:b], c: [:b,:c])
128
- end
129
-
130
- it 'should hide parent scope of context is in a package' do
131
- pkg = {
132
- a: svc(:a),
133
- b: pkg(
134
- c: svc(:c),
135
- d: svc(:d),
136
- )
137
- }
138
- scope(pkg,[:b,:c]).must_equal(root: [:b], c: [:b,:c], d: [:b,:d])
139
- end
140
-
141
- it 'should respect package overrides' do
142
- pkg2 = {
143
- c: svc(:c),
144
- }
145
- pkg = {
146
- a: svc(:a),
147
- b: pkg(
148
- pkg2,
149
- d: svc(:d),
150
- )
151
- }
152
- scope(pkg,[:b,:c]).must_equal(root: [:b], c: [:b,:c], d: [:b,:d])
153
- end
154
-
155
- it 'should not change root and should add :orig symbol to override contexts' do
156
- pkg2 = {
157
- d: svc(:d),
158
- }
159
- pkg = {
160
- a: svc(:a),
161
- b: pkg(
162
- pkg2,
163
- c: svc(:c),
164
- )
165
- }
166
- scope(pkg,[:b,:c]).must_equal(root: [],pkg: [:b,:orig], c: [:b,:c], a: [:a], b: [:b])
167
- end
168
-
169
- it 'should respect :orig symbol in path to access non-overriden services' do
170
- pkg2 = {
171
- c: svc(:c),
172
- d: svc(:d),
173
- }
174
- pkg = {
175
- a: svc(:a),
176
- b: pkg(
177
- pkg2,
178
- c: svc(:c),
179
- )
180
- }
181
- scope(pkg,[:b,:orig,:c]).must_equal(root: [:b], c: [:b,:c], d: [:b,:d])
182
- end
183
-
184
- it 'should handle nested packages' do
185
- pkg2 = {
186
- e: svc(:e),
187
- }
188
- pkg = {
189
- a: svc(:a),
190
- b: pkg(
191
- c: svc(:c),
192
- d: pkg(
193
- pkg2,
194
- f: svc(:f),
195
- )
196
- )
197
- }
198
- scope(pkg,[:b,:d,:e]).must_equal(root: [:b,:d], e: [:b,:d,:e], f: [:b,:d,:f])
199
- scope(pkg,[:b,:d,:f]).must_equal(root: [:b], pkg: [:b,:d,:orig], d: [:b,:d], c: [:b,:c], f: [:b,:d,:f])
200
- end
201
-
202
- it 'should handle nested packages in overrides' do
203
- pkg2 = {
204
- c: svc(:c),
205
- }
206
- pkg3 = {
207
- e: svc(:e),
208
- }
209
- pkg = {
210
- a: svc(:a),
211
- b: pkg(
212
- pkg2,
213
- d: pkg(
214
- pkg3,
215
- f: svc(:f)
216
- )
217
- )
218
- }
219
- scope(pkg,[:b,:d,:e]).must_equal(root: [:b,:d], e: [:b,:d,:e], f: [:b,:d,:f])
220
- end
221
- end
222
-
223
- describe :lookup_overlays do
224
- def overlays(pkg,path)
225
- @pe.lookup(pkg,path)[:overlays].map{|o| o[:block]}
226
- end
227
-
228
- it 'should contain a root item for the tree root' do
229
- pkg = {
230
- a: svc(:a)
231
- }
232
- overlays(pkg,[:a]).must_equal([])
233
- end
234
-
235
- it 'should contain a root item for the tree root2' do
236
- pkg = {
237
- 'overlays' => [:o1,:o2],
238
- a: svc(:a)
239
- }
240
- overlays(pkg,[:a]).must_equal([:o1,:o2])
241
- end
242
-
243
- it 'should contain a root item for the tree root3' do
244
- pkg = {
245
- 'overlays' => [:o1,:o2],
246
- a: svc(:a),
247
- b: group(
248
- 'overlays' => [:o3,:o4],
249
- c: svc(:c)
250
- )
251
- }
252
- overlays(pkg,[:b,:c]).must_equal([:o1,:o2,:o3,:o4])
253
- end
254
-
255
- it 'should contain a root item for the tree root4' do
256
- pkg = {
257
- 'overlays' => [:o1],
258
- a: svc(:a),
259
- b: pkg(
260
- 'overlays' => [:o3,:o4],
261
- c: svc(:c)
262
- )
263
- }
264
- overlays(pkg,[:b,:c]).must_equal([:o1,:o3,:o4])
265
- end
266
-
267
- it 'should contain a root item for the tree root5' do
268
- pkg2 = {
269
- 'overlays' => [:o3],
270
- d: svc(:d),
271
- }
272
- pkg = {
273
- 'overlays' => [:o1],
274
- a: svc(:a),
275
- b: pkg(pkg2,
276
- 'overlays' => [:o2],
277
- c: svc(:c)
278
- )
279
- }
280
- overlays(pkg,[:b,:c]).must_equal([:o1,:o2,:o3])
281
- overlays(pkg,[:b,:d]).must_equal([:o1,:o2,:o3])
282
- end
283
-
284
- it 'should contain a root item for the tree root6' do
285
- pkg2 = {
286
- 'overlays' => [:o3],
287
- d: svc(:d),
288
- }
289
- pkg = {
290
- 'overlays' => [:o1],
291
- a: svc(:a),
292
- b: pkg(pkg2,
293
- 'overlays' => [:clear,:o2],
294
- c: svc(:c)
295
- )
296
- }
297
- overlays(pkg,[:b,:c]).must_equal([:o2,:o3])
298
- overlays(pkg,[:b,:d]).must_equal([:o2,:o3])
299
- end
300
-
301
- it 'should contain a root item for the tree root7' do
302
- pkg2 = {
303
- 'overlays' => [:clear,:o3],
304
- d: svc(:d),
305
- }
306
- pkg = {
307
- 'overlays' => [:o1],
308
- a: svc(:a),
309
- b: pkg(pkg2,
310
- 'overlays' => [:o2],
311
- c: svc(:c)
312
- )
313
- }
314
- overlays(pkg,[:b,:c]).must_equal([:o3])
315
- overlays(pkg,[:b,:d]).must_equal([:o3])
316
- end
317
-
318
- end
319
- end