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
@@ -34,7 +34,7 @@
34
34
 
35
35
 
36
36
  require 'facets/functor'
37
- #require 'facets/module/name' # was identify, for what?
37
+ require 'facets/module/name' # for Module#basename
38
38
 
39
39
 
40
40
  #
@@ -32,6 +32,42 @@ require 'ostruct'
32
32
 
33
33
  class OpenStruct
34
34
 
35
+ #
36
+ # Allows the initialization of an OpenStruct with a block:
37
+ #
38
+ # person = OpenStruct.new do |p|
39
+ # p.name = 'John Smith'
40
+ # p.gender = :M
41
+ # p.age = 71
42
+ # end
43
+ #
44
+ # You can still provide a hash for initialization purposes, and even combine
45
+ # the two approaches if you wish.
46
+ #
47
+ # person = OpenStruct.new(:name => 'John Smith', :age => 31) do |p|
48
+ # p.gender = :M
49
+ # end
50
+ #
51
+ # CREDIT Noah Gibbs
52
+ # CREDIT Gavin Sinclair
53
+
54
+ def initialize(hash=nil) # :yield: self
55
+ @table = {}
56
+ if hash
57
+ for k,v in hash
58
+ @table[k.to_sym] = v
59
+ new_ostruct_member(k)
60
+ end
61
+ end
62
+ yield self if block_given?
63
+ end
64
+
65
+ #
66
+ def each(&blk)
67
+ @table.each(&blk)
68
+ end
69
+
70
+ #
35
71
  def to_h
36
72
  @table
37
73
  end
@@ -88,8 +124,8 @@ class OpenStruct
88
124
  # o.a #=> 2
89
125
  #
90
126
  def ostruct_update(other)
91
- hash = other.to_hash #to_h ?
92
- for k,v in hash
127
+ #other = other.to_hash #to_h ?
128
+ for k,v in other
93
129
  @table[k.to_sym] = v
94
130
  end
95
131
  self
@@ -119,9 +155,9 @@ class OpenStruct
119
155
  # o.ostruct_update { :a => 2 }
120
156
  # o.a #=> 2
121
157
  #
122
- def __update__( other )
123
- hash = other.to_h
124
- for k,v in hash
158
+ def __update__(other)
159
+ #other = other.to_hash #to_h?
160
+ for k,v in other
125
161
  @table[k.to_sym] = v
126
162
  end
127
163
  self
@@ -133,9 +169,9 @@ class OpenStruct
133
169
  # o.ostruct_merge { :a => 2 }
134
170
  # o.a #=> 2
135
171
  #
136
- def __merge__( other )
172
+ def __merge__(other)
137
173
  o = dup
138
- o.__update__( other )
174
+ o.__update__(other)
139
175
  o
140
176
  end
141
177
  end
@@ -176,14 +212,14 @@ class Hash
176
212
  # o = h.to_ostruct_recurse( { h['a'] => h['a'] } )
177
213
  # o.a['b'] #=> 1
178
214
  #
179
- def to_ostruct_recurse( exclude={} )
215
+ def to_ostruct_recurse(exclude={})
180
216
  return exclude[self] if exclude.key?( self )
181
217
  o = exclude[self] = OpenStruct.new
182
218
  h = self.dup
183
219
  each_pair do |k,v|
184
- h[k] = v.to_ostruct_recurse( exclude ) if v.respond_to?( :to_ostruct_recurse )
220
+ h[k] = v.to_ostruct_recurse( exclude ) if v.respond_to?(:to_ostruct_recurse)
185
221
  end
186
- o.__update__( h )
222
+ o.__update__(h)
187
223
  end
188
224
 
189
225
  end
@@ -98,54 +98,3 @@ class Module
98
98
  end
99
99
 
100
100
  end
101
-
102
-
103
- # _____ _
104
- # |_ _|__ ___| |_
105
- # | |/ _ \/ __| __|
106
- # | | __/\__ \ |_
107
- # |_|\___||___/\__|
108
- #
109
-
110
- =begin test
111
-
112
- require 'test/unit'
113
-
114
- class TCOverload < Test::Unit::TestCase
115
-
116
- class X
117
-
118
- def x
119
- "hello"
120
- end
121
-
122
- overload :x, Integer do |i|
123
- i
124
- end
125
-
126
- overload :x, String, String do |s1, s2|
127
- [s1, s2]
128
- end
129
-
130
- end
131
-
132
- def setup
133
- @x = X.new
134
- end
135
-
136
- def test_x
137
- assert_equal( "hello", @x.x )
138
- end
139
-
140
- def test_i
141
- assert_equal( 1, @x.x(1) )
142
- end
143
-
144
- def test_s
145
- assert_equal( ["a","b"], @x.x("a","b") )
146
- end
147
-
148
- end
149
-
150
- =end
151
-
@@ -146,100 +146,3 @@ class Module
146
146
  end
147
147
 
148
148
  end
149
-
150
-
151
-
152
- # _____ _
153
- # |_ _|__ ___| |_
154
- # | |/ _ \/ __| __|
155
- # | | __/\__ \ |_
156
- # |_|\___||___/\__|
157
- #
158
-
159
- =begin test
160
-
161
- require 'test/unit'
162
- require 'facets/kernel/metaid'
163
-
164
- class TC01 < Test::Unit::TestCase
165
-
166
- module M
167
- def f
168
- M(:p)
169
- end
170
- def self.included_with_parameters( base, parms )
171
- base.class_eval do
172
- define_method :check do
173
- parms
174
- end
175
- end
176
- end
177
- end
178
-
179
- class C
180
- include M, :p => "check"
181
- end
182
-
183
- class D
184
- include M, :p => "steak"
185
- end
186
-
187
- def test_01_001
188
- c = C.new
189
- assert_equal( "check", c.M(:p) )
190
- assert_equal( "check", c.f )
191
- end
192
-
193
- def test_01_002
194
- d = D.new
195
- assert_equal( "steak", d.M(:p) )
196
- assert_equal( "steak", d.f )
197
- end
198
-
199
- def test_01_003
200
- assert_equal( {M=>{:p => "check"}}, C.mixin_parameters )
201
- assert_equal( {M=>{:p => "steak"}}, D.mixin_parameters )
202
- end
203
-
204
- def test_01_004
205
- c = C.new
206
- assert_equal( {:p => "check"}, c.check )
207
- d = D.new
208
- assert_equal( {:p => "steak"}, d.check )
209
- end
210
-
211
- end
212
-
213
-
214
- class TC02 < Test::Unit::TestCase
215
-
216
- module M
217
- def f
218
- M(:p)
219
- end
220
- end
221
-
222
- class C
223
- extend M, :p => "mosh"
224
- end
225
-
226
- class D
227
- extend M, :p => "many"
228
- end
229
-
230
- def test_02_001
231
- assert_equal( "mosh", C.f )
232
- end
233
-
234
- def test_02_002
235
- assert_equal( "many", D.f )
236
- end
237
-
238
- def test_02_003
239
- assert_equal( {M=>{:p => "mosh"}}, C.eigenclass.mixin_parameters )
240
- assert_equal( {M=>{:p => "many"}}, D.eigenclass.mixin_parameters )
241
- end
242
-
243
- end
244
-
245
- =end
@@ -0,0 +1,30 @@
1
+ # TODO How useful is this really? Or, can it go in with something else?
2
+
3
+ require 'pp'
4
+ require 'stringio'
5
+
6
+ module Kernel
7
+
8
+ # Returns a pretty-printed string of the object. Requires libraries +pp+ and
9
+ # +stringio+ from the Ruby standard library.
10
+ #
11
+ # The following code pretty-prints an object (much like +p+ plain-prints an
12
+ # object):
13
+ #
14
+ # pp object
15
+ #
16
+ # The following code captures the pretty-printing in +str+ instead of
17
+ # sending it to +STDOUT+.
18
+ #
19
+ # str = object.pp_s
20
+ #
21
+ # CREDIT Noah Gibbs
22
+ # CREDIT Gavin Sinclair
23
+
24
+ def pp_s
25
+ pps = StringIO.new
26
+ PP.pp(self, pps)
27
+ pps.string
28
+ end
29
+
30
+ end
@@ -25,7 +25,7 @@
25
25
  #
26
26
  # == Usage
27
27
  #
28
- # pbar = ConsoleProgressBar.new( "Demo", 100 )
28
+ # pbar = Console::ProgressBar.new( "Demo", 100 )
29
29
  # 100.times { pbar.inc }
30
30
  # pbar.finish
31
31
  #
@@ -72,7 +72,7 @@ class Console::ProgressBar
72
72
  convert_bytes(@current)
73
73
  end
74
74
 
75
- def format_time (t)
75
+ def format_time(t)
76
76
  t = t.to_i
77
77
  sec = t % 60
78
78
  min = (t / 60) % 60
@@ -147,7 +147,7 @@ class Console::ProgressBar
147
147
  end
148
148
 
149
149
  def show
150
- arguments = @format_arguments.map {|method| send(method) }
150
+ arguments = @format_arguments.map{|method| send(method)}
151
151
  line = sprintf(@format, *arguments)
152
152
 
153
153
  width = get_width
@@ -178,22 +178,26 @@ class Console::ProgressBar
178
178
 
179
179
  public
180
180
  def file_transfer_mode
181
- @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
181
+ @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
182
182
  end
183
183
 
184
- def bar_mark= (mark)
184
+ def title=(str)
185
+ @title = str
186
+ end
187
+
188
+ def bar_mark=(mark)
185
189
  @bar_mark = String(mark)[0..0]
186
190
  end
187
191
 
188
- def total_overflow= (boolv)
192
+ def total_overflow=(boolv)
189
193
  @total_overflow = boolv ? true : false
190
194
  end
191
195
 
192
- def format= (format)
196
+ def format=(format)
193
197
  @format = format
194
198
  end
195
199
 
196
- def format_arguments= (arguments)
200
+ def format_arguments=(arguments)
197
201
  @format_arguments = arguments
198
202
  end
199
203
 
@@ -203,12 +207,16 @@ class Console::ProgressBar
203
207
  show_progress
204
208
  end
205
209
 
210
+ def flush
211
+ @out.flush
212
+ end
213
+
206
214
  def halt
207
215
  @is_finished = true
208
216
  show_progress
209
217
  end
210
218
 
211
- def set (count)
219
+ def set(count)
212
220
  if count < 0
213
221
  raise "invalid count less than zero: #{count}"
214
222
  elsif count > @total
@@ -223,7 +231,7 @@ class Console::ProgressBar
223
231
  @previous = @current
224
232
  end
225
233
 
226
- def inc (step = 1)
234
+ def inc(step = 1)
227
235
  @current += step
228
236
  @current = @total if @current > @total
229
237
  show_progress
@@ -53,7 +53,7 @@ class Prototype
53
53
  end
54
54
 
55
55
  def trait(obj)
56
- traist << obj.new
56
+ traits << obj.new
57
57
  end
58
58
 
59
59
  def method_missing(s, *a, &b)
@@ -87,42 +87,3 @@ module Kernel
87
87
  end
88
88
 
89
89
  end
90
-
91
-
92
-
93
- =begin test
94
-
95
- require 'test/unit'
96
-
97
- class TestPrototypeKernel < Test::Unit::TestCase
98
-
99
- def test_new
100
- q = nil
101
- s = "Testing"
102
- assert_nothing_raised { q = s.new }
103
- assert_equal( s, q )
104
- assert_not_equal( s.object_id, q.object_id )
105
- end
106
- end
107
-
108
- class TestPrototype < Test::Unit::TestCase
109
-
110
- def setup
111
- @person = prototype do
112
- @name = ''
113
- @age = 0
114
- @announce = fn { |x| "#{x}, #{name} is #{age}" }
115
- end
116
-
117
- @person.name = 'Tom'
118
- @person.age = 35
119
- end
120
-
121
- def test_simple_case
122
- assert_equal( "Peter, Tom is 35", @person.announce['Peter'])
123
- end
124
-
125
- end
126
-
127
- =end
128
-
@@ -28,6 +28,7 @@
28
28
  # - Thomas Sawyer
29
29
 
30
30
  require 'facets/hash/new' # for zipnew
31
+ require 'facets/string/scan' # for shatter
31
32
 
32
33
  module Kernel
33
34
 
@@ -33,7 +33,10 @@
33
33
  #
34
34
  # - Thomas Sawyer
35
35
  # - Minero Aoki
36
-
36
+ #
37
+ # TODO:
38
+ #
39
+ # - Consider renaming module to "Ruby" ?
37
40
 
38
41
  require 'rbconfig'
39
42