facets 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/AUTHORS +3 -3
  2. data/README +6 -7
  3. data/lib/core/facets.rb +1 -46
  4. data/lib/core/facets/array.rb +3 -0
  5. data/lib/core/facets/array/indexable.rb +6 -1
  6. data/lib/core/facets/array/only.rb +20 -0
  7. data/lib/core/facets/dir/multiglob.rb +12 -1
  8. data/lib/core/facets/enumerable.rb +0 -1
  9. data/lib/core/facets/enumerable/collect.rb +1 -0
  10. data/lib/core/facets/enumerable/combination.rb +44 -90
  11. data/lib/core/facets/facets.rb +46 -0
  12. data/lib/core/facets/file/write.rb +46 -58
  13. data/lib/core/facets/hash.rb +2 -0
  14. data/lib/core/facets/hash/select.rb +14 -0
  15. data/lib/core/facets/integer/multiples.rb +12 -55
  16. data/lib/core/facets/kernel/val.rb +14 -0
  17. data/lib/core/facets/module/alias.rb +28 -9
  18. data/lib/core/facets/module/methods.rb +18 -0
  19. data/lib/core/facets/module/traits.rb +65 -70
  20. data/lib/core/facets/proc/compose.rb +15 -12
  21. data/lib/core/facets/stackable.rb +3 -2
  22. data/lib/core/facets/string/format.rb +4 -6
  23. data/lib/core/facets/string/tabs.rb +34 -0
  24. data/lib/core/facets/symbol.rb +1 -0
  25. data/lib/core/facets/symbol/succ.rb +1 -42
  26. data/lib/core/facets/symbol/to_proc.rb +34 -0
  27. data/lib/methods/facets/array/contains.rb +1 -0
  28. data/lib/methods/facets/facets/require_core.rb +1 -0
  29. data/lib/methods/facets/file/writelines.rb +1 -0
  30. data/lib/methods/facets/io/writelines.rb +1 -0
  31. data/lib/methods/facets/kernel/not_nil.rb +1 -0
  32. data/lib/methods/facets/module/conflict.rb +1 -0
  33. data/lib/methods/facets/module/instance_method_defined.rb +1 -0
  34. data/lib/methods/facets/module/module_method_defined.rb +1 -0
  35. data/lib/methods/facets/module/private_conflict.rb +1 -0
  36. data/lib/methods/facets/module/protected_conflict.rb +1 -0
  37. data/lib/methods/facets/module/public_conflict.rb +1 -0
  38. data/lib/methods/facets/string/expand_tabs.rb +1 -0
  39. data/lib/methods/facets/string/outdent.rb +1 -0
  40. data/lib/methods/facets/string/taballto.rb +1 -0
  41. data/lib/more/facets/arguments.rb +1 -1
  42. data/lib/more/facets/association.rb +0 -46
  43. data/lib/more/facets/autoarray.rb +0 -28
  44. data/lib/more/facets/command.rb +341 -8
  45. data/lib/more/facets/dictionary.rb +25 -131
  46. data/lib/more/facets/downloader.rb +1 -1
  47. data/lib/more/facets/infinity.rb +3 -3
  48. data/lib/more/facets/interval.rb +0 -161
  49. data/lib/more/facets/multiton.rb +16 -12
  50. data/lib/more/facets/namespace.rb +1 -1
  51. data/lib/more/facets/ostruct.rb +46 -10
  52. data/lib/more/facets/overload.rb +0 -51
  53. data/lib/more/facets/paramix.rb +0 -97
  54. data/lib/more/facets/pp_s.rb +30 -0
  55. data/lib/more/facets/progressbar.rb +18 -10
  56. data/lib/more/facets/prototype.rb +1 -40
  57. data/lib/more/facets/random.rb +1 -0
  58. data/lib/more/facets/rbsystem.rb +4 -1
  59. data/lib/more/facets/snapshot.rb +8 -1
  60. data/lib/more/facets/stylize.rb +2 -0
  61. data/meta/{project.yaml → facets-2.0.3.roll} +22 -14
  62. data/meta/manifest.txt +38 -8
  63. data/task/{config.yaml → config/general.yaml} +7 -2
  64. data/task/{rdoc.yaml → config/rdoc.yaml} +1 -1
  65. data/task/crosstest +309 -0
  66. data/task/isotest +293 -0
  67. data/task/loadtest +28 -0
  68. data/task/methods +4 -4
  69. data/task/prepare +5 -0
  70. data/task/publish +2 -2
  71. data/task/rdoc +1 -0
  72. data/task/syntax +29 -0
  73. data/task/test +0 -1
  74. data/task/testeach +42 -0
  75. data/task/testpairs +50 -0
  76. data/test/lib/rq.rb +15 -0
  77. data/test/unit/array/test_merge.rb +21 -43
  78. data/test/unit/array/test_only.rb +21 -0
  79. data/test/unit/enumerable/test_collect.rb +1 -21
  80. data/test/unit/enumerable/test_combination.rb +50 -44
  81. data/test/unit/file/test_topath.rb +48 -57
  82. data/test/unit/file/test_write.rb +82 -0
  83. data/test/unit/hash/test_select.rb +43 -0
  84. data/test/unit/integer/test_multiples.rb +28 -32
  85. data/test/unit/kernel/test_report.rb +9 -12
  86. data/test/unit/kernel/test_val.rb +50 -45
  87. data/test/unit/module/test_include.rb +56 -57
  88. data/test/unit/module/test_name.rb +42 -55
  89. data/test/unit/module/test_traits.rb +46 -47
  90. data/test/unit/string/test_filter.rb +19 -34
  91. data/test/unit/string/test_format.rb +87 -96
  92. data/test/unit/string/test_regesc.rb +18 -26
  93. data/test/unit/string/test_tabs.rb +226 -119
  94. data/test/unit/symbol/test_succ.rb +14 -23
  95. data/test/unit/symbol/test_to_proc.rb +41 -0
  96. data/test/unit/test_association.rb +38 -47
  97. data/test/unit/test_attributes.rb +24 -33
  98. data/test/unit/test_autoarray.rb +23 -32
  99. data/test/unit/test_command.rb +26 -0
  100. data/test/unit/test_dictionary.rb +123 -117
  101. data/test/unit/test_infinity.rb +41 -47
  102. data/test/unit/test_inheritor.rb +133 -142
  103. data/test/unit/test_interval.rb +129 -93
  104. data/test/unit/test_ostruct.rb +148 -101
  105. data/test/unit/test_overload.rb +8 -15
  106. data/test/unit/test_paramix.rb +67 -73
  107. data/test/unit/test_pp_s.rb +23 -0
  108. data/test/unit/test_prototype.rb +28 -38
  109. metadata +47 -11
  110. data/lib/core/facets/enumerable/instance_map.rb +0 -0
  111. data/lib/more/facets/command_options.rb +0 -328
  112. data/meta/version.txt +0 -1
  113. data/task/load +0 -39
  114. data/test/unit/test_command_options.rb +0 -29
@@ -0,0 +1,23 @@
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for facets/pp_s.rb
8
+
9
+ require 'facets/pp_s.rb'
10
+ require 'test/unit'
11
+
12
+ class TestPP_S < Test::Unit::TestCase
13
+
14
+ def test_pp_s
15
+ # Can't so much, as the code is so simple; all the work is done by PP.
16
+ # Any testing of its output would be rendered incorrect by changes to
17
+ # that library. Just do a sanity check with a simple value.
18
+ assert_equal(%{"one"\n}, "one".pp_s)
19
+ end
20
+
21
+ end
22
+
23
+
@@ -1,50 +1,40 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/prototype.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:08 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
12
7
 
13
- require 'facets/prototype.rb'
8
+ require 'facets/prototype.rb'
14
9
 
10
+ require 'test/unit'
15
11
 
12
+ class TestPrototypeKernel < Test::Unit::TestCase
16
13
 
17
- require 'test/unit'
18
-
19
- class TestPrototypeKernel < Test::Unit::TestCase
20
-
21
- def test_new
22
- q = nil
23
- s = "Testing"
24
- assert_nothing_raised { q = s.new }
25
- assert_equal( s, q )
26
- assert_not_equal( s.object_id, q.object_id )
27
- end
14
+ def test_new
15
+ q = nil
16
+ s = "Testing"
17
+ assert_nothing_raised { q = s.new }
18
+ assert_equal( s, q )
19
+ assert_not_equal( s.object_id, q.object_id )
28
20
  end
21
+ end
29
22
 
30
- class TestPrototype < Test::Unit::TestCase
31
-
32
- def setup
33
- @person = prototype do
34
- @name = ''
35
- @age = 0
36
- @announce = fn { |x| "#{x}, #{name} is #{age}" }
37
- end
23
+ class TestPrototype < Test::Unit::TestCase
38
24
 
39
- @person.name = 'Tom'
40
- @person.age = 35
41
- end
42
-
43
- def test_simple_case
44
- assert_equal( "Peter, Tom is 35", @person.announce['Peter'])
25
+ def setup
26
+ @person = prototype do
27
+ @name = ''
28
+ @age = 0
29
+ @announce = fn { |x| "#{x}, #{name} is #{age}" }
45
30
  end
46
31
 
32
+ @person.name = 'Tom'
33
+ @person.age = 35
47
34
  end
48
35
 
36
+ def test_simple_case
37
+ assert_equal( "Peter, Tom is 35", @person.announce['Peter'])
38
+ end
49
39
 
50
-
40
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: facets
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.0.2
7
- date: 2007-10-08 00:00:00 -07:00
6
+ version: 2.0.3
7
+ date: 2007-11-02 00:00:00 -04:00
8
8
  summary: Premium Core Extensions and Standard Additions
9
9
  require_paths:
10
10
  - lib/methods
@@ -58,6 +58,7 @@ files:
58
58
  - lib/core/facets/array/delete.rb
59
59
  - lib/core/facets/array/indexable.rb
60
60
  - lib/core/facets/array/merge.rb
61
+ - lib/core/facets/array/only.rb
61
62
  - lib/core/facets/array/pad.rb
62
63
  - lib/core/facets/array/rotate.rb
63
64
  - lib/core/facets/array/select.rb
@@ -93,9 +94,9 @@ files:
93
94
  - lib/core/facets/enumerable/collect.rb
94
95
  - lib/core/facets/enumerable/combination.rb
95
96
  - lib/core/facets/enumerable/count.rb
96
- - lib/core/facets/enumerable/instance_map.rb
97
97
  - lib/core/facets/enumerable/permutation.rb
98
98
  - lib/core/facets/enumerable/probability.rb
99
+ - lib/core/facets/facets.rb
99
100
  - lib/core/facets/file
100
101
  - lib/core/facets/file.rb
101
102
  - lib/core/facets/file/read.rb
@@ -121,6 +122,7 @@ files:
121
122
  - lib/core/facets/hash/new.rb
122
123
  - lib/core/facets/hash/op.rb
123
124
  - lib/core/facets/hash/rekey.rb
125
+ - lib/core/facets/hash/select.rb
124
126
  - lib/core/facets/hash/traverse.rb
125
127
  - lib/core/facets/hash/update.rb
126
128
  - lib/core/facets/hash/weave.rb
@@ -215,6 +217,7 @@ files:
215
217
  - lib/core/facets/symbol/not.rb
216
218
  - lib/core/facets/symbol/shadow.rb
217
219
  - lib/core/facets/symbol/succ.rb
220
+ - lib/core/facets/symbol/to_proc.rb
218
221
  - lib/core/facets/time
219
222
  - lib/core/facets/time.rb
220
223
  - lib/core/facets/time/change.rb
@@ -226,6 +229,7 @@ files:
226
229
  - lib/methods
227
230
  - lib/methods/facets
228
231
  - lib/methods/facets/array
232
+ - lib/methods/facets/array/contains.rb
229
233
  - lib/methods/facets/array/delete_unless.rb
230
234
  - lib/methods/facets/array/delete_values.rb
231
235
  - lib/methods/facets/array/delete_values_at.rb
@@ -323,6 +327,8 @@ files:
323
327
  - lib/methods/facets/enumerable/to_h.rb
324
328
  - lib/methods/facets/enumerable/to_hash.rb
325
329
  - lib/methods/facets/enumerable/uniq_by.rb
330
+ - lib/methods/facets/facets
331
+ - lib/methods/facets/facets/require_core.rb
326
332
  - lib/methods/facets/falseclass
327
333
  - lib/methods/facets/falseclass/to_bool.rb
328
334
  - lib/methods/facets/file
@@ -335,6 +341,7 @@ files:
335
341
  - lib/methods/facets/file/rootname.rb
336
342
  - lib/methods/facets/file/sanitize.rb
337
343
  - lib/methods/facets/file/split_all.rb
344
+ - lib/methods/facets/file/writelines.rb
338
345
  - lib/methods/facets/filetest
339
346
  - lib/methods/facets/filetest/root.rb
340
347
  - lib/methods/facets/float
@@ -400,6 +407,8 @@ files:
400
407
  - lib/methods/facets/integer/test_bitmask.rb
401
408
  - lib/methods/facets/integer/times_collect.rb
402
409
  - lib/methods/facets/integer/times_map.rb
410
+ - lib/methods/facets/io
411
+ - lib/methods/facets/io/writelines.rb
403
412
  - lib/methods/facets/kernel
404
413
  - lib/methods/facets/kernel/__DIR__.rb
405
414
  - lib/methods/facets/kernel/__assign__.rb
@@ -446,6 +455,7 @@ files:
446
455
  - lib/methods/facets/kernel/meta_eval.rb
447
456
  - lib/methods/facets/kernel/metaclass.rb
448
457
  - lib/methods/facets/kernel/method.rb
458
+ - lib/methods/facets/kernel/not_nil.rb
449
459
  - lib/methods/facets/kernel/object_class.rb
450
460
  - lib/methods/facets/kernel/object_clone.rb
451
461
  - lib/methods/facets/kernel/object_dup.rb
@@ -497,16 +507,19 @@ files:
497
507
  - lib/methods/facets/module/clone_removing.rb
498
508
  - lib/methods/facets/module/clone_renaming.rb
499
509
  - lib/methods/facets/module/clone_using.rb
510
+ - lib/methods/facets/module/conflict.rb
500
511
  - lib/methods/facets/module/dirname.rb
501
512
  - lib/methods/facets/module/include_and_extend.rb
502
513
  - lib/methods/facets/module/include_as.rb
503
514
  - lib/methods/facets/module/include_function_module.rb
504
515
  - lib/methods/facets/module/instance_method.rb
516
+ - lib/methods/facets/module/instance_method_defined.rb
505
517
  - lib/methods/facets/module/integrate.rb
506
518
  - lib/methods/facets/module/is.rb
507
519
  - lib/methods/facets/module/modspace.rb
508
520
  - lib/methods/facets/module/module_load.rb
509
521
  - lib/methods/facets/module/module_method.rb
522
+ - lib/methods/facets/module/module_method_defined.rb
510
523
  - lib/methods/facets/module/module_require.rb
511
524
  - lib/methods/facets/module/nesting.rb
512
525
  - lib/methods/facets/module/nodef.rb
@@ -514,6 +527,9 @@ files:
514
527
  - lib/methods/facets/module/op_minus.rb
515
528
  - lib/methods/facets/module/op_mul.rb
516
529
  - lib/methods/facets/module/op_plus.rb
530
+ - lib/methods/facets/module/private_conflict.rb
531
+ - lib/methods/facets/module/protected_conflict.rb
532
+ - lib/methods/facets/module/public_conflict.rb
517
533
  - lib/methods/facets/module/redef.rb
518
534
  - lib/methods/facets/module/redefine_method.rb
519
535
  - lib/methods/facets/module/redirect.rb
@@ -573,6 +589,7 @@ files:
573
589
  - lib/methods/facets/string/each_character.rb
574
590
  - lib/methods/facets/string/each_word.rb
575
591
  - lib/methods/facets/string/ends_with.rb
592
+ - lib/methods/facets/string/expand_tabs.rb
576
593
  - lib/methods/facets/string/first.rb
577
594
  - lib/methods/facets/string/fold.rb
578
595
  - lib/methods/facets/string/format.rb
@@ -585,6 +602,7 @@ files:
585
602
  - lib/methods/facets/string/lowercase.rb
586
603
  - lib/methods/facets/string/margin.rb
587
604
  - lib/methods/facets/string/mscan.rb
605
+ - lib/methods/facets/string/outdent.rb
588
606
  - lib/methods/facets/string/peek.rb
589
607
  - lib/methods/facets/string/poke.rb
590
608
  - lib/methods/facets/string/pop.rb
@@ -601,6 +619,7 @@ files:
601
619
  - lib/methods/facets/string/store.rb
602
620
  - lib/methods/facets/string/succ.rb
603
621
  - lib/methods/facets/string/tab.rb
622
+ - lib/methods/facets/string/taballto.rb
604
623
  - lib/methods/facets/string/tabto.rb
605
624
  - lib/methods/facets/string/to_b.rb
606
625
  - lib/methods/facets/string/to_const.rb
@@ -654,7 +673,6 @@ files:
654
673
  - lib/more/facets/classmethods.rb
655
674
  - lib/more/facets/cloneable.rb
656
675
  - lib/more/facets/command.rb
657
- - lib/more/facets/command_options.rb
658
676
  - lib/more/facets/compare_on.rb
659
677
  - lib/more/facets/console.rb
660
678
  - lib/more/facets/coroutine.rb
@@ -708,6 +726,7 @@ files:
708
726
  - lib/more/facets/pathlist.rb
709
727
  - lib/more/facets/pathname.rb
710
728
  - lib/more/facets/pool.rb
729
+ - lib/more/facets/pp_s.rb
711
730
  - lib/more/facets/pqueue.rb
712
731
  - lib/more/facets/prepend.rb
713
732
  - lib/more/facets/progressbar.rb
@@ -739,29 +758,37 @@ files:
739
758
  - lib/more/facets/yaml.rb
740
759
  - lib/more/facets/ziputils.rb
741
760
  - meta
761
+ - meta/facets-2.0.3.roll
742
762
  - meta/manifest.txt
743
- - meta/project.yaml
744
- - meta/version.txt
745
763
  - task
746
764
  - task/clean
747
765
  - task/config
748
- - task/config.yaml
766
+ - task/config/general.yaml
767
+ - task/config/rdoc.yaml
768
+ - task/crosstest
749
769
  - task/extest
750
770
  - task/groups
751
771
  - task/install
752
- - task/load
772
+ - task/isotest
773
+ - task/loadtest
753
774
  - task/methods
775
+ - task/prepare
754
776
  - task/publish
755
777
  - task/rdoc
756
- - task/rdoc.yaml
757
778
  - task/stats
779
+ - task/syntax
758
780
  - task/test
781
+ - task/testeach
782
+ - task/testpairs
759
783
  - test
784
+ - test/lib
785
+ - test/lib/rq.rb
760
786
  - test/unit
761
787
  - test/unit/array
762
788
  - test/unit/array/test_delete.rb
763
789
  - test/unit/array/test_indexable.rb
764
790
  - test/unit/array/test_merge.rb
791
+ - test/unit/array/test_only.rb
765
792
  - test/unit/array/test_pad.rb
766
793
  - test/unit/array/test_rotate.rb
767
794
  - test/unit/array/test_select.rb
@@ -788,6 +815,7 @@ files:
788
815
  - test/unit/enumerable/test_probability.rb
789
816
  - test/unit/file
790
817
  - test/unit/file/test_topath.rb
818
+ - test/unit/file/test_write.rb
791
819
  - test/unit/hash
792
820
  - test/unit/hash/test_at.rb
793
821
  - test/unit/hash/test_delete.rb
@@ -800,6 +828,7 @@ files:
800
828
  - test/unit/hash/test_new.rb
801
829
  - test/unit/hash/test_op.rb
802
830
  - test/unit/hash/test_rekey.rb
831
+ - test/unit/hash/test_select.rb
803
832
  - test/unit/hash/test_traverse.rb
804
833
  - test/unit/hash/test_update.rb
805
834
  - test/unit/hash/test_weave.rb
@@ -868,6 +897,7 @@ files:
868
897
  - test/unit/symbol/test_not.rb
869
898
  - test/unit/symbol/test_shadow.rb
870
899
  - test/unit/symbol/test_succ.rb
900
+ - test/unit/symbol/test_to_proc.rb
871
901
  - test/unit/test_1stclassmethod.rb
872
902
  - test/unit/test_advice.rb
873
903
  - test/unit/test_annotations.rb
@@ -887,7 +917,6 @@ files:
887
917
  - test/unit/test_class_extension.rb
888
918
  - test/unit/test_classmethods.rb
889
919
  - test/unit/test_command.rb
890
- - test/unit/test_command_options.rb
891
920
  - test/unit/test_compare_on.rb
892
921
  - test/unit/test_conversion.rb
893
922
  - test/unit/test_coroutine.rb
@@ -920,6 +949,7 @@ files:
920
949
  - test/unit/test_ostruct.rb
921
950
  - test/unit/test_overload.rb
922
951
  - test/unit/test_paramix.rb
952
+ - test/unit/test_pp_s.rb
923
953
  - test/unit/test_prototype.rb
924
954
  - test/unit/test_random.rb
925
955
  - test/unit/test_recorder.rb
@@ -936,11 +966,14 @@ files:
936
966
  - test/unit/time/test_change.rb
937
967
  - test/unit/time/test_elapse.rb
938
968
  test_files:
969
+ - test/lib
970
+ - test/lib/rq.rb
939
971
  - test/unit
940
972
  - test/unit/array
941
973
  - test/unit/array/test_delete.rb
942
974
  - test/unit/array/test_indexable.rb
943
975
  - test/unit/array/test_merge.rb
976
+ - test/unit/array/test_only.rb
944
977
  - test/unit/array/test_pad.rb
945
978
  - test/unit/array/test_rotate.rb
946
979
  - test/unit/array/test_select.rb
@@ -967,6 +1000,7 @@ test_files:
967
1000
  - test/unit/enumerable/test_probability.rb
968
1001
  - test/unit/file
969
1002
  - test/unit/file/test_topath.rb
1003
+ - test/unit/file/test_write.rb
970
1004
  - test/unit/hash
971
1005
  - test/unit/hash/test_at.rb
972
1006
  - test/unit/hash/test_delete.rb
@@ -979,6 +1013,7 @@ test_files:
979
1013
  - test/unit/hash/test_new.rb
980
1014
  - test/unit/hash/test_op.rb
981
1015
  - test/unit/hash/test_rekey.rb
1016
+ - test/unit/hash/test_select.rb
982
1017
  - test/unit/hash/test_traverse.rb
983
1018
  - test/unit/hash/test_update.rb
984
1019
  - test/unit/hash/test_weave.rb
@@ -1047,6 +1082,7 @@ test_files:
1047
1082
  - test/unit/symbol/test_not.rb
1048
1083
  - test/unit/symbol/test_shadow.rb
1049
1084
  - test/unit/symbol/test_succ.rb
1085
+ - test/unit/symbol/test_to_proc.rb
1050
1086
  - test/unit/test_1stclassmethod.rb
1051
1087
  - test/unit/test_advice.rb
1052
1088
  - test/unit/test_annotations.rb
@@ -1066,7 +1102,6 @@ test_files:
1066
1102
  - test/unit/test_class_extension.rb
1067
1103
  - test/unit/test_classmethods.rb
1068
1104
  - test/unit/test_command.rb
1069
- - test/unit/test_command_options.rb
1070
1105
  - test/unit/test_compare_on.rb
1071
1106
  - test/unit/test_conversion.rb
1072
1107
  - test/unit/test_coroutine.rb
@@ -1099,6 +1134,7 @@ test_files:
1099
1134
  - test/unit/test_ostruct.rb
1100
1135
  - test/unit/test_overload.rb
1101
1136
  - test/unit/test_paramix.rb
1137
+ - test/unit/test_pp_s.rb
1102
1138
  - test/unit/test_prototype.rb
1103
1139
  - test/unit/test_random.rb
1104
1140
  - test/unit/test_recorder.rb
@@ -1,328 +0,0 @@
1
- # TITLE:
2
- #
3
- # Command Options
4
- #
5
- # COPYRIGHT:
6
- #
7
- # Copyright (c) 2005 7rans, Tyler Rick
8
- #
9
- # Ruby License
10
- #
11
- # This module is free software. You may use, modify, and/or
12
- # redistribute this software under the same terms as Ruby.
13
- #
14
- # This program is distributed in the hope that it will be
15
- # useful, but WITHOUT ANY WARRANTY; without even the implied
16
- # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17
- # PURPOSE.
18
- #
19
- # AUTHORS:
20
- #
21
- # - 7rans
22
- # - Tyler Rick
23
- #
24
- # TODOs:
25
- #
26
- # - Add help/documentation features.
27
-
28
- require 'shellwords'
29
- #require 'facets/arguments'
30
-
31
- # = Console::CommandOptions
32
- #
33
- # CommandOptions provides the basis for Command to Object Mapping (COM).
34
- # It is an commandline options parser that uses method definitions
35
- # as means of interprting command arguments.
36
- #
37
- # == Synopsis
38
- #
39
- # Let's make an executable called 'mycmd'.
40
- #
41
- # #!/usr/bin/env ruby
42
- #
43
- # require 'facets/command_options'
44
- #
45
- # class MyOptions < CommandOptions
46
- # attr_accessor :file
47
- #
48
- # def v!
49
- # @verbose = true
50
- # end
51
- # end
52
- #
53
- # opts = MyOptions.parse("-v --file hello.rb")
54
- #
55
- # opts.verbose #=> true
56
- # opts.file #=> "hello.rb"
57
- #
58
- #--
59
- # == Global Options
60
- #
61
- # You can define <i>global options</i> which are options that will be
62
- # processed no matter where they occur in the command line. In the above
63
- # examples only the options occuring before the subcommand are processed
64
- # globally. Anything occuring after the subcommand belonds strictly to
65
- # the subcommand. For instance, if we had added the following to the above
66
- # example:
67
- #
68
- # global_option :_v
69
- #
70
- # Then -v could appear anywhere in the command line, even on the end,
71
- # and still work as expected.
72
- #
73
- # % mycmd jump -h 3 -v
74
- #++
75
- #
76
- # == Missing Options
77
- #
78
- # You can use #option_missing to catch any options that are not explicility
79
- # defined.
80
- #
81
- # The method signature should look like:
82
- #
83
- # option_missing(option_name, args)
84
- #
85
- # Example:
86
- # def option_missing(option_name, args)
87
- # p args if $debug
88
- # case option_name
89
- # when 'p'
90
- # @a = args[0].to_i
91
- # @b = args[1].to_i
92
- # 2
93
- # else
94
- # raise InvalidOptionError(option_name, args)
95
- # end
96
- # end
97
- #
98
- # Its return value should be the effective "arity" of that options -- that is,
99
- # how many arguments it consumed ("-p a b", for example, would consume 2 args:
100
- # "a" and "b"). An arity of 1 is assumed if nil or false is returned.
101
-
102
- #module Console
103
-
104
- class CommandOptions
105
-
106
- def self.parse(*line_and_options)
107
- o = new
108
- o.parse(*line_and_options)
109
- o
110
- end
111
-
112
- def initialize(delegate=nil)
113
- @__self__ = delegate || self
114
- end
115
-
116
- # Parse line for options in the context self.
117
- #
118
- # Options:
119
- #
120
- # :pass => true || false
121
- #
122
- # Setting this to true prevents the parse_missing routine from running.
123
- #
124
- # :only => [ global options, ... ]
125
- #
126
- # When processing global options, we only want to parse selected options.
127
- # This also set +pass+ to true.
128
- #
129
- # :stop => true || false
130
- #
131
- # If we are parsing options for the *main* command and we are allowing
132
- # subcommands, then we want to stop as soon as we get to the first non-option,
133
- # because that non-option will be the name of our subcommand and all options that
134
- # follow should be parsed later when we handle the subcommand.
135
- # This also set +pass+ to true.
136
-
137
- def parse(*line_and_options)
138
- __self__ = @__self__
139
-
140
- if Hash === line_and_options.last
141
- options = line_and_options.pop
142
- line = line_and_options.first
143
- else
144
- options = {}
145
- line = line_and_options.first
146
- end
147
-
148
- case line
149
- when String
150
- argv = Shellwords.shellwords(line)
151
- when Array
152
- argv = line.dup
153
- else
154
- argv = ARGV.dup
155
- end
156
-
157
- only = options[:only] # only parse these options
158
- stop = options[:stop] # stop at first non-option
159
- pass = options[:pass] || only || stop # don't run options_missing
160
-
161
- if $debug
162
- puts(only ? "\nGlobal parsing..." : "\nParsing...")
163
- end
164
-
165
- puts "# line: #{argv.inspect}" if $debug
166
-
167
- # Split single letter option groupings into separate options.
168
- # ie. -xyz => -x -y -z
169
- argv = argv.collect { |arg|
170
- if md = /^-(\w{2,})/.match( arg )
171
- md[1].split(//).collect { |c| "-#{c}" }
172
- else
173
- arg
174
- end
175
- }.flatten
176
-
177
- index = 0
178
-
179
- until index >= argv.size
180
- arg = argv.at(index)
181
- break if arg == '--' # POSIX compliance
182
- if arg[0,1] == '-'
183
- puts "# option: #{arg}" if $debug
184
- #opt = Option.new(arg)
185
- #name = opt.methodize
186
- name = arg.sub(/^-{1,2}/,'')
187
- skip = only && only.include?(name)
188
- if __self__.respond_to?(name+'=')
189
- puts "# method: #{name}=" if $debug
190
- __self__.send(name+'=', *argv.slice(index+1, 1)) unless skip
191
- argv.delete_at(index) # Get rid of the *name* of the option
192
- argv.delete_at(index) # Get rid of the *value* of the option
193
- elsif __self__.respond_to?(name+'!')
194
- puts "# method: #{name}!" if $debug
195
- __self__.send(name+'!') unless skip
196
- argv.delete_at(index) # Get rid of the *name* of the option
197
- else
198
- index += 1
199
- end
200
- else
201
- index += 1
202
- break if stop
203
- end
204
- end
205
- # parse missing ?
206
- argv = parse_missing(argv) unless pass
207
- # return the remaining argv
208
- puts "# return: #{argv.inspect}" if $debug
209
- return argv
210
- end
211
-
212
- #
213
-
214
- def parse_missing(argv)
215
- argv.each_with_index do |a,i|
216
- if a =~ /^-/
217
- kept = @__self__.option_missing(a, *argv[i+1,1])
218
- argv.delete_at(i) if kept # delete if value kept
219
- argv.delete_at(i) # delete option
220
- end
221
- end
222
- return argv
223
- end
224
-
225
- #
226
-
227
- def option_missing(opt, arg=nil)
228
- raise InvalidOptionError.new(opt)
229
- # #$stderr << "Unknown option '#{arg}'.\n"
230
- # #exit -1
231
- end
232
-
233
- #
234
-
235
- def to_h
236
- #writers = public_methods.sellect{ |m| m =~ /=$/ }
237
- instance_variables.inject({}) do |h, v|
238
- h[v[1,-1]] = instance_variable_get(v); h
239
- end
240
- end
241
-
242
- # Provides a basic usage help string.
243
-
244
- def usage
245
- str = []
246
- public_methods(false).each do |meth|
247
- meth = meth.to_s
248
- case meth
249
- when /=$/
250
- opt = meth.chomp('=')
251
- str << (opt.size > 1 ? "[--#{opt} value]" : "[-#{opt} value]")
252
- when /!$/
253
- opt = meth.chomp('!')
254
- str << (opt.size > 1 ? "[--#{opt}]" : "[-#{opt}]")
255
- end
256
- end
257
- return str.join(" ")
258
- end
259
-
260
- #
261
-
262
- def self.usage_class(usage)
263
- c = Class.new(self)
264
- argv = Shellwords.shellwords(usage)
265
- argv.each_with_index do |name, i|
266
- if name =~ /^-/
267
- if argv[i+1] =~ /^[(.*?)]/
268
- c.class_eval %{
269
- attr_accessor :#{name}
270
- }
271
- else
272
- c.class_eval %{
273
- attr_reader :#{name}
274
- def #{name}! ; @#{name} = true ; end
275
- }
276
- end
277
- end
278
- end
279
- return c
280
- end
281
-
282
- # # Single Option
283
- #
284
- # class Option < String
285
- #
286
- # def initialize(option)
287
- # @flag = option
288
- # @long = (/^--/ =~ option)
289
- # super(option.sub(/^-{1,2}/,''))
290
- # end
291
- #
292
- # def long?
293
- # @long
294
- # end
295
- #
296
- # def short?
297
- # !@long
298
- # end
299
- #
300
- # #def demethodize
301
- # # sub('__','--').sub('_','-')
302
- # #end
303
- #
304
- # def methodize
305
- # @flag.sub(/^-{1,2}/,'')
306
- # end
307
- #
308
- # end
309
-
310
- end
311
-
312
- # For CommandOptions, but defined external to it, so
313
- # that it is easy to access from user defined commands.
314
- # (This lookup issue should be fixed in Ruby 1.9+, and then
315
- # the class can be moved back into Command namespace.)
316
-
317
- class InvalidOptionError < StandardError
318
- def initialize(option_name)
319
- @option_name = option_name
320
- end
321
- def message
322
- "Unknown option '#{@option_name}'."
323
- end
324
- end
325
-
326
- #end
327
-
328
-