ruby_ex 0.4.6.1 → 0.4.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -1,3 +1,7 @@
1
+ = New in 0.4_p2, 2006-03-11:
2
+
3
+ Fix a bug in the pathname substitution inside symbol tables.
4
+
1
5
  = New in 0.4_p1, 2006-03-10:
2
6
 
3
7
  Fix a bug in sendmail.rb with recents ruby versions.
data/SPEC.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  Author: The Uttk Team.
3
3
  License: Ruby License
4
- Revision: '$Id: /w/fey/ruby_ex/trunk/SPEC.yml 22255 2006-02-26T14:19:43.502502Z pouillar $'
4
+ Revision: '$Id: /w/fey/ruby_ex/trunk/SPEC.yml 22445 2006-03-11T15:56:04.480135Z pouillar $'
5
5
 
6
- version: !feydakins.org,2006/version dev-ruby/ruby_ex-0.4_p1
6
+ version: !feydakins.org,2006/version dev-ruby/ruby_ex-0.4_p2
7
7
 
8
8
  title: RubyEx -- General purpose Ruby extensions.
9
9
  summary: RubyEx contains general purpose Ruby extensions.
@@ -17,7 +17,7 @@ root_test_suite: test/check-pkg-ruby_ex.yml
17
17
  rdoc_dir: doc/html
18
18
  tags_url: svn://svn.feydakins.org/ruby_ex/tags
19
19
  trunk_url: svn://svn.feydakins.org/ruby_ex/trunk
20
- version_path: !path lib/ruby_ex.rb
20
+ version_id.rb: !path lib/ruby_ex.rb
21
21
 
22
22
  rdoc_files: !filelist
23
23
  - README
@@ -1,339 +1,336 @@
1
- # Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
2
- # Author: Nicolas Despres <polrop@lrde.epita.fr>.
3
- # License: Gnu General Public License.
4
-
5
- # $LastChangedBy: polrop $
6
- # $Id: /w/fey/ruby_ex/trunk/lib/module/hierarchy.rb 7944 2005-09-06T23:27:27.929371Z ertai $
7
-
8
-
9
- # Extend the Module class with method to manipulate inheritance relation
10
- # between constants of a module.
11
- module Hierarchy
12
-
13
- # Return the list of all sub classes of base_class (including itself).
14
- # If force_autoload is false, not yet loaded constants will be ignored.
15
- # If recursive is true sub modules will also be traversed.
16
- def sub_classes(base_class, force_autoload=false, recursive=false)
17
- check_const_is_class?(base_class)
18
- result = []
19
- constants.each do |const_name|
20
- if autoload?(const_name).nil? or force_autoload
21
- const = const_get(const_name)
22
- if const.is_a?(Module)
23
- if const.is_a?(Class)
24
- result << const if const.ancestors.include?(base_class)
25
- elsif recursive
26
- result += const.sub_classes(base_class, force_autoload, recursive)
1
+ # Copyright:: Copyright (c) 2004, 2006 Nicolas Despres. All rights reserved.
2
+ # Author:: Nicolas Despres <polrop@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/module/hierarchy.rb 22446 2006-03-11T18:07:59.270837Z pouillar $
5
+
6
+ class Module
7
+
8
+ # Extend the Module class with method to manipulate inheritance relation
9
+ # between constants of a module.
10
+ module Hierarchy
11
+
12
+ # Return the list of all sub classes of base_class (including itself).
13
+ # If force_autoload is false, not yet loaded constants will be ignored.
14
+ # If recursive is true sub modules will also be traversed.
15
+ def sub_classes(base_class, force_autoload=false, recursive=false)
16
+ check_const_is_class?(base_class)
17
+ result = []
18
+ constants.each do |const_name|
19
+ if autoload?(const_name).nil? or force_autoload
20
+ const = const_get(const_name)
21
+ if const.is_a?(Module)
22
+ if const.is_a?(Class)
23
+ result << const if const.ancestors.include?(base_class)
24
+ elsif recursive
25
+ result += const.sub_classes(base_class, force_autoload, recursive)
26
+ end
27
27
  end
28
28
  end
29
29
  end
30
+ result
30
31
  end
31
- result
32
- end
33
-
34
- # Remove a class from the hierarchy using remove_const. Sub classes of this
35
- # class are also removed. It returns an array of the removed class name.
36
- # See sub_classes for a description of the recursive argument.
37
- def remove_class(base_class, recursive=false)
38
- subs = sub_classes(base_class, true, recursive)
39
- re = /^#{name}::/
40
- result = []
41
- subs.each do |sub|
42
- sub_name = sub.to_s.sub!(re, '')
43
- if sub_name =~ /^(.+)::(.+)$/
44
- const_get($1).module_eval { remove_const($2.to_sym) }
45
- else
46
- remove_const(sub_name.to_sym)
32
+
33
+ # Remove a class from the hierarchy using remove_const. Sub classes of this
34
+ # class are also removed. It returns an array of the removed class name.
35
+ # See sub_classes for a description of the recursive argument.
36
+ def remove_class(base_class, recursive=false)
37
+ subs = sub_classes(base_class, true, recursive)
38
+ re = /^#{name}::/
39
+ result = []
40
+ subs.each do |sub|
41
+ sub_name = sub.to_s.sub!(re, '')
42
+ if sub_name =~ /^(.+)::(.+)$/
43
+ const_get($1).module_eval { remove_const($2.to_sym) }
44
+ else
45
+ remove_const(sub_name.to_sym)
46
+ end
47
+ result << sub_name
47
48
  end
48
- result << sub_name
49
+ result
49
50
  end
50
- result
51
- end
52
-
53
- # Return the inheritance tree of the base_class.
54
- # Example:
55
- #
56
- # module M
57
- # class A; end
58
- # class B < A; end
59
- # class C < B; end
60
- # class D < B; end
61
- # class E < A; end
62
- # module N
63
- # class F < A; end
64
- # class G < F; end
65
- # class H < D; end
66
- # class I < H; end
67
- # class J < E; end
68
- # class Y; end
69
- # end
70
- # class Z; end
71
- # FOO = 42
72
- # end
73
- #
74
- # M.sub_classes_tree(M::A)
75
- #
76
- # produces:
77
- #
78
- # {
79
- # M::A => {
80
- # M::B => {
81
- # M::D => {},
82
- # M::C => {}
83
- # },
84
- # M::E => {}
85
- # }
86
- # }
87
- #
88
- # and
89
- #
90
- # M.sub_classes_tree(M::A, false, true)
91
- #
92
- # produces:
93
- #
94
- # {
95
- # M::A => {
96
- # M::N::F => {
97
- # M::N::G => {}
98
- # },
99
- # M::B => {
100
- # M::C => {},
101
- # M::D => {
102
- # M::N::H => {
103
- # M::N::I => {}
104
- # }
105
- # }
106
- # },
107
- # M::E => {
108
- # M::N::J => {}
109
- # }
110
- # }
111
- # }
112
- def sub_classes_tree(base_class, force_autoload=false, recursive=false)
113
- subs = sub_classes(base_class, force_autoload, recursive)
114
- sub_classes_tree_rec([base_class], subs)
115
- end
116
-
117
- private
118
- def sub_classes_tree_rec(base_classes, csts)
119
- result = {}
120
- next_csts = Set.new
121
- base_classes.each do |b|
122
- next_base_classes = Set.new
123
- csts.each do |c|
124
- c.superclass == b ? next_base_classes << c : next_csts << c;
125
- end
126
- result[b] = sub_classes_tree_rec(next_base_classes, next_csts)
51
+
52
+ # Return the inheritance tree of the base_class.
53
+ # Example:
54
+ #
55
+ # module M
56
+ # class A; end
57
+ # class B < A; end
58
+ # class C < B; end
59
+ # class D < B; end
60
+ # class E < A; end
61
+ # module N
62
+ # class F < A; end
63
+ # class G < F; end
64
+ # class H < D; end
65
+ # class I < H; end
66
+ # class J < E; end
67
+ # class Y; end
68
+ # end
69
+ # class Z; end
70
+ # FOO = 42
71
+ # end
72
+ #
73
+ # M.sub_classes_tree(M::A)
74
+ #
75
+ # produces:
76
+ #
77
+ # {
78
+ # M::A => {
79
+ # M::B => {
80
+ # M::D => {},
81
+ # M::C => {}
82
+ # },
83
+ # M::E => {}
84
+ # }
85
+ # }
86
+ #
87
+ # and
88
+ #
89
+ # M.sub_classes_tree(M::A, false, true)
90
+ #
91
+ # produces:
92
+ #
93
+ # {
94
+ # M::A => {
95
+ # M::N::F => {
96
+ # M::N::G => {}
97
+ # },
98
+ # M::B => {
99
+ # M::C => {},
100
+ # M::D => {
101
+ # M::N::H => {
102
+ # M::N::I => {}
103
+ # }
104
+ # }
105
+ # },
106
+ # M::E => {
107
+ # M::N::J => {}
108
+ # }
109
+ # }
110
+ # }
111
+ def sub_classes_tree(base_class, force_autoload=false, recursive=false)
112
+ subs = sub_classes(base_class, force_autoload, recursive)
113
+ sub_classes_tree_rec([base_class], subs)
127
114
  end
128
- result
129
- end
130
115
 
131
- private
132
- def check_const_is_class?(*base_classes)
133
- base_classes.each do |b|
134
- raise(TypeError, "`#{b}' - not a class") unless b.is_a?(Class)
116
+ private
117
+ def sub_classes_tree_rec(base_classes, csts)
118
+ result = {}
119
+ next_csts = Set.new
120
+ base_classes.each do |b|
121
+ next_base_classes = Set.new
122
+ csts.each do |c|
123
+ c.superclass == b ? next_base_classes << c : next_csts << c;
124
+ end
125
+ result[b] = sub_classes_tree_rec(next_base_classes, next_csts)
126
+ end
127
+ result
135
128
  end
136
- end
137
129
 
138
- end # module Hierarchy
130
+ private
131
+ def check_const_is_class?(*base_classes)
132
+ base_classes.each do |b|
133
+ raise(TypeError, "`#{b}' - not a class") unless b.is_a?(Class)
134
+ end
135
+ end
139
136
 
140
- class Module
137
+ end # module Hierarchy
141
138
 
142
139
  include Hierarchy
143
140
 
144
- end # class Module
145
-
146
- module Hierarchy
147
-
148
- test_section __FILE__ do
141
+ module Hierarchy
149
142
 
150
- require 'diff'
143
+ test_section __FILE__ do
151
144
 
145
+ require 'diff'
152
146
 
153
- class HierarchyTest < Test::Unit::TestCase
154
147
 
155
- module M
148
+ class HierarchyTest < Test::Unit::TestCase
156
149
 
157
- class A; end
158
- class B < A; end
159
- class C; end
160
- FOO = 42
150
+ module M
161
151
 
162
- end
152
+ class A; end
153
+ class B < A; end
154
+ class C; end
155
+ FOO = 42
163
156
 
164
- def test_sub_classes
165
- sub_classes = M.sub_classes(HierarchyTest::M::A)
166
- assert_equal(2, sub_classes.size)
167
- [HierarchyTest::M::B, HierarchyTest::M::A].each do |x|
168
- assert(sub_classes.include?(x))
169
157
  end
170
- assert_equal([HierarchyTest::M::C], M.sub_classes(M::C))
171
- end
172
158
 
173
- module Mautoload
159
+ def test_sub_classes
160
+ sub_classes = M.sub_classes(HierarchyTest::M::A)
161
+ assert_equal(2, sub_classes.size)
162
+ [HierarchyTest::M::B, HierarchyTest::M::A].each do |x|
163
+ assert(sub_classes.include?(x))
164
+ end
165
+ assert_equal([HierarchyTest::M::C], M.sub_classes(M::C))
166
+ end
174
167
 
175
- class A; end
176
- class B < A; end
177
- autoload(:C, '/foo')
178
- FOO = 42
168
+ module Mautoload
179
169
 
180
- end
170
+ class A; end
171
+ class B < A; end
172
+ autoload(:C, '/foo')
173
+ FOO = 42
181
174
 
182
- def test_sub_classes_force_autoload
183
- sub_classes = Mautoload.sub_classes(Mautoload::A)
184
- assert_equal(2, sub_classes.size)
185
- [Mautoload::B, Mautoload::A].each do |x|
186
- assert(sub_classes.include?(x))
187
175
  end
188
- assert_equal(4, Mautoload.constants.size)
189
- assert_not_nil(Mautoload.autoload?(:C))
190
- assert_raise(MissingSourceFile, LoadError) { Mautoload.sub_classes(Mautoload::A, true) }
191
- assert_equal(3, Mautoload.constants.size)
192
- assert_nil(Mautoload.autoload?(:C))
193
- end
194
176
 
195
- module Mrec
196
- class A; end
197
- class B < A; end
198
- module M
199
- class C < A; end
200
- class D < B; end
201
- class E < D; end
202
- class Y; end
177
+ def test_sub_classes_force_autoload
178
+ sub_classes = Mautoload.sub_classes(Mautoload::A)
179
+ assert_equal(2, sub_classes.size)
180
+ [Mautoload::B, Mautoload::A].each do |x|
181
+ assert(sub_classes.include?(x))
182
+ end
183
+ assert_equal(4, Mautoload.constants.size)
184
+ assert_not_nil(Mautoload.autoload?(:C))
185
+ assert_raise(MissingSourceFile, LoadError) { Mautoload.sub_classes(Mautoload::A, true) }
186
+ assert_equal(3, Mautoload.constants.size)
187
+ assert_nil(Mautoload.autoload?(:C))
203
188
  end
204
- class Z; end
205
- FOO = 42
206
- end
207
189
 
208
- def test_sub_classes_recursive
209
- sub_classes = Mrec.sub_classes(Mrec::A)
210
- assert_equal(2, sub_classes.size)
211
- [Mrec::B, Mrec::A].each do |x|
212
- assert(sub_classes.include?(x))
213
- end
214
- sub_classes = Mrec.sub_classes(Mrec::A, false, true)
215
- assert_equal(5, sub_classes.size)
216
- [Mrec::B, Mrec::A, Mrec::M::C, Mrec::M::D, Mrec::M::E].each do |x|
217
- assert(sub_classes.include?(x))
190
+ module Mrec
191
+ class A; end
192
+ class B < A; end
193
+ module M
194
+ class C < A; end
195
+ class D < B; end
196
+ class E < D; end
197
+ class Y; end
198
+ end
199
+ class Z; end
200
+ FOO = 42
218
201
  end
219
- r = Mrec.remove_class(Mrec::A, true)
220
- assert_equal(5, r.size)
221
- ['B', 'A', 'M::E', 'M::C', 'M::D'].each do |x|
222
- assert(r.include?(x))
202
+
203
+ def test_sub_classes_recursive
204
+ sub_classes = Mrec.sub_classes(Mrec::A)
205
+ assert_equal(2, sub_classes.size)
206
+ [Mrec::B, Mrec::A].each do |x|
207
+ assert(sub_classes.include?(x))
208
+ end
209
+ sub_classes = Mrec.sub_classes(Mrec::A, false, true)
210
+ assert_equal(5, sub_classes.size)
211
+ [Mrec::B, Mrec::A, Mrec::M::C, Mrec::M::D, Mrec::M::E].each do |x|
212
+ assert(sub_classes.include?(x))
213
+ end
214
+ r = Mrec.remove_class(Mrec::A, true)
215
+ assert_equal(5, r.size)
216
+ ['B', 'A', 'M::E', 'M::C', 'M::D'].each do |x|
217
+ assert(r.include?(x))
218
+ end
219
+ assert_equal(3, Mrec.constants.size)
220
+ ['FOO', 'M', 'Z'].each { |x| assert(Mrec.constants.include?(x)) }
221
+ assert_equal(1, Mrec::M.constants.size)
222
+ ['Y'].each { |x| assert(Mrec::M.constants.include?(x)) }
223
223
  end
224
- assert_equal(3, Mrec.constants.size)
225
- ['FOO', 'M', 'Z'].each { |x| assert(Mrec.constants.include?(x)) }
226
- assert_equal(1, Mrec::M.constants.size)
227
- ['Y'].each { |x| assert(Mrec::M.constants.include?(x)) }
228
- end
229
224
 
230
- module Tree
225
+ module Tree
231
226
 
232
- class A; end
233
- class B < A; end
234
- class C < B; end
235
- class D < B; end
236
- class E < A; end
237
- module M
238
- class F < A; end
239
- class G < F; end
240
- class H < D; end
241
- class I < H; end
242
- class J < E; end
243
- class Y; end
244
- end
245
- class Z; end
246
- FOO = 42
227
+ class A; end
228
+ class B < A; end
229
+ class C < B; end
230
+ class D < B; end
231
+ class E < A; end
232
+ module M
233
+ class F < A; end
234
+ class G < F; end
235
+ class H < D; end
236
+ class I < H; end
237
+ class J < E; end
238
+ class Y; end
239
+ end
240
+ class Z; end
241
+ FOO = 42
247
242
 
248
- end
243
+ end
249
244
 
250
- def test_sub_classes_tree_rec
251
- r = Tree.sub_classes_tree(HierarchyTest::Tree::A, false, true)
252
- ref = {
253
- HierarchyTest::Tree::A => {
254
- HierarchyTest::Tree::M::F => {
255
- HierarchyTest::Tree::M::G => {}
256
- },
257
- HierarchyTest::Tree::B => {
258
- HierarchyTest::Tree::C => {},
259
- HierarchyTest::Tree::D => {
260
- HierarchyTest::Tree::M::H => {
261
- HierarchyTest::Tree::M::I=>{}
245
+ def test_sub_classes_tree_rec
246
+ r = Tree.sub_classes_tree(HierarchyTest::Tree::A, false, true)
247
+ ref = {
248
+ HierarchyTest::Tree::A => {
249
+ HierarchyTest::Tree::M::F => {
250
+ HierarchyTest::Tree::M::G => {}
251
+ },
252
+ HierarchyTest::Tree::B => {
253
+ HierarchyTest::Tree::C => {},
254
+ HierarchyTest::Tree::D => {
255
+ HierarchyTest::Tree::M::H => {
256
+ HierarchyTest::Tree::M::I=>{}
257
+ }
262
258
  }
259
+ },
260
+ HierarchyTest::Tree::E=> {
261
+ HierarchyTest::Tree::M::J=>{}
263
262
  }
264
- },
265
- HierarchyTest::Tree::E=> {
266
- HierarchyTest::Tree::M::J=>{}
267
263
  }
268
264
  }
269
- }
270
- d = r.diff(ref)
271
- assert_equal({}, d[:different])
272
- assert_equal({}, d[:additional])
273
- assert_equal({}, d[:missing])
274
- end
265
+ d = r.diff(ref)
266
+ assert_equal({}, d[:different])
267
+ assert_equal({}, d[:additional])
268
+ assert_equal({}, d[:missing])
269
+ end
275
270
 
276
- def test_sub_classes_tree
277
- r = Tree.sub_classes_tree(HierarchyTest::Tree::A)
278
- ref = {
279
- HierarchyTest::Tree::A => {
280
- HierarchyTest::Tree::B => {
281
- HierarchyTest::Tree::D => {},
282
- HierarchyTest::Tree::C => {}
283
- },
284
- HierarchyTest::Tree::E => {}
271
+ def test_sub_classes_tree
272
+ r = Tree.sub_classes_tree(HierarchyTest::Tree::A)
273
+ ref = {
274
+ HierarchyTest::Tree::A => {
275
+ HierarchyTest::Tree::B => {
276
+ HierarchyTest::Tree::D => {},
277
+ HierarchyTest::Tree::C => {}
278
+ },
279
+ HierarchyTest::Tree::E => {}
280
+ }
285
281
  }
286
- }
287
- d = r.diff(ref)
288
- assert_equal({}, d[:different])
289
- assert_equal({}, d[:additional])
290
- assert_equal({}, d[:missing])
291
- end
292
-
293
- module Error
294
- module M; end
295
- end
296
-
297
- def test_sub_classes_error
298
- assert_raise(TypeError) do
299
- Error.sub_classes_tree(HierarchyTest::Error::M)
282
+ d = r.diff(ref)
283
+ assert_equal({}, d[:different])
284
+ assert_equal({}, d[:additional])
285
+ assert_equal({}, d[:missing])
300
286
  end
301
- assert_raise(TypeError) do
302
- Error.sub_classes(HierarchyTest::Error::M)
287
+
288
+ module Error
289
+ module M; end
303
290
  end
304
- assert_raise(TypeError) do
305
- Error.remove_class(HierarchyTest::Error::M)
291
+
292
+ def test_sub_classes_error
293
+ assert_raise(TypeError) do
294
+ Error.sub_classes_tree(HierarchyTest::Error::M)
295
+ end
296
+ assert_raise(TypeError) do
297
+ Error.sub_classes(HierarchyTest::Error::M)
298
+ end
299
+ assert_raise(TypeError) do
300
+ Error.remove_class(HierarchyTest::Error::M)
301
+ end
306
302
  end
307
- end
308
303
 
309
- module RemoveClass
304
+ module RemoveClass
310
305
 
311
- class A; end
312
- class B < A; end
313
- class C < B; end
314
- class D < B; end
315
- class E < D; end
316
- class F < A; end
317
- class Z; end
318
- module M
319
- class Y; end
320
- end
321
- BAR = 51
306
+ class A; end
307
+ class B < A; end
308
+ class C < B; end
309
+ class D < B; end
310
+ class E < D; end
311
+ class F < A; end
312
+ class Z; end
313
+ module M
314
+ class Y; end
315
+ end
316
+ BAR = 51
322
317
 
323
- end
318
+ end
324
319
 
325
- def test_remove_class
326
- r = RemoveClass.remove_class(HierarchyTest::RemoveClass::B)
327
- assert_equal(4, r.size)
328
- ['B', 'D', 'E', 'C'].each { |x| assert(r.include?(x)) }
329
- assert_equal(5, RemoveClass.constants.size)
330
- ['A', 'F', 'Z', 'M', 'BAR'].each do |x|
331
- assert(RemoveClass.constants.include?(x))
320
+ def test_remove_class
321
+ r = RemoveClass.remove_class(HierarchyTest::RemoveClass::B)
322
+ assert_equal(4, r.size)
323
+ ['B', 'D', 'E', 'C'].each { |x| assert(r.include?(x)) }
324
+ assert_equal(5, RemoveClass.constants.size)
325
+ ['A', 'F', 'Z', 'M', 'BAR'].each do |x|
326
+ assert(RemoveClass.constants.include?(x))
327
+ end
332
328
  end
333
- end
334
329
 
335
- end # class HierarchyTest
330
+ end # class HierarchyTest
331
+
332
+ end
336
333
 
337
- end
334
+ end # module Hierarchy
338
335
 
339
- end # module Hierarchy
336
+ end # class Module
data/lib/ruby_ex.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
2
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/ruby_ex.rb 22255 2006-02-26T14:19:43.502502Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/ruby_ex.rb 22445 2006-03-11T15:56:04.480135Z pouillar $
5
5
 
6
6
  require 'pathname'
7
7
 
@@ -57,7 +57,7 @@ module RubyEx
57
57
  i.fixed_cases 'URI', 'DRuby', 'MySQL', 'PgSQL', 'FTP', 'HTTP', 'DRb'
58
58
  end
59
59
 
60
- Version = ::Version.parse("dev-ruby/ruby_ex-0.4_p1")
60
+ VersionId = ::Version.parse("dev-ruby/ruby_ex-0.4_p2")
61
61
 
62
62
  dir.load_path!
63
63
  (dir + 'module').load_path!
data/lib/sym_tbl_gsub.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: Ruby License
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/sym_tbl_gsub.rb 21868 2006-02-18T18:09:17.837831Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/sym_tbl_gsub.rb 22444 2006-03-11T15:54:37.116683Z pouillar $
5
5
 
6
6
  module SymTblGsub
7
7
 
@@ -10,13 +10,24 @@ module SymTblGsub
10
10
  attr_accessor :symtbl
11
11
 
12
12
  def assert_symtbl ( my, ref )
13
+ my_copy = Marshal.load(Marshal.dump(my))
13
14
  assert_equal ref, my.do_symtbl_gsub(symtbl)
15
+ assert_equal my, my_copy,
16
+ 'substitution not inplace has changed the object'
14
17
  end
15
18
 
16
19
  def assert_symtbl_nil ( my )
17
20
  assert_nil my.symtbl_gsub(symtbl)
18
21
  end
19
22
 
23
+ def assert_symtbl! ( my, ref )
24
+ assert_equal ref, my.do_symtbl_gsub!(symtbl)
25
+ end
26
+
27
+ def assert_symtbl_nil! ( my )
28
+ assert_nil my.symtbl_gsub!(symtbl)
29
+ end
30
+
20
31
  end # module Assertions
21
32
 
22
33
  end # module SymTblGsub
@@ -123,7 +134,8 @@ class Pathname
123
134
  end
124
135
 
125
136
  def symtbl_gsub ( symtbl )
126
- dup.symtbl_gsub!(symtbl)
137
+ x = Pathname.new(@path.dup)
138
+ x.symtbl_gsub!(symtbl)
127
139
  end
128
140
 
129
141
  end # class Pathname
@@ -266,6 +278,14 @@ module SymTblGsub
266
278
  assert_symtbl '<<dne>> <<foo>>', '<<dne>> bar'
267
279
  end
268
280
  class Foo
281
+ include Comparable
282
+ attr_reader :y
283
+ def initialize
284
+ @y = rand
285
+ end
286
+ def <=> ( x )
287
+ @y <=> x.y
288
+ end
269
289
  end
270
290
  def test_object
271
291
  f = Foo.new
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
2
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/uri/generic_ex.rb 22242 2006-02-24T17:19:34.959052Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/uri/generic_ex.rb 22448 2006-03-11T18:09:23.325348Z pouillar $
5
5
 
6
6
  module URI
7
7
 
@@ -142,10 +142,12 @@ module URI
142
142
  def test_lazy_loading_full
143
143
  PathList[__FILE__.to_path.dirname.parent + '(uri/**/*).rb'].each do |full, path|
144
144
  assert_nothing_raised do
145
- class_name = path.to_s.camelize.gsub(/Ex$/, '')
145
+ next if path.to_s == 'uri/generic_ex'
146
+ class_name = path.to_s.gsub(/_ex$/, '').camelize
146
147
  class_object = class_name.constantize
147
148
  assert_equal class_name, class_object.name
148
- assert_match(/URI::Generic(Ex)?/, class_object.superclass.name)
149
+ assert_match(/URI::Generic(Ex)?/, class_object.superclass.name,
150
+ "Superclass of #{class_object}")
149
151
  end
150
152
  end
151
153
  end
@@ -7,95 +7,91 @@ require 'yaml'
7
7
  require 'stringio'
8
8
  require 'test/unit'
9
9
 
10
- module Algorithms
10
+ class SimulatedAnnealingTest < Test::Unit::TestCase
11
11
 
12
- class SimulatedAnnealingTest < Test::Unit::TestCase
12
+ class BasicFunction
13
+ include Algorithms::SimulatedAnnealing::Support
13
14
 
14
- class BasicFunction
15
- include SimulatedAnnealing::Support
16
-
17
- def initialize ( &fun )
18
- @max = 100000
19
- @min = -@max
20
- @step_width = 500
21
- @f = fun
22
- @cur_pos = (@min..@max).choose
23
- end
24
-
25
- def choose_transition ( generator=nil )
26
- @cur_pos + @step_width.choose(generator) - (@step_width / 2)
27
- end
28
-
29
- def apply_transition ( transition )
30
- @cur_pos = transition
31
- end
32
-
33
- def transition_cost ( current_cost, transition )
34
- @f[transition] - current_cost
35
- end
36
-
37
- def cost
38
- @f[@cur_pos]
39
- end
15
+ def initialize ( &fun )
16
+ @max = 100000
17
+ @min = -@max
18
+ @step_width = 500
19
+ @f = fun
20
+ @cur_pos = (@min..@max).choose
21
+ end
40
22
 
41
- def copy_of_the_current_solution
42
- @cur_pos
43
- end
23
+ def choose_transition ( generator=nil )
24
+ @cur_pos + @step_width.choose(generator) - (@step_width / 2)
25
+ end
44
26
 
45
- end # class BasicFunction
27
+ def apply_transition ( transition )
28
+ @cur_pos = transition
29
+ end
46
30
 
47
- def factory ( out, &fun )
48
- obj = BasicFunction.new(&fun)
49
- SimulatedAnnealing.new(
50
- :support => obj,
51
- :output => out,
52
- :global_threshold => 20,
53
- :step_multiplicator => 0.63,
54
- :initial_temperature => 10,
55
- :initial_cost => obj.cost,
56
- :iteration_modulus => 10,
57
- :step_modulus => 5000
58
- )
31
+ def transition_cost ( current_cost, transition )
32
+ @f[transition] - current_cost
59
33
  end
60
34
 
61
- def basic_checker ( &fun )
62
- out = StringIO.new
63
- strm, sa = nil, nil
64
- assert_nothing_raised do
65
- sa = factory(out, &fun)
66
- end
67
- assert_nothing_raised do
68
- sa.run
69
- end
70
- assert_nothing_raised do
71
- sa.summary
72
- end
73
- out.flush
74
- out.rewind
75
- assert_nothing_raised do
76
- strm = YAML::load_stream(out.read)
77
- end
78
- assert_kind_of(YAML::Stream, strm)
79
- docs = strm.documents
80
- assert_equal(2, docs.size)
81
- docs[0] = [] if docs[0].nil?
82
- assert_kind_of(Array, docs[0])
83
- assert(docs[0].all? { |x| x.is_a?(Hash) })
84
- docs[0].all? do |x|
85
- ks = x.keys.delete_if { |y| y.is_a? Integer or y =~ /\|/ }
86
- assert_equal(%w[cost prob temp thres], ks.sort)
87
- end
88
- assert_kind_of(Hash, docs[1])
35
+ def cost
36
+ @f[@cur_pos]
89
37
  end
90
38
 
91
- def test_square
92
- basic_checker { |x| x ** 2 }
39
+ def copy_of_the_current_solution
40
+ @cur_pos
93
41
  end
94
42
 
95
- def test_poly4
96
- basic_checker { |x| (x - 1) * (x - 300) * (x - 10000) * (x + 300) }
43
+ end # class BasicFunction
44
+
45
+ def factory ( out, &fun )
46
+ obj = BasicFunction.new(&fun)
47
+ Algorithms::SimulatedAnnealing.new(
48
+ :support => obj,
49
+ :output => out,
50
+ :global_threshold => 20,
51
+ :step_multiplicator => 0.63,
52
+ :initial_temperature => 10,
53
+ :initial_cost => obj.cost,
54
+ :iteration_modulus => 10,
55
+ :step_modulus => 5000
56
+ )
57
+ end
58
+
59
+ def basic_checker ( &fun )
60
+ out = StringIO.new
61
+ strm, sa = nil, nil
62
+ assert_nothing_raised do
63
+ sa = factory(out, &fun)
64
+ end
65
+ assert_nothing_raised do
66
+ sa.run
67
+ end
68
+ assert_nothing_raised do
69
+ sa.summary
97
70
  end
71
+ out.flush
72
+ out.rewind
73
+ assert_nothing_raised do
74
+ strm = YAML::load_stream(out.read)
75
+ end
76
+ assert_kind_of(YAML::Stream, strm)
77
+ docs = strm.documents
78
+ assert_equal(2, docs.size)
79
+ docs[0] = [] if docs[0].nil?
80
+ assert_kind_of(Array, docs[0])
81
+ assert(docs[0].all? { |x| x.is_a?(Hash) })
82
+ docs[0].all? do |x|
83
+ ks = x.keys.delete_if { |y| y.is_a? Integer or y =~ /\|/ }
84
+ assert_equal(%w[cost prob temp thres], ks.sort)
85
+ end
86
+ assert_kind_of(Hash, docs[1])
87
+ end
88
+
89
+ def test_square
90
+ basic_checker { |x| x ** 2 }
91
+ end
98
92
 
99
- end # class SimulatedAnnealingTest
93
+ def test_poly4
94
+ basic_checker { |x| (x - 1) * (x - 300) * (x - 10000) * (x + 300) }
95
+ end
100
96
 
101
- end # module Algorithms
97
+ end # class SimulatedAnnealingTest
data/test/unit-suite.yml CHANGED
@@ -10,6 +10,6 @@ RubyEx Unit Test Suite: !S::Iterate
10
10
  load_path: [<<pwd>>/../lib, <<pwd>>/algorithms]
11
11
  requires: <<pwd>>/../lib/ruby_ex # The full path is here to ensure we
12
12
  # load the good one.
13
- input: !path <<it_name>>
14
- uttk_unit_options: --uttk no
13
+ input: !path <<it_name>>.rb
14
+ uttk_unit_options: --uttk no --mode import
15
15
  verbose: true
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ruby_ex
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.6.1
7
- date: 2006-03-10 00:00:00 +01:00
6
+ version: 0.4.6.2
7
+ date: 2006-03-11 00:00:00 +01:00
8
8
  summary: RubyEx contains general purpose Ruby extensions.
9
9
  require_paths:
10
10
  - lib
@@ -167,7 +167,6 @@ files:
167
167
  - test/sanity/single-requires.yml
168
168
  - test/sanity/multiple-requires.yml
169
169
  - NEWS
170
- - SPEC.gemspec
171
170
  - Rakefile
172
171
  - README
173
172
  - AUTHORS
data/SPEC.gemspec DELETED
@@ -1,14 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = %q{ruby_ex}
3
- s.version = "0.4.6.1"
4
- s.date = %q{2006-03-10}
5
- s.summary = %q{RubyEx contains general purpose Ruby extensions.}
6
- s.email = ["nicolas.despres@gmail.com", "ertai@feydakins.org"]
7
- s.homepage = %q{http://api.feydakins.org/ruby_ex}
8
- s.rubyforge_project = %q{ruby_ex}
9
- s.description = %q{}
10
- s.authors = ["Nicolas Despr\350s", "Nicolas Pouillard"]
11
- s.files = ["lib/file_type.rb", "lib/config_file.rb", "lib/labeled_node.rb", "lib/diff.rb", "lib/spring_set.rb", "lib/genpasswd.rb", "lib/sendmail.rb", "lib/auto_object.rb", "lib/concrete.rb", "lib/commands.rb", "lib/generate_id.rb", "lib/ruby_ex.rb", "lib/verbose_object.rb", "lib/md5sum.rb", "lib/daemon.rb", "lib/syn_flow.rb", "lib/html_encode.rb", "lib/hooker.rb", "lib/d_logger.rb", "lib/cache.rb", "lib/diff_tools.rb", "lib/mocks.rb", "lib/choose.rb", "lib/safe_eval.rb", "lib/histogram.rb", "lib/regex_path.rb", "lib/timeout_ex.rb", "lib/text.rb", "lib/observable.rb", "lib/r_path.rb", "lib/indexed_node.rb", "lib/io_marshal.rb", "lib/ioo.rb", "lib/logger_observer.rb", "lib/abstract.rb", "lib/service_manager.rb", "lib/node.rb", "lib/meta_factory.rb", "lib/hash_eval.rb", "lib/object_monitor.rb", "lib/hookable.rb", "lib/pp_hierarchy.rb", "lib/ordered_hash.rb", "lib/spring.rb", "lib/shuffle.rb", "lib/observable_pool.rb", "lib/object_monitor_activity.rb", "lib/sym_tbl.rb", "lib/blank_slate.rb", "lib/sym_tbl_gsub.rb", "lib/attributed_class.rb", "lib/drb_ex.rb", "lib/random_generators.rb", "lib/method_call.rb", "lib/const_regexp.rb", "lib/regex_list.rb", "lib/abstract_node.rb", "lib/kill_all.rb", "lib/trace.rb", "lib/drb/undumped_attributes.rb", "lib/drb/insecure_protected_methods.rb", "lib/drb/observable.rb", "lib/drb/service.rb", "lib/drb/observable_pool.rb", "lib/drb/undumped_indexed_object.rb", "lib/uri/ftp_ex.rb", "lib/uri/pgsql.rb", "lib/uri/rsync.rb", "lib/uri/file.rb", "lib/uri/druby.rb", "lib/uri/generic_ex.rb", "lib/uri/http_ex.rb", "lib/uri/ssh.rb", "lib/uri/svn.rb", "lib/uri/mysql.rb", "lib/yaml/yregexpath.rb", "lib/yaml/chop_header.rb", "lib/yaml/transform.rb", "lib/mocks/observer.rb", "lib/mocks/assertions.rb", "lib/mocks/mock.rb", "lib/mocks/method_logger.rb", "lib/mocks/object.rb", "lib/commands/datas.rb", "lib/commands/helpers.rb", "lib/commands/seq.rb", "lib/commands/command.rb", "lib/commands/factory.rb", "lib/commands/pipe.rb", "lib/commands/runners.rb", "lib/commands/datas/data.rb", "lib/commands/datas/composite.rb", "lib/commands/datas/temp.rb", "lib/commands/datas/factory.rb", "lib/commands/datas/pipe.rb", "lib/commands/runners/popen.rb", "lib/commands/runners/system.rb", "lib/commands/runners/exec.rb", "lib/commands/runners/no_run.rb", "lib/commands/runners/fork.rb", "lib/commands/runners/mockable.rb", "lib/commands/runners/runner.rb", "lib/algorithms/simulated_annealing.rb", "lib/module/instance_method_visibility.rb", "lib/module/hierarchy.rb", "lib/module/autoload_tree.rb", "lib/random_generators/random_generator.rb", "lib/random_generators/ruby.rb", "test/unit-suite.yml", "test/check-ruby_ex.yml", "test/functional", "test/algorithms", "test/stress-tests", "test/fixtures", "test/sanity", "test/sanity-suite.yml", "test/check-pkg-ruby_ex.yml", "test/algorithms/simulated_annealing_test.rb", "test/stress-tests/threads_and_exceptions.yml", "test/fixtures/tar.gz.log", "test/fixtures/foo.tar.bz2", "test/fixtures/foo.rb.gz", "test/fixtures/my_diff.patch", "test/fixtures/foo.bz2", "test/fixtures/foo.tar", "test/fixtures/foo.txt", "test/fixtures/foo.gz.zip", "test/fixtures/foo.tar.gz", "test/fixtures/autoload_tree", "test/fixtures/autoload_tree/foo", "test/fixtures/autoload_tree/A.rb", "test/fixtures/autoload_tree/B.rb", "test/fixtures/autoload_tree/foo/C.rb", "test/sanity/single-requires.yml", "test/sanity/multiple-requires.yml", "NEWS", "SPEC.gemspec", "Rakefile", "README", "AUTHORS", "SPEC.yml", "ChangeLog"]
12
- s.add_dependency(%q<highline>, ["~> 1.0.1"])
13
- s.add_dependency(%q<core_ex>, ["~> 0.5.5"])
14
- end