jackbox 0.9.6.6 → 0.9.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/LICENSE.lic +0 -0
- data/LICENSE.txt +7 -1
- data/README.md +509 -406
- data/Rakefile +5 -6
- data/Vagrantfile +77 -0
- data/bin/test-jacks +13 -0
- data/jackbox.gemspec +2 -2
- data/lib/jackbox.rb +1 -1
- data/lib/jackbox/examples/dir.rb +2 -7
- data/lib/jackbox/injectors.rb +1 -1
- data/lib/jackbox/injectors/coda.rb +1 -1
- data/lib/jackbox/injectors/prelude.rb +1 -1
- data/lib/jackbox/rake.rb +1 -1
- data/lib/jackbox/tools/prefs.rb +1 -1
- data/lib/jackbox/version.rb +1 -1
- data/spec/bin/jackup_cmd_shared.rb +2 -1
- data/spec/bin/jackup_cmd_spec.rb +4 -7
- data/spec/lib/jackbox/examples/dir_spec.rb +52 -17
- data/spec/lib/jackbox/injector_composition_spec.rb +554 -85
- data/spec/lib/jackbox/injector_inheritance_spec.rb +122 -75
- data/spec/lib/jackbox/injector_introspection_spec.rb +129 -187
- data/spec/lib/jackbox/injector_namespacing_spec.rb +19 -9
- data/spec/lib/jackbox/injector_spec.rb +2 -2
- data/spec/lib/jackbox/injector_versioning_spec.rb +37 -14
- data/spec/lib/jackbox/jiti_rules_spec.rb +536 -272
- data/spec/lib/jackbox/patterns_spec.rb +142 -105
- data/spec/lib/jackbox/prefs_spec.rb +50 -39
- data/spec/lib/jackbox/vmc_spec.rb +33 -28
- data/spec/lib/jackbox_spec.rb +39 -12
- data/spec/spec_helper.rb +33 -89
- data/work +8 -0
- metadata +26 -41
@@ -197,76 +197,79 @@ describe 'some use cases', :traits do
|
|
197
197
|
|
198
198
|
a 'different way of doing it using: JIT inheritance' do
|
199
199
|
|
200
|
-
|
200
|
+
# some data
|
201
201
|
|
202
|
-
|
203
|
-
|
204
|
-
|
202
|
+
def database_content # could be any model
|
203
|
+
%{car truck airplane boat}
|
204
|
+
end
|
205
205
|
|
206
|
-
|
206
|
+
# rendering helper controls
|
207
207
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
208
|
+
class MyWidget
|
209
|
+
def initialize(content)
|
210
|
+
@content = content
|
211
|
+
end
|
212
212
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
213
|
+
def render
|
214
|
+
"<div id='MyWidget'>#{@content}</div>"
|
215
|
+
end
|
216
|
+
end
|
217
217
|
|
218
|
-
|
219
|
-
MainDecorator = trait :WidgetDecorator do
|
220
|
-
|
221
|
-
attr_accessor :font, :width, :height
|
222
218
|
|
223
|
-
|
224
|
-
@width, @heigth = width, heigth
|
225
|
-
end
|
226
|
-
|
227
|
-
def render
|
228
|
-
%{
|
229
|
-
<style>
|
230
|
-
#MyWidget{
|
231
|
-
font: 14px, #{@font};
|
232
|
-
width:#{@width};
|
233
|
-
height: #{@heigth}
|
234
|
-
}
|
235
|
-
</style>
|
236
|
-
#{super()}
|
237
|
-
}
|
238
|
-
end
|
239
|
-
end
|
219
|
+
MainFace = trait :WidgetFace do # our trait
|
240
220
|
|
241
|
-
|
221
|
+
attr_accessor :font, :width, :height
|
242
222
|
|
243
|
-
|
244
|
-
|
223
|
+
def dim(width, heigth)
|
224
|
+
@width, @heigth = width, heigth
|
225
|
+
end
|
245
226
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
227
|
+
def render
|
228
|
+
%{
|
229
|
+
<style>
|
230
|
+
#MyWidget{
|
231
|
+
font: 14px, #{@font};
|
232
|
+
width:#{@width};
|
233
|
+
height: #{@heigth}
|
234
|
+
}
|
235
|
+
</style>
|
236
|
+
#{super()}
|
237
|
+
}
|
238
|
+
end
|
239
|
+
end
|
254
240
|
|
255
|
-
|
256
|
-
end
|
257
|
-
end)
|
241
|
+
# somewhere in a view
|
258
242
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
def render # override invoking JIT inheritance
|
263
|
-
dim '200px', '600px' # normal inherited method call
|
264
|
-
@font ='arial'
|
243
|
+
browser = 'Safari' # the user selected media
|
244
|
+
@content = database_content
|
265
245
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
246
|
+
|
247
|
+
my_widget = case browser
|
248
|
+
when match(/Safari|Firefox|IE/)
|
249
|
+
|
250
|
+
MyWidget.new(@content).enrich(WidgetFace() do
|
251
|
+
|
252
|
+
def render # override invoking JIT inheritance
|
253
|
+
dim '600px', '200px' # normal inherited method call
|
254
|
+
@font = 'helvetica'
|
255
|
+
|
256
|
+
super()
|
257
|
+
end
|
258
|
+
end)
|
259
|
+
|
260
|
+
else
|
261
|
+
|
262
|
+
MyWidget.new(@content).enrich(WidgetFace() do
|
263
|
+
|
264
|
+
def render # override invoking JIT inheritance
|
265
|
+
dim '200px', '600px' # normal inherited method call
|
266
|
+
@font ='arial'
|
267
|
+
|
268
|
+
super()
|
269
|
+
end
|
270
|
+
end)
|
271
|
+
|
272
|
+
end
|
270
273
|
|
271
274
|
# expect(WidgetDecorator().ancestors).to eq([WidgetDecorator(), MainDecorator])
|
272
275
|
|
@@ -291,7 +294,7 @@ describe 'some use cases', :traits do
|
|
291
294
|
my_widget = case browser
|
292
295
|
when match(/Safari|Firefox|IE/)
|
293
296
|
# debugger
|
294
|
-
|
297
|
+
MyWidget.new(@content).enrich(WidgetFace() do
|
295
298
|
|
296
299
|
def render
|
297
300
|
dim '600px', '200px'
|
@@ -301,7 +304,7 @@ describe 'some use cases', :traits do
|
|
301
304
|
end
|
302
305
|
end)
|
303
306
|
else
|
304
|
-
|
307
|
+
MyWidget.new(@content).enrich(WidgetFace() do
|
305
308
|
def render
|
306
309
|
dim '200px', '600px'
|
307
310
|
@font ='arial'
|
@@ -325,7 +328,7 @@ describe 'some use cases', :traits do
|
|
325
328
|
}.split.join
|
326
329
|
)
|
327
330
|
|
328
|
-
|
331
|
+
WidgetFace(:implode)
|
329
332
|
|
330
333
|
end
|
331
334
|
|
@@ -545,96 +548,130 @@ describe 'some use cases', :traits do
|
|
545
548
|
|
546
549
|
describe "jiti as decorators with internal base" do
|
547
550
|
before do
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
+
suppress_warnings do
|
552
|
+
JD1 = trait :jd do
|
553
|
+
def m1
|
554
|
+
1
|
555
|
+
end
|
551
556
|
end
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
557
|
+
JD2 = jd do
|
558
|
+
def m1
|
559
|
+
super + 2
|
560
|
+
end
|
556
561
|
end
|
557
562
|
end
|
558
563
|
end
|
564
|
+
|
559
565
|
it 'works like normal decorators' do
|
560
566
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
p.enrich JD1, JD2
|
567
|
-
p.m1.should == 1
|
567
|
+
suppress_warnings do
|
568
|
+
o = Object.new
|
569
|
+
o.enrich JD2, JD1
|
570
|
+
o.m1.should == 3
|
571
|
+
end
|
568
572
|
|
569
573
|
end
|
570
574
|
|
571
|
-
it '
|
572
|
-
|
575
|
+
it 'issues warnings on decorator collusions' do
|
576
|
+
|
577
|
+
expect { # same as above without #suppress_warnings
|
578
|
+
|
579
|
+
o = Object.new
|
580
|
+
o.enrich JD2, JD1
|
581
|
+
o.m1.should == 3
|
582
|
+
|
583
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
573
584
|
expect{
|
574
585
|
|
575
586
|
r = Object.new
|
576
587
|
r.enrich JD1, JD1
|
577
588
|
r.m1.should == 1
|
578
589
|
|
579
|
-
}.to
|
590
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
591
|
+
expect{
|
592
|
+
|
593
|
+
p = Object.new
|
594
|
+
p.enrich JD1, JD2
|
595
|
+
p.m1.should == 1
|
596
|
+
|
597
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
580
598
|
expect{
|
581
599
|
|
582
600
|
q = Object.new
|
583
601
|
q.enrich JD2, JD2
|
584
602
|
q.m1.should == 5
|
585
603
|
|
586
|
-
}.to
|
604
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
587
605
|
|
588
606
|
end
|
589
607
|
end
|
590
608
|
|
591
|
-
describe "jiti as decorators
|
609
|
+
describe "jiti as decorators with external base" do
|
592
610
|
before do
|
593
|
-
|
594
|
-
|
595
|
-
|
611
|
+
suppress_warnings do
|
612
|
+
|
613
|
+
class JDClass
|
614
|
+
def m1
|
615
|
+
1
|
616
|
+
end
|
596
617
|
end
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
618
|
+
JD1 = trait :jd do
|
619
|
+
def m1
|
620
|
+
super + 1
|
621
|
+
end
|
601
622
|
end
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
623
|
+
JD2 = jd do
|
624
|
+
def m1
|
625
|
+
super + 2
|
626
|
+
end
|
606
627
|
end
|
628
|
+
|
607
629
|
end
|
608
630
|
end
|
609
631
|
|
610
|
-
it '
|
632
|
+
it 'works like normal decorators' do
|
611
633
|
|
612
|
-
|
613
|
-
|
614
|
-
|
634
|
+
suppress_warnings do
|
635
|
+
o = JDClass.new
|
636
|
+
o.enrich(JD1).m1.should == 2
|
637
|
+
o.enrich(JD2)
|
638
|
+
o.m1.should == 5
|
639
|
+
end
|
640
|
+
|
615
641
|
|
616
|
-
p = JDClass.new
|
617
|
-
p.enrich JD1, JD2
|
618
|
-
p.m1.should == 5
|
619
|
-
|
620
642
|
end
|
621
643
|
|
622
|
-
it '
|
644
|
+
it 'should issue warnings for colluding ancestors' do
|
623
645
|
|
624
|
-
expect{
|
646
|
+
expect {
|
647
|
+
|
648
|
+
o = JDClass.new
|
649
|
+
o.enrich(JD1).m1.should == 2
|
650
|
+
o.enrich(JD2)
|
651
|
+
o.m1.should == 5
|
652
|
+
|
653
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
654
|
+
expect {
|
625
655
|
|
626
656
|
r = JDClass.new
|
627
|
-
r.enrich
|
628
|
-
r.m1.should == 3
|
657
|
+
r.enrich(JD1).m1.should == 2
|
658
|
+
r.enrich(JD1).m1.should == 3
|
629
659
|
|
630
|
-
}.to
|
660
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
661
|
+
expect{
|
662
|
+
|
663
|
+
p = JDClass.new
|
664
|
+
p.enrich JD1, JD2
|
665
|
+
p.m1.should == 5
|
666
|
+
|
667
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
631
668
|
expect{
|
632
669
|
|
633
670
|
q = JDClass.new
|
634
671
|
q.enrich JD2, JD2
|
635
672
|
q.m1.should == 6
|
636
673
|
|
637
|
-
}.to
|
674
|
+
}.to output(a_string_starting_with('warning')).to_stderr
|
638
675
|
|
639
676
|
end
|
640
677
|
end
|
@@ -9,6 +9,17 @@ include Injectors
|
|
9
9
|
|
10
10
|
describe 'what Prefs does' do
|
11
11
|
|
12
|
+
# def launch program
|
13
|
+
# case
|
14
|
+
# when OS.windows?
|
15
|
+
# return system "ruby.exe", program if File.exists?(program)
|
16
|
+
# system "ruby.exe", '-e', program
|
17
|
+
# else
|
18
|
+
# return system "/usr/bin/env ruby", program if File.exists?(program)
|
19
|
+
# system "/usr/bin/env ruby", '-e', program
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
12
23
|
it 'creates module level attribute methods' do
|
13
24
|
module Tester
|
14
25
|
extend Prefs
|
@@ -51,45 +62,45 @@ describe 'what Prefs does' do
|
|
51
62
|
Jester.value.should == 10
|
52
63
|
end
|
53
64
|
|
54
|
-
it 'persists across processes' do
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
65
|
+
# it 'persists across processes' do
|
66
|
+
# # we run a process and make settings
|
67
|
+
# launch %{
|
68
|
+
# require 'jackbox'
|
69
|
+
#
|
70
|
+
# class Application
|
71
|
+
# include Prefs
|
72
|
+
#
|
73
|
+
# pref :data_path => "#{ENV['HOME']}/tmp/jackbox"
|
74
|
+
#
|
75
|
+
# def foo
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# #...
|
80
|
+
#
|
81
|
+
# Application.data_path = "#{ENV['HOME']}/tmp/foo"
|
82
|
+
# }
|
83
|
+
# Process.waitall
|
84
|
+
#
|
85
|
+
# # After the previous invocation
|
86
|
+
# class Application
|
87
|
+
# include Prefs
|
88
|
+
#
|
89
|
+
# pref :data_path => "#{ENV['HOME']}/tmp/jackbox"
|
90
|
+
#
|
91
|
+
# def foo
|
92
|
+
# end
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# # ...
|
96
|
+
#
|
97
|
+
# Application.data_path.should == "#{ENV['HOME']}/tmp/foo"
|
98
|
+
#
|
99
|
+
# # ...
|
100
|
+
#
|
101
|
+
# Application.reset
|
102
|
+
# Application.data_path.should == "#{ENV['HOME']}/tmp/jackbox"
|
103
|
+
# end
|
93
104
|
|
94
105
|
it 'should allow definition of prefs outside the module definition' do
|
95
106
|
lambda{
|
@@ -14,24 +14,31 @@ include Injectors
|
|
14
14
|
describe "VMC (Virtual Method Cache)" do
|
15
15
|
|
16
16
|
before do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
suppress_warnings do
|
18
|
+
jack :J1
|
19
|
+
jack :K1
|
20
|
+
jack :L1
|
21
|
+
jack :M1
|
22
|
+
jack :N1
|
23
|
+
A = Class.new
|
24
|
+
B = Class.new
|
25
|
+
end
|
22
26
|
end
|
23
|
-
|
24
27
|
after do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
suppress_warnings do
|
29
|
+
A = nil
|
30
|
+
B = nil
|
31
|
+
J1(:implode)
|
32
|
+
K1(:implode)
|
33
|
+
L1(:implode)
|
34
|
+
M1(:implode)
|
35
|
+
N1(:implode)
|
36
|
+
end
|
30
37
|
end
|
31
38
|
|
32
39
|
it 'goes 3 deep' do
|
33
40
|
|
34
|
-
class
|
41
|
+
class A
|
35
42
|
inject J1()
|
36
43
|
end
|
37
44
|
J1 do
|
@@ -49,15 +56,15 @@ describe "VMC (Virtual Method Cache)" do
|
|
49
56
|
end
|
50
57
|
end
|
51
58
|
# debugger
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
A.new.n1m1
|
60
|
+
A.new.n2m1
|
61
|
+
A.new.n3m1
|
55
62
|
|
56
63
|
end
|
57
64
|
|
58
65
|
it 'goes even deeper' do
|
59
66
|
|
60
|
-
class
|
67
|
+
class A
|
61
68
|
inject J1()
|
62
69
|
end
|
63
70
|
J1 do
|
@@ -73,7 +80,7 @@ describe "VMC (Virtual Method Cache)" do
|
|
73
80
|
def daa
|
74
81
|
end
|
75
82
|
end
|
76
|
-
|
83
|
+
A.new.daa
|
77
84
|
|
78
85
|
end
|
79
86
|
|
@@ -306,8 +313,6 @@ describe "VMC (Virtual Method Cache)" do
|
|
306
313
|
trait :J2
|
307
314
|
trait :J3
|
308
315
|
|
309
|
-
class AA1
|
310
|
-
end
|
311
316
|
J1 do
|
312
317
|
include J2()
|
313
318
|
end
|
@@ -321,12 +326,12 @@ describe "VMC (Virtual Method Cache)" do
|
|
321
326
|
:mJ1
|
322
327
|
end
|
323
328
|
end
|
324
|
-
class
|
329
|
+
class A
|
325
330
|
include J1()
|
326
331
|
end
|
327
332
|
|
328
|
-
|
329
|
-
|
333
|
+
A.new.mJ2.should == :mJ2
|
334
|
+
A.new.mJ1.should == :mJ1
|
330
335
|
|
331
336
|
}.not_to raise_error
|
332
337
|
|
@@ -347,10 +352,10 @@ describe "VMC (Virtual Method Cache)" do
|
|
347
352
|
end
|
348
353
|
end
|
349
354
|
end
|
350
|
-
class
|
355
|
+
class A
|
351
356
|
include K1()
|
352
357
|
end
|
353
|
-
|
358
|
+
A.new.mj2.should == :mj2
|
354
359
|
K2 do
|
355
360
|
include K3() do
|
356
361
|
def mj3 # virtual cache method with another indirect
|
@@ -358,7 +363,7 @@ describe "VMC (Virtual Method Cache)" do
|
|
358
363
|
end
|
359
364
|
end
|
360
365
|
end
|
361
|
-
|
366
|
+
A.new.mj3.should == :mj3
|
362
367
|
|
363
368
|
}.not_to raise_error
|
364
369
|
|
@@ -379,10 +384,10 @@ describe "VMC (Virtual Method Cache)" do
|
|
379
384
|
end
|
380
385
|
end
|
381
386
|
end
|
382
|
-
class
|
387
|
+
class A
|
383
388
|
include M1()
|
384
389
|
end
|
385
|
-
|
390
|
+
A.new.mk2.should == :mk2
|
386
391
|
M2 do
|
387
392
|
include M3()
|
388
393
|
end
|
@@ -391,7 +396,7 @@ describe "VMC (Virtual Method Cache)" do
|
|
391
396
|
:mk3
|
392
397
|
end
|
393
398
|
end
|
394
|
-
|
399
|
+
A.new.mk3.should == :mk3
|
395
400
|
|
396
401
|
}.not_to raise_error
|
397
402
|
|