jackbox 0.9.6.6 → 0.9.6.8

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.
@@ -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
- # some data
200
+ # some data
201
201
 
202
- def database_content
203
- %{car truck airplane boat}
204
- end
202
+ def database_content # could be any model
203
+ %{car truck airplane boat}
204
+ end
205
205
 
206
- # rendering helper controls
206
+ # rendering helper controls
207
207
 
208
- class MyWidgetClass
209
- def initialize(content)
210
- @content = content
211
- end
208
+ class MyWidget
209
+ def initialize(content)
210
+ @content = content
211
+ end
212
212
 
213
- def render
214
- "<div id='MyWidget'>#{@content}</div>"
215
- end
216
- end
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
- def dim(width, heigth)
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
- # somewhere in a view
221
+ attr_accessor :font, :width, :height
242
222
 
243
- browser = 'Safari'
244
- @content = database_content
223
+ def dim(width, heigth)
224
+ @width, @heigth = width, heigth
225
+ end
245
226
 
246
- my_widget = case browser
247
- when match(/Safari|Firefox|IE/)
248
- # debugger
249
- MyWidgetClass.new(@content).enrich(WidgetDecorator() do
250
-
251
- def render # override invoking JIT inheritance
252
- dim '600px', '200px' # normal inherited method call
253
- @font = 'helvetica'
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
- super()
256
- end
257
- end)
241
+ # somewhere in a view
258
242
 
259
- else
260
- MyWidgetClass.new(@content).enrich(WidgetDecorator() do
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
- super()
267
- end
268
- end)
269
- end
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
- MyWidgetClass.new(@content).enrich(WidgetDecorator() do
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
- MyWidgetClass.new(@content).enrich(WidgetDecorator() do
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
- WidgetDecorator(:implode)
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
- JD1 = trait :jd do
549
- def m1
550
- 1
551
+ suppress_warnings do
552
+ JD1 = trait :jd do
553
+ def m1
554
+ 1
555
+ end
551
556
  end
552
- end
553
- JD2 = jd do
554
- def m1
555
- super + 2
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
- o = Object.new
562
- o.enrich JD2, JD1
563
- o.m1.should == 3
564
-
565
- p = Object.new
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 'raise errors on decorator collusions' do
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 raise_error(ArgumentError)
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 raise_error(ArgumentError)
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 on external base" do
609
+ describe "jiti as decorators with external base" do
592
610
  before do
593
- JD1 = trait :jd do
594
- def m1
595
- super + 1
611
+ suppress_warnings do
612
+
613
+ class JDClass
614
+ def m1
615
+ 1
616
+ end
596
617
  end
597
- end
598
- JD2 = jd do
599
- def m1
600
- super + 2
618
+ JD1 = trait :jd do
619
+ def m1
620
+ super + 1
621
+ end
601
622
  end
602
- end
603
- class JDClass
604
- def m1
605
- 1
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 'can work like normal decorators' do
632
+ it 'works like normal decorators' do
611
633
 
612
- o = JDClass.new
613
- o.enrich JD2, JD1
614
- o.m1.should == 5
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 'raises errors on decorator collusions' do
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 JD1, JD1
628
- r.m1.should == 3
657
+ r.enrich(JD1).m1.should == 2
658
+ r.enrich(JD1).m1.should == 3
629
659
 
630
- }.to raise_error(ArgumentError)
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 raise_error(ArgumentError)
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
- # we run a process and make settings
56
- launch %{
57
- require 'jackbox'
58
-
59
- class Application
60
- include Prefs
61
-
62
- pref :data_path => "#{ENV['HOME']}/tmp/jackbox"
63
-
64
- def foo
65
- end
66
- end
67
-
68
- #...
69
-
70
- Application.data_path = "#{ENV['HOME']}/tmp/foo"
71
- }
72
- Process.waitall
73
-
74
- # After the previous invocation
75
- class Application
76
- include Prefs
77
-
78
- pref :data_path => "#{ENV['HOME']}/tmp/jackbox"
79
-
80
- def foo
81
- end
82
- end
83
-
84
- # ...
85
-
86
- Application.data_path.should == "#{ENV['HOME']}/tmp/foo"
87
-
88
- # ...
89
-
90
- Application.reset
91
- Application.data_path.should == "#{ENV['HOME']}/tmp/jackbox"
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
- jack :J1
18
- jack :K1
19
- jack :L1
20
- jack :M1
21
- jack :N1
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
- J1(:implode)
26
- K1(:implode)
27
- L1(:implode)
28
- M1(:implode)
29
- N1(:implode)
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 AA4
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
- AA4.new.n1m1
53
- AA4.new.n2m1
54
- AA4.new.n3m1
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 AA5
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
- AA5.new.daa
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 AA1
329
+ class A
325
330
  include J1()
326
331
  end
327
332
 
328
- AA1.new.mJ2.should == :mJ2
329
- AA1.new.mJ1.should == :mJ1
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 AA2
355
+ class A
351
356
  include K1()
352
357
  end
353
- AA2.new.mj2.should == :mj2
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
- AA2.new.mj3.should == :mj3
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 AA3
387
+ class A
383
388
  include M1()
384
389
  end
385
- AA3.new.mk2.should == :mk2
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
- AA3.new.mk3.should == :mk3
399
+ A.new.mk3.should == :mk3
395
400
 
396
401
  }.not_to raise_error
397
402