jackbox 0.9.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +5 -0
  3. data/CHANGES.txt +108 -0
  4. data/LICENSE.lic +0 -0
  5. data/LICENSE.txt +13 -0
  6. data/README.md +1395 -0
  7. data/Rakefile +6 -0
  8. data/bin/jackup +248 -0
  9. data/jackbox.gemspec +27 -0
  10. data/jackbox.jpg +0 -0
  11. data/lib/.document +0 -0
  12. data/lib/jackbox.rb +2 -0
  13. data/lib/jackbox/examples/dir.rb +80 -0
  14. data/lib/jackbox/examples/dx.rb +182 -0
  15. data/lib/jackbox/examples/transformers.rb +101 -0
  16. data/lib/jackbox/injectors.rb +2 -0
  17. data/lib/jackbox/rake.rb +2 -0
  18. data/lib/jackbox/tools/prefs.rb +2 -0
  19. data/lib/jackbox/version.rb +4 -0
  20. data/rgloader/loader.rb +23 -0
  21. data/rgloader/rgloader.darwin.bundle +0 -0
  22. data/rgloader/rgloader.freebsd.so +0 -0
  23. data/rgloader/rgloader.freebsd.x86_64.so +0 -0
  24. data/rgloader/rgloader.linux.so +0 -0
  25. data/rgloader/rgloader.linux.x86_64.so +0 -0
  26. data/rgloader/rgloader.mingw.so +0 -0
  27. data/rgloader/rgloader19.darwin.bundle +0 -0
  28. data/rgloader/rgloader19.freebsd.so +0 -0
  29. data/rgloader/rgloader19.freebsd.x86_64.so +0 -0
  30. data/rgloader/rgloader19.linux.so +0 -0
  31. data/rgloader/rgloader19.linux.x86_64.so +0 -0
  32. data/rgloader/rgloader19.mingw.so +0 -0
  33. data/rgloader/rgloader191.mingw.so +0 -0
  34. data/rgloader/rgloader192.darwin.bundle +0 -0
  35. data/rgloader/rgloader192.freebsd.so +0 -0
  36. data/rgloader/rgloader192.freebsd.x86_64.so +0 -0
  37. data/rgloader/rgloader192.linux.so +0 -0
  38. data/rgloader/rgloader192.linux.x86_64.so +0 -0
  39. data/rgloader/rgloader192.mingw.so +0 -0
  40. data/rgloader/rgloader193.darwin.bundle +0 -0
  41. data/rgloader/rgloader193.freebsd.so +0 -0
  42. data/rgloader/rgloader193.freebsd.x86_64.so +0 -0
  43. data/rgloader/rgloader193.linux.so +0 -0
  44. data/rgloader/rgloader193.linux.x86_64.so +0 -0
  45. data/rgloader/rgloader193.mingw.so +0 -0
  46. data/rgloader/rgloader20.darwin.bundle +0 -0
  47. data/rgloader/rgloader20.freebsd.so +0 -0
  48. data/rgloader/rgloader20.freebsd.x86_64.so +0 -0
  49. data/rgloader/rgloader20.linux.so +0 -0
  50. data/rgloader/rgloader20.linux.x86_64.so +0 -0
  51. data/rgloader/rgloader20.mingw.so +0 -0
  52. data/rgloader/rgloader20.mingw.x64.so +0 -0
  53. data/rgloader/rgloader21.darwin.bundle +0 -0
  54. data/rgloader/rgloader21.freebsd.so +0 -0
  55. data/rgloader/rgloader21.freebsd.x86_64.so +0 -0
  56. data/rgloader/rgloader21.linux.so +0 -0
  57. data/rgloader/rgloader21.linux.x86_64.so +0 -0
  58. data/rgloader/rgloader21.mingw.so +0 -0
  59. data/rgloader/rgloader21.mingw.x64.so +0 -0
  60. data/rgloader/rgloader22.darwin.bundle +0 -0
  61. data/rgloader/rgloader22.freebsd.so +0 -0
  62. data/rgloader/rgloader22.linux.so +0 -0
  63. data/rgloader/rgloader22.linux.x86_64.so +0 -0
  64. data/rgloader/rgloader22.mingw.so +0 -0
  65. data/rgloader/rgloader22.mingw.x64.so +0 -0
  66. data/spec/bin/jackup_cmd_shared.rb +176 -0
  67. data/spec/bin/jackup_cmd_spec.rb +292 -0
  68. data/spec/lib/abtract_spec.rb +56 -0
  69. data/spec/lib/jackbox/examples/dir_spec.rb +112 -0
  70. data/spec/lib/jackbox/examples/dx_spec.rb +346 -0
  71. data/spec/lib/jackbox/examples/result.xml +15 -0
  72. data/spec/lib/jackbox/examples/source1.xml +11 -0
  73. data/spec/lib/jackbox/examples/source2.xml +15 -0
  74. data/spec/lib/jackbox/examples/source3.xml +11 -0
  75. data/spec/lib/jackbox/examples/trasnformers_spec.rb +35 -0
  76. data/spec/lib/jackbox/injector_composition_spec.rb +950 -0
  77. data/spec/lib/jackbox/injector_directives_spec.rb +266 -0
  78. data/spec/lib/jackbox/injector_inheritance_spec.rb +799 -0
  79. data/spec/lib/jackbox/injector_introspection_spec.rb +614 -0
  80. data/spec/lib/jackbox/injector_namespacing_spec.rb +345 -0
  81. data/spec/lib/jackbox/injector_spec.rb +847 -0
  82. data/spec/lib/jackbox/injector_versioning_spec.rb +334 -0
  83. data/spec/lib/jackbox/patterns_spec.rb +410 -0
  84. data/spec/lib/jackbox/prefs_spec.rb +212 -0
  85. data/spec/lib/jackbox/reclassing_spec.rb +394 -0
  86. data/spec/lib/jackbox_spec.rb +595 -0
  87. data/spec/spec_helper.rb +139 -0
  88. metadata +218 -0
@@ -0,0 +1,212 @@
1
+ require "spec_helper"
2
+ =begin rdoc
3
+ prefs_spec
4
+ author: Lou Henry
5
+ :nodoc:all
6
+ =end
7
+
8
+ include Injectors
9
+
10
+ describe 'what Prefs does' do
11
+
12
+ it 'creates module level attribute methods' do
13
+ module Tester
14
+ extend Prefs
15
+
16
+ pref :pref1 => 10
17
+ end
18
+
19
+ lambda{
20
+ Tester.pref1.should == 10
21
+
22
+ }.should_not raise_error()
23
+ lambda{
24
+ Tester.pref1=( 2 )
25
+
26
+ }.should_not raise_error()
27
+ Tester.pref1.should == 2
28
+ end
29
+
30
+ it 'should work the same on inclusion' do
31
+ lambda {
32
+ module Fester
33
+ include Prefs
34
+
35
+ pref :location => :file_system
36
+ end
37
+ }.should_not raise_error()
38
+ Fester.location.should == :file_system
39
+ end
40
+
41
+ it 'allows resetting prefs to their original/default values' do
42
+ module Jester
43
+ extend Prefs
44
+
45
+ pref :value => 10
46
+ end
47
+ Jester.value.should == 10
48
+ Jester.value = 3
49
+ Jester.value.should == 3
50
+ Jester.reset :value
51
+ Jester.value.should == 10
52
+ end
53
+
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
93
+
94
+ it 'should allow definition of prefs outside the module definition' do
95
+ lambda{
96
+ Tester.pref :new_prop => 3
97
+
98
+ }.should_not raise_error()
99
+ Tester.pref :someprop => 'tester'
100
+
101
+ lambda{
102
+ Tester.someprop
103
+
104
+ }.should_not raise_error
105
+ Tester.someprop.should == 'tester'
106
+ end
107
+
108
+ it 'should not pass-on definitions to descendants' do
109
+ module Tester
110
+ include Prefs
111
+ pref :pref1 => 10
112
+ end
113
+ lambda{Tester.pref1}.should_not raise_error
114
+ module Descendant
115
+ include Tester
116
+ end
117
+ lambda{Descendant.pref1}.should raise_error(NoMethodError)
118
+ module Offspring
119
+ extend Tester
120
+ end
121
+ lambda{Offspring.pref1}.should raise_error(NoMethodError)
122
+ class Child
123
+ include Tester
124
+ extend Tester
125
+ end
126
+ lambda{Child.pref1}.should raise_error(NoMethodError)
127
+ lambda{Child.new.pref1}.should raise_error(NoMethodError)
128
+ end
129
+
130
+ it 'should allow all of the following' do
131
+ lambda{
132
+ module Master
133
+ extend Prefs
134
+
135
+ pref :tester => 10
136
+ end
137
+
138
+ Master.pref :boo => 45
139
+ Master.boo = [23,45,32,56]
140
+ Master.tester = 30
141
+ Master.reset :tester
142
+ Master.pref :second => 'second'
143
+ Master.second = 'first'
144
+
145
+ module Extras
146
+ extend Prefs
147
+
148
+ pref :a => 10
149
+ pref :reminders_on => true
150
+ pref :interval => 60
151
+ pref :log_file => "/d/workspace"
152
+ pref :tester => :mary
153
+
154
+ self.a = :b
155
+ #TODO: problem: local variables override prefs
156
+ a = 'c'
157
+ self.reminders_on = false
158
+ self.interval=45
159
+ end
160
+ }.should_not raise_error
161
+
162
+ lambda {
163
+ module Tester
164
+ extend Prefs
165
+
166
+ pref :foo => true
167
+ pref :faa => :is_not_error
168
+ end}.should_not raise_error
169
+ Tester.foo.should == true
170
+ Tester.faa.should == :is_not_error
171
+
172
+ end
173
+
174
+ it 'should also allow classes to be used' do
175
+ class C
176
+ extend Prefs
177
+
178
+ pref :boo => "something"
179
+ end
180
+ C.boo.should == 'something'
181
+ lambda{C.boo=(3)}.should_not raise_error
182
+ lambda{C.new.boo}.should raise_error(NoMethodError)
183
+ end
184
+
185
+ it 'should be possible to reset the prefs to their defaults' do
186
+ lambda{Tester.reset}.should_not raise_error
187
+ end
188
+
189
+ it 'should allow definition of prefs store location' do
190
+ class One
191
+ extend Prefs
192
+ prefs_path 'spec/some_path'
193
+
194
+ pref :gaga => 3456
195
+ end
196
+ One.gaga.should == 3456
197
+
198
+ File.should exist('spec/some_path/prefs')
199
+ end
200
+
201
+ the 'Prefs module also works with Injectors' do
202
+
203
+ injector :prefs_tester do
204
+ extend Prefs
205
+ pref :some_pref => 'value'
206
+ end
207
+
208
+ prefs_tester.some_pref.should == 'value'
209
+ end
210
+
211
+ end
212
+
@@ -0,0 +1,394 @@
1
+ require "spec_helper"
2
+ =begin rdoc
3
+ This file represents a new approach to refining a class using Jackbox modular closures.
4
+
5
+ lha
6
+ =end
7
+
8
+ # Jackbox Reclassings
9
+ ############################################
10
+
11
+ # RubyProf.start
12
+
13
+ injector :StringExtensions do # define injector
14
+ def to_s
15
+ super + '++++'
16
+ end
17
+ end
18
+
19
+ # debugger
20
+ lets String do # apply to class
21
+ include StringExtensions()
22
+ end
23
+
24
+ assert( String('boo').to_s == 'boo++++' )
25
+ assert( String("").class == String )
26
+
27
+ describe :String do
28
+ it 'should pass' do
29
+ String('boo').to_s.should == 'boo++++'
30
+ end
31
+ # introspecting on Type
32
+ it 'should be class String' do
33
+ String('boo').class.should be(String)
34
+ end
35
+ end
36
+
37
+
38
+ # Another Reclassing
39
+
40
+ jack :ArrayExtensions do
41
+ def to_s
42
+ super + '####'
43
+ end
44
+ end
45
+
46
+ lets Array do
47
+ inject ArrayExtensions()
48
+ end
49
+
50
+ assert(Array(3).to_s == "[nil, nil, nil]####")
51
+ assert(Array(3).class == Array)
52
+
53
+ describe :Array do
54
+ it 'allows the following' do
55
+ Array(3).to_s.should == "[nil, nil, nil]####"
56
+ end
57
+ # introspecting on Type
58
+ it 'should be Array' do
59
+ Array(3).class.should be(Array)
60
+ end
61
+ end
62
+
63
+ # ORIGINAL CLASSES REMAIN UNTOUCHED!!!
64
+ ##################################################
65
+ assert( String.new.to_s == '' ) #
66
+ assert( Array.new(3).to_s == '[nil, nil, nil]' ) #
67
+ #
68
+ describe String do #
69
+ it 'should remain untouched' do #
70
+ String.new('bar').should == 'bar' #
71
+ end #
72
+ end #
73
+ #
74
+ describe Array do #
75
+ it 'should remain untouched' do #
76
+ Array.new(3).should == [nil, nil, nil] #
77
+ end #
78
+ end #
79
+ ##################################################
80
+ # ORIGINAL CLASSES REMAIN UNTOUCHED!!!
81
+
82
+ # ORIGINAL KERNEL METHODS REMAIN UNTOUCHED!!!
83
+ ##################################################
84
+ assert( Kernel.String(123) == '123' ) #
85
+ assert( Kernel.Array(3) == [3]) #
86
+ #
87
+ describe :'Kernel.String' do #
88
+ it 'should reamain untouched' do #
89
+ Kernel.String(123).should == '123' #
90
+ end #
91
+ end #
92
+ #
93
+ describe :'Kernel.Array' do #
94
+ it 'should reamain untouched' do #
95
+ Kernel.Array([1,2,3]).should == [1,2,3] #
96
+ end #
97
+ end #
98
+ ##################################################
99
+ # ORIGINAL KERNEL METHODS REMAIN UNTOUCHED!!!
100
+
101
+
102
+
103
+
104
+
105
+ # Namespaced Reclassings
106
+ ##################################################
107
+
108
+ jack :NameSpacedArrayExtensions do
109
+ def to_s
110
+ super + '!!!!'
111
+ end
112
+ end
113
+
114
+ module M7
115
+
116
+ # Internal reclassing
117
+
118
+ lets Array do
119
+ inject NameSpacedArrayExtensions()
120
+ end
121
+
122
+ def foo_bar
123
+ Array(2)
124
+ end
125
+ end
126
+
127
+ class A6
128
+ include M7
129
+ end
130
+
131
+
132
+ describe "Internal Array()" do
133
+ it 'should pass' do
134
+ A6.new.foo_bar.to_s.should == '[nil, nil]!!!!'
135
+ end
136
+ # introspecting on Type
137
+ it 'should be an Array' do
138
+ A6.new.foo_bar.class.should be(Array)
139
+ end
140
+ end
141
+
142
+
143
+
144
+
145
+ # Further Introspection
146
+ ##################################################
147
+ # debugger
148
+ assert( A6.new.foo_bar.injectors.by_name == [:NameSpacedArrayExtensions] )
149
+
150
+ describe "introspection" do
151
+
152
+ # introspecting on capabilities
153
+
154
+ it 'should allow injector introspection' do
155
+ # # top level re-class
156
+ Array() do
157
+ injectors.by_name.should == [:ArrayExtensions]
158
+ end
159
+ # debugger
160
+ Array(){injectors.by_name}.should == [:ArrayExtensions]
161
+
162
+ # top level re-class instances
163
+ Array(1).injectors.by_name == [:ArrayExtensions]
164
+
165
+ end
166
+
167
+ it 'works on namespaced reclassings' do
168
+ module M7
169
+ # debugger
170
+ Array() do
171
+ injectors.by_name.should == [:NameSpacedArrayExtensions]
172
+ end
173
+ end
174
+ end
175
+
176
+ it 'can test the existence of a re-classing' do
177
+
178
+ reclass?(String).should == true
179
+ reclass?(Array).should == true
180
+
181
+ module M7
182
+ reclass? Array
183
+ end.should == true
184
+
185
+ module M8
186
+ reclass? Array
187
+ end.should == false
188
+
189
+ module M9
190
+ reclass? String
191
+ end.should == false
192
+
193
+ end
194
+
195
+ it 'works' do
196
+
197
+ # Injector declaration
198
+
199
+ jack :StringRefinements do
200
+ lets String do
201
+ with singleton_class do
202
+ alias _new new
203
+ def new *args, &code
204
+ super(*args, &code) + ' is a special string'
205
+ end
206
+ end
207
+ end
208
+ end
209
+
210
+ class OurClass
211
+ include StringRefinements()
212
+
213
+ def foo_bar
214
+ String('foo and bar')
215
+ end
216
+ end
217
+
218
+ c = OurClass.new
219
+ c.foo_bar.class.should == String
220
+ c.foo_bar.should == 'foo and bar is a special string'
221
+ expect{c.foo_bar.extra.should == :extra}.to raise_error(NoMethodError)
222
+
223
+ StringRefinements do
224
+ String() do
225
+ def extra
226
+ :extra
227
+ end
228
+ end
229
+ end
230
+
231
+ c.foo_bar.should == 'foo and bar is a special string'
232
+ c.foo_bar.class.should == String
233
+ c.foo_bar.extra.should == :extra
234
+
235
+ SR = StringRefinements do # New Version
236
+ lets String do
237
+ def to_s
238
+ super + '****'
239
+ end
240
+ end
241
+ end
242
+
243
+ # c is still the same
244
+
245
+ c.foo_bar.should == 'foo and bar is a special string'
246
+ c.foo_bar.class.should == String
247
+ c.foo_bar.extra.should == :extra
248
+
249
+
250
+ class OurOtherClass
251
+ include SR # Apply new version
252
+ # to another class
253
+ def foo_bar
254
+ String('foo and bar')
255
+ end
256
+ end
257
+
258
+ d = OurOtherClass.new
259
+ d.foo_bar.should == 'foo and bar'
260
+ d.foo_bar.to_s.should == 'foo and bar****'
261
+ expect{ d.extra }.to raise_error(NoMethodError)
262
+
263
+ end
264
+ end
265
+
266
+
267
+
268
+
269
+
270
+ # Calls deeper down the hierarchy
271
+ ##################################################
272
+
273
+ module M5
274
+ def self.foo
275
+ String('foo').to_s
276
+ end
277
+ end
278
+
279
+ assert( M5.foo == 'foo++++' )
280
+
281
+ describe M5 do
282
+ it 'works' do
283
+ M5.foo.should == 'foo++++'
284
+ end
285
+ it 'should be String' do
286
+ M5.foo.class.should be(String)
287
+ end
288
+ end
289
+
290
+ # even deeper
291
+
292
+ class A5
293
+ module M6
294
+ def meth arg
295
+ String(arg).to_s
296
+ end
297
+ end
298
+ include M6
299
+ end
300
+
301
+ assert(A5.new.meth("meth")== 'meth++++')
302
+
303
+ describe A5 do
304
+ it "shold pass" do
305
+ A5.new.meth("meth").should == 'meth++++'
306
+ end
307
+ # introspecting on Type
308
+ it 'should be a String' do
309
+ A5.new.meth("meth").class.should be(String)
310
+ end
311
+
312
+ it 'should hold access to top level re-class' do
313
+ class A5
314
+ module M6
315
+ String(){injectors.by_name}.should == [:StringExtensions]
316
+ end
317
+ end
318
+ end
319
+ end
320
+
321
+
322
+
323
+
324
+ # re- Reclassing
325
+ ################################################
326
+
327
+ MyStringExtensions = StringExtensions() do
328
+ def to_s
329
+ super + '----'
330
+ end
331
+ end
332
+
333
+ describe 're-reclassing' do
334
+ it 'should pass' do
335
+ String() do
336
+ update MyStringExtensions
337
+ end
338
+
339
+ String('standard').to_s.should == 'standard----'
340
+ end
341
+ # introspecting on Type
342
+ it 'should be a String' do
343
+ String('standard').class.should be(String)
344
+ end
345
+
346
+ it 'should introspect' do
347
+ String(){injectors}.first.should == MyStringExtensions
348
+ end
349
+ end
350
+
351
+
352
+
353
+ # TOP LEVEL RECLASSINGS REMAIN UNTOUCHED!!!
354
+ ##################################################
355
+ #
356
+ assert( String('test').to_s == 'test++++' ) #
357
+ assert( Array(3).to_s == '[nil, nil, nil]####' ) #
358
+ #
359
+ ##################################################
360
+ # TOP LEVEL RECLASSINGS REMAIN UNTOUCHED!!!
361
+
362
+ # TOP LEVEL RECLASSING TYPES REMAIN UNTOUCHED!!!
363
+ ##################################################
364
+ #
365
+ assert( String('test').class == String ) #
366
+ assert( Array(3).class == Array ) #
367
+ #
368
+ ##################################################
369
+ # TOP LEVEL RECLASSING TYPES REMAIN UNTOUCHED!!!
370
+
371
+ # ORIGINAL CLASSES REMAIN UNTOUCHED!!!
372
+ ##################################################
373
+ #
374
+ assert(String.new.to_s == '') #
375
+ assert(Array.new(3).to_s == '[nil, nil, nil]') #
376
+ #
377
+ ##################################################
378
+ # ORIGINAL CLASSES REMAIN UNTOUCHED!!!
379
+
380
+ # ORIGINAL KERNEL METHODS REMAIN UNTOUCHED!!!
381
+ ##################################################
382
+ #
383
+ assert( Kernel.String(123) == '123' ) #
384
+ assert( Kernel.Array(3) == [3]) #
385
+ #
386
+ ##################################################
387
+ # ORIGINAL KERNEL METHODS REMAIN UNTOUCHED!!!
388
+
389
+ # profile = RubyProf.stop
390
+ # RubyProf::FlatPrinter.new(profile).print(STDOUT)
391
+ # RubyProf::GraphHtmlPrinter.new(profile).print(open('profile.html', 'w+'))
392
+ # RubyProf::CallStackPrinter.new(profile).print(open('profile.html', 'w+'))
393
+
394
+