jackbox 0.9.6.3 → 0.9.6.6
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 +5 -13
- data/CHANGES.txt +38 -4
- data/LICENSE.lic +0 -0
- data/README.md +568 -364
- data/lib/jackbox.rb +1 -1
- data/lib/jackbox/injectors.rb +1 -1
- data/lib/jackbox/injectors/coda.rb +2 -0
- data/lib/jackbox/injectors/prelude.rb +2 -0
- data/lib/jackbox/rake.rb +1 -1
- data/lib/jackbox/tools/prefs.rb +1 -1
- data/lib/jackbox/version.rb +1 -1
- data/spec/lib/jackbox/injector_composition_spec.rb +111 -111
- data/spec/lib/jackbox/injector_directives_spec.rb +25 -27
- data/spec/lib/jackbox/injector_inheritance_spec.rb +610 -1004
- data/spec/lib/jackbox/injector_introspection_spec.rb +265 -219
- data/spec/lib/jackbox/injector_namespacing_spec.rb +17 -17
- data/spec/lib/jackbox/injector_spec.rb +26 -0
- data/spec/lib/jackbox/injector_versioning_spec.rb +37 -37
- data/spec/lib/jackbox/jiti_rules_spec.rb +663 -0
- data/spec/lib/jackbox/patterns_spec.rb +224 -122
- data/spec/lib/jackbox/prefs_spec.rb +4 -4
- data/spec/lib/jackbox/reclassing_spec.rb +154 -406
- data/spec/lib/jackbox/vmc_spec.rb +169 -10
- data/spec/lib/jackbox_spec.rb +241 -131
- metadata +26 -26
- data/spec/lib/jackbox/examples/dx_spec.rb +0 -346
@@ -2,12 +2,12 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
=begin rdoc
|
4
4
|
This file contains the specs for the GOF Decorator Pattern and
|
5
|
-
Strategy Pattern use cases for
|
5
|
+
Strategy Pattern use cases for traits.
|
6
6
|
=end
|
7
7
|
|
8
8
|
include Injectors
|
9
9
|
|
10
|
-
describe 'some use cases', :
|
10
|
+
describe 'some use cases', :traits do
|
11
11
|
|
12
12
|
describe 'GOF Decortors is one use of this codebase. Traditionally this is only partially solved in Ruby through PORO
|
13
13
|
decorators or the use of modules with the problems of loss of class identity for the former
|
@@ -22,12 +22,12 @@ describe 'some use cases', :injectors do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# debugger
|
25
|
-
|
25
|
+
trait :milk do
|
26
26
|
def cost
|
27
27
|
super() + 0.30
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
trait :vanilla do
|
31
31
|
def cost
|
32
32
|
super() + 0.15
|
33
33
|
end
|
@@ -59,7 +59,7 @@ describe 'some use cases', :injectors do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
cup = Coffee.new.enrich(milk).enrich(vanilla).enrich(vanilla)
|
62
|
-
cup.
|
62
|
+
cup.traits.sym_list.should == [:vanilla, :vanilla, :milk]
|
63
63
|
cup.cost.should == 2.10
|
64
64
|
cup.should be_instance_of(Coffee)
|
65
65
|
|
@@ -96,13 +96,13 @@ describe 'some use cases', :injectors do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
cup.enrich(vanilla)
|
99
|
-
cup.
|
99
|
+
cup.traits.sym_list.should == [:vanilla, :vanilla, :milk]
|
100
100
|
cup.cost.should == 2.10
|
101
101
|
cup.appearance.should == 'extra red vanilla'
|
102
102
|
|
103
103
|
end
|
104
104
|
|
105
|
-
a 'bigger example using normal Injector inheritance' do
|
105
|
+
a 'bigger example using normal Injector inheritance on web rendering' do
|
106
106
|
|
107
107
|
# some data
|
108
108
|
|
@@ -122,7 +122,7 @@ describe 'some use cases', :injectors do
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
|
125
|
+
trait :WidgetDecorator do
|
126
126
|
attr_reader :width, :height
|
127
127
|
|
128
128
|
def dim(width, heigth)
|
@@ -216,7 +216,7 @@ describe 'some use cases', :injectors do
|
|
216
216
|
end
|
217
217
|
|
218
218
|
|
219
|
-
MainDecorator =
|
219
|
+
MainDecorator = trait :WidgetDecorator do
|
220
220
|
|
221
221
|
attr_accessor :font, :width, :height
|
222
222
|
|
@@ -268,7 +268,7 @@ describe 'some use cases', :injectors do
|
|
268
268
|
end)
|
269
269
|
end
|
270
270
|
|
271
|
-
expect(WidgetDecorator().ancestors).to eq([WidgetDecorator(), MainDecorator])
|
271
|
+
# expect(WidgetDecorator().ancestors).to eq([WidgetDecorator(), MainDecorator])
|
272
272
|
|
273
273
|
expect(
|
274
274
|
my_widget.render.split.join).to eq( # split.join used for comparison
|
@@ -285,45 +285,45 @@ describe 'some use cases', :injectors do
|
|
285
285
|
)
|
286
286
|
|
287
287
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
288
|
+
browser = 'mobile'
|
289
|
+
@content = database_content
|
290
|
+
|
291
|
+
my_widget = case browser
|
292
|
+
when match(/Safari|Firefox|IE/)
|
293
|
+
# debugger
|
294
|
+
MyWidgetClass.new(@content).enrich(WidgetDecorator() do
|
295
|
+
|
296
|
+
def render
|
297
|
+
dim '600px', '200px'
|
298
|
+
@font ='helvetica'
|
299
|
+
|
300
|
+
super()
|
301
|
+
end
|
302
|
+
end)
|
303
|
+
else
|
304
|
+
MyWidgetClass.new(@content).enrich(WidgetDecorator() do
|
305
|
+
def render
|
306
|
+
dim '200px', '600px'
|
307
|
+
@font ='arial'
|
308
|
+
|
309
|
+
super()
|
310
|
+
end
|
311
|
+
end)
|
312
|
+
end
|
313
|
+
expect(
|
314
|
+
|
315
|
+
my_widget.render.split.join).to eq( # split.join used for comparison
|
316
|
+
%{
|
317
|
+
<style>
|
318
|
+
#MyWidget {
|
319
|
+
font: 14px, arial;
|
320
|
+
width:200px;
|
321
|
+
height:600px
|
322
|
+
}
|
323
|
+
</style>
|
324
|
+
<div id='MyWidget'>car truck airplane boat</div>
|
325
|
+
}.split.join
|
326
|
+
)
|
327
327
|
|
328
328
|
WidgetDecorator(:implode)
|
329
329
|
|
@@ -351,12 +351,12 @@ describe 'some use cases', :injectors do
|
|
351
351
|
end
|
352
352
|
end
|
353
353
|
|
354
|
-
|
354
|
+
trait :Sweedish do
|
355
355
|
def brew
|
356
356
|
@strategy = 'sweedish-'
|
357
357
|
end
|
358
358
|
end
|
359
|
-
|
359
|
+
trait :French do
|
360
360
|
def brew
|
361
361
|
@strategy ='french-'
|
362
362
|
end
|
@@ -377,12 +377,12 @@ describe 'some use cases', :injectors do
|
|
377
377
|
|
378
378
|
this 'can be further enhanced by mixing it with the above decorator pattern' do
|
379
379
|
|
380
|
-
|
380
|
+
trait :Russian do
|
381
381
|
def brew
|
382
382
|
@strategy = super.to_s + 'vodka-'
|
383
383
|
end
|
384
384
|
end
|
385
|
-
|
385
|
+
trait :Scotish do
|
386
386
|
def brew
|
387
387
|
@strategy = super.to_s + 'wiskey-'
|
388
388
|
end
|
@@ -400,7 +400,7 @@ describe 'some use cases', :injectors do
|
|
400
400
|
a new one' do
|
401
401
|
|
402
402
|
class Tea < Coffee # Tea is a type of coffee ;~Q)
|
403
|
-
|
403
|
+
trait :SpecialStrategy do
|
404
404
|
def brew
|
405
405
|
@strategy = 'special'
|
406
406
|
end
|
@@ -436,107 +436,209 @@ describe 'some use cases', :injectors do
|
|
436
436
|
|
437
437
|
describe "further Jackbox Injector workflows" do
|
438
438
|
|
439
|
-
|
439
|
+
describe 'Delayed Decorator pattern'do
|
440
|
+
it "allows adding decorators with function to be defined at later statge" do
|
440
441
|
|
441
|
-
|
442
|
-
|
443
|
-
|
442
|
+
class Widget
|
443
|
+
def cost
|
444
|
+
1
|
445
|
+
end
|
444
446
|
end
|
445
|
-
|
446
|
-
w = Widget.new
|
447
|
+
w = Widget.new
|
447
448
|
|
448
|
-
|
449
|
-
|
449
|
+
trait :decorator
|
450
|
+
w.enrich decorator, decorator, decorator, decorator
|
450
451
|
|
451
|
-
|
452
|
-
|
452
|
+
# user input
|
453
|
+
bid = 3.5
|
453
454
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
455
|
+
# define function
|
456
|
+
decorator do
|
457
|
+
# Global define
|
458
|
+
define_method :cost do
|
459
|
+
super() + bid
|
460
|
+
end
|
459
461
|
end
|
460
|
-
end
|
461
462
|
|
462
|
-
|
463
|
+
w.cost.should == 15
|
463
464
|
|
465
|
+
end
|
464
466
|
end
|
465
467
|
|
466
|
-
|
468
|
+
describe 'Super pattern (no its not a superlative pattern)' do
|
469
|
+
it "allows self-terminating recursion workflow using super" do
|
467
470
|
|
468
|
-
|
471
|
+
jack :Superb
|
469
472
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
473
|
+
Superb do
|
474
|
+
def process string, additives, index
|
475
|
+
str = string.gsub('o', additives.slice!(index))
|
476
|
+
super(string, additives, index) + str rescue str
|
477
|
+
end
|
478
|
+
extend Superb(), Superb(), Superb()
|
479
|
+
end
|
477
480
|
|
478
|
-
|
479
|
-
|
481
|
+
Superb().process( 'food ', 'aeiu', 0 ).should == 'fuud fiid feed faad '
|
482
|
+
Superb(:implode)
|
480
483
|
|
484
|
+
end
|
481
485
|
end
|
486
|
+
|
487
|
+
describe 'Solutions Pattern' do
|
488
|
+
it 'allows trying several solutions in workflow using soft tags' do
|
482
489
|
|
483
|
-
|
490
|
+
###########################################################################
|
491
|
+
# For a specific example of what can be accomplished using this workflow #
|
492
|
+
# please refer to the examples directory under transformers spec #
|
493
|
+
# #
|
494
|
+
# #########################################################################
|
495
|
+
|
496
|
+
jack :Solution
|
484
497
|
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
498
|
+
Solution( :tag ) do
|
499
|
+
def solution
|
500
|
+
1
|
501
|
+
end
|
502
|
+
end
|
503
|
+
Solution( :tag ) do
|
504
|
+
def solution
|
505
|
+
2
|
506
|
+
end
|
507
|
+
end
|
508
|
+
Solution( :tag ) do
|
509
|
+
def solution
|
510
|
+
3
|
511
|
+
end
|
512
|
+
end
|
490
513
|
|
491
|
-
jack :Solution
|
492
514
|
|
493
|
-
|
494
|
-
|
495
|
-
|
515
|
+
class Client
|
516
|
+
inject Solution()
|
517
|
+
|
518
|
+
def self.solve
|
519
|
+
Solution().tags.each { |e|
|
520
|
+
update e
|
521
|
+
puts new.solution rescue nil
|
522
|
+
}
|
523
|
+
|
524
|
+
# or...
|
525
|
+
|
526
|
+
solutions = Solution().tags.each
|
527
|
+
begin
|
528
|
+
update solutions.next
|
529
|
+
puts solved = new().solution()
|
530
|
+
end until solved
|
531
|
+
solved
|
532
|
+
end
|
533
|
+
|
496
534
|
end
|
535
|
+
|
536
|
+
$stdout.should_receive(:puts).with(1)
|
537
|
+
$stdout.should_receive(:puts).with(2)
|
538
|
+
$stdout.should_receive(:puts).with(3)
|
539
|
+
$stdout.should_receive(:puts).with(1)
|
540
|
+
|
541
|
+
Client.solve
|
542
|
+
|
497
543
|
end
|
498
|
-
|
499
|
-
|
500
|
-
|
544
|
+
end
|
545
|
+
|
546
|
+
describe "jiti as decorators with internal base" do
|
547
|
+
before do
|
548
|
+
JD1 = trait :jd do
|
549
|
+
def m1
|
550
|
+
1
|
551
|
+
end
|
501
552
|
end
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
553
|
+
JD2 = jd do
|
554
|
+
def m1
|
555
|
+
super + 2
|
556
|
+
end
|
506
557
|
end
|
507
558
|
end
|
508
|
-
|
559
|
+
it 'works like normal decorators' do
|
509
560
|
|
510
|
-
|
511
|
-
|
561
|
+
o = Object.new
|
562
|
+
o.enrich JD2, JD1
|
563
|
+
o.m1.should == 3
|
512
564
|
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
565
|
+
p = Object.new
|
566
|
+
p.enrich JD1, JD2
|
567
|
+
p.m1.should == 1
|
568
|
+
|
569
|
+
end
|
570
|
+
|
571
|
+
it 'raise errors on decorator collusions' do
|
572
|
+
|
573
|
+
expect{
|
518
574
|
|
519
|
-
|
575
|
+
r = Object.new
|
576
|
+
r.enrich JD1, JD1
|
577
|
+
r.m1.should == 1
|
578
|
+
|
579
|
+
}.to raise_error(ArgumentError)
|
580
|
+
expect{
|
520
581
|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
solved
|
527
|
-
end
|
582
|
+
q = Object.new
|
583
|
+
q.enrich JD2, JD2
|
584
|
+
q.m1.should == 5
|
585
|
+
|
586
|
+
}.to raise_error(ArgumentError)
|
528
587
|
|
529
588
|
end
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
589
|
+
end
|
590
|
+
|
591
|
+
describe "jiti as decorators on external base" do
|
592
|
+
before do
|
593
|
+
JD1 = trait :jd do
|
594
|
+
def m1
|
595
|
+
super + 1
|
596
|
+
end
|
597
|
+
end
|
598
|
+
JD2 = jd do
|
599
|
+
def m1
|
600
|
+
super + 2
|
601
|
+
end
|
602
|
+
end
|
603
|
+
class JDClass
|
604
|
+
def m1
|
605
|
+
1
|
606
|
+
end
|
607
|
+
end
|
608
|
+
end
|
535
609
|
|
536
|
-
|
610
|
+
it 'can work like normal decorators' do
|
611
|
+
|
612
|
+
o = JDClass.new
|
613
|
+
o.enrich JD2, JD1
|
614
|
+
o.m1.should == 5
|
615
|
+
|
616
|
+
p = JDClass.new
|
617
|
+
p.enrich JD1, JD2
|
618
|
+
p.m1.should == 5
|
619
|
+
|
620
|
+
end
|
537
621
|
|
622
|
+
it 'raises errors on decorator collusions' do
|
623
|
+
|
624
|
+
expect{
|
625
|
+
|
626
|
+
r = JDClass.new
|
627
|
+
r.enrich JD1, JD1
|
628
|
+
r.m1.should == 3
|
629
|
+
|
630
|
+
}.to raise_error(ArgumentError)
|
631
|
+
expect{
|
632
|
+
|
633
|
+
q = JDClass.new
|
634
|
+
q.enrich JD2, JD2
|
635
|
+
q.m1.should == 6
|
636
|
+
|
637
|
+
}.to raise_error(ArgumentError)
|
638
|
+
|
639
|
+
end
|
538
640
|
end
|
641
|
+
|
539
642
|
end
|
540
|
-
|
541
643
|
end
|
542
644
|
|