core_ex 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -1,6 +1,20 @@
1
+ = New in 0.2, ...:
2
+
3
+ * Yaml:
4
+ Great improvement of the Yaml extension, new Yaml types are now
5
+ absolutly easy and clean to define.
6
+
7
+ * PathList:
8
+ PathList is based on the Rake FileList class. PathList contains
9
+ pathnames, and some interestings improvements.
10
+
11
+ * DumpableProc:
12
+ You can simply initialize a DumpableProc with a String, and keep this
13
+ String to allow the dump of that proc.
14
+
1
15
  = New in 0.1, 2005-05-31:
2
16
 
3
- CoreEx is designed to provides a simple but quite useful extension of the
17
+ CoreEx is designed to provides a simple but quite useful extension of the
4
18
  standard library of Ruby. So some classes and modules like Pathname, Time,
5
19
  Enumerable, Exception, FileUtils, String, and YAML are extended. There is
6
20
  also some new features like attr_once, DTime, TempPath, Version,
data/SPEC.dyn.yml CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:OpenStruct
2
2
  table:
3
- :date: "Sun, 05 Jun 2005"
3
+ :date: "Thu, 23 Jun 2005"
4
4
  :version: !ruby/object:Version
5
- build: 3
5
+ build: 0
6
6
  major: 0
7
- minor: 1
8
- revision: 281
9
- :version_id: ''
7
+ minor: 2
8
+ revision: 307
10
9
  :url: svn://svn.feydakins.org/ruby_ex/trunk/core_ex
10
+ :version_id: ''
data/SPEC.yml CHANGED
@@ -37,5 +37,6 @@ pkg_files: !filelist
37
37
  - test/**/*
38
38
  - '[A-Z]*'
39
39
 
40
- #dependencies:
41
- # ttk: ~> 0.2.0
40
+ autorequire: core_ex
41
+
42
+ ttk_version: ~> 0.3.0
@@ -0,0 +1,47 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: dumpable_proc.rb 299 2005-06-19 10:47:10Z ertai $
5
+
6
+ require 'core_ex'
7
+
8
+ class DumpableProc < Proc
9
+
10
+ def self.new ( str )
11
+ pr = super(&eval("proc { #{str} }"))
12
+ pr.instance_eval { @str = str.freeze }
13
+ pr
14
+ end
15
+
16
+ def _dump ( depth )
17
+ Marshal.dump([self.class, @str])
18
+ end
19
+
20
+ def self._load ( data )
21
+ klass, str = Marshal.load(data)
22
+ klass.new(str)
23
+ end
24
+
25
+ def to_s
26
+ @str
27
+ end
28
+
29
+ end
30
+
31
+ test_section __FILE__ do
32
+
33
+ class DumpableProcTest < Test::Unit::TestCase
34
+
35
+ def test_simple
36
+ p = DumpableProc.new('|x| 3 + x')
37
+ assert_equal(7, p[4])
38
+ str = nil
39
+ assert_nothing_raised { str = Marshal.dump(p) }
40
+ p2 = nil
41
+ assert_nothing_raised { p2 = Marshal.load(str) }
42
+ assert_equal(9, p2[6])
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -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: embedded_tests.rb 249 2005-05-31 13:23:42Z ertai $
4
+ # Revision:: $Id: embedded_tests.rb 298 2005-06-18 21:56:51Z ertai $
5
5
 
6
6
  require 'set'
7
7
 
@@ -31,3 +31,7 @@ module Kernel
31
31
  end
32
32
 
33
33
  end # module Kernel
34
+
35
+ if defined? EMBEDDED_TEST_MODE
36
+ test_mode EMBEDDED_TEST_MODE
37
+ end
@@ -1,5 +1,7 @@
1
- # Revision:: $Id: filelist.rb 249 2005-05-31 13:23:42Z ertai $
2
-
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: pathlist.rb 295 2005-06-18 11:22:24Z ertai $
3
5
  #--
4
6
  # Copyright (c) 2003, 2004 Jim Weirich
5
7
  #
@@ -24,26 +26,26 @@
24
26
  #++
25
27
  #
26
28
 
27
- # Contributons by Nicolas Pouillard <ertai@lrde.epita.fr>.
28
-
29
29
  # Some objects are dupable, some are not. So we define a version of
30
30
  # dup (called rake_dup) that returns self on the handful of classes
31
31
  # that are not dupable.
32
32
 
33
- module Kernel
34
- # Duplicate an object if it can be duplicated. If it can not be
35
- # cloned or duplicated, then just return the original object.
36
- def rake_dup()
37
- dup
38
- end
39
- end
40
-
41
- [NilClass, FalseClass, TrueClass, Fixnum, Symbol].each do |clazz|
42
- clazz.class_eval {
33
+ unless respond_to? :rake_dup
34
+ module Kernel
43
35
  # Duplicate an object if it can be duplicated. If it can not be
44
36
  # cloned or duplicated, then just return the original object.
45
- def rake_dup() self end
46
- }
37
+ def rake_dup()
38
+ dup
39
+ end
40
+ end
41
+
42
+ [NilClass, FalseClass, TrueClass, Fixnum, Symbol].each do |clazz|
43
+ clazz.class_eval {
44
+ # Duplicate an object if it can be duplicated. If it can not be
45
+ # cloned or duplicated, then just return the original object.
46
+ def rake_dup() self end
47
+ }
48
+ end
47
49
  end
48
50
 
49
51
  ######################################################################
@@ -67,23 +69,26 @@ class String
67
69
  end
68
70
  end
69
71
 
72
+ #
73
+ # PathList is essentially based on FileList from Rake.
74
+ #
70
75
 
71
76
  ####################################################################
72
- # A FileList is essentially an array with a few helper methods
77
+ # A PathList is essentially an array with a few helper methods
73
78
  # defined to make file manipulation a bit easier.
74
79
  #
75
- # FileLists are lazy. When given a list of glob patterns for
80
+ # PathLists are lazy. When given a list of glob patterns for
76
81
  # possible files to be included in the file list, instead of
77
- # searching the file structures to find the files, a FileList holds
82
+ # searching the file structures to find the files, a PathList holds
78
83
  # the pattern for latter use.
79
84
  #
80
- # This allows us to define a number of FileList to match any number of
81
- # files, but only search out the actual files when then FileList
85
+ # This allows us to define a number of PathList to match any number of
86
+ # files, but only search out the actual files when then PathList
82
87
  # itself is actually used. The key is that the first time an
83
- # element of the FileList/Array is requested, the pending patterns
88
+ # element of the PathList/Array is requested, the pending patterns
84
89
  # are resolved into a real list of file names.
85
90
  #
86
- class FileList
91
+ class PathList
87
92
 
88
93
  def clone
89
94
  sibling = self.class.new
@@ -97,7 +102,7 @@ class FileList
97
102
 
98
103
  # == Method Delegation
99
104
  #
100
- # The lazy evaluation magic of FileLists happens by implementing
105
+ # The lazy evaluation magic of PathLists happens by implementing
101
106
  # all the array specific methods to call +resolve+ before
102
107
  # delegating the heavy lifting to an embedded array object
103
108
  # (@items).
@@ -106,11 +111,11 @@ class FileList
106
111
  # regular kind delegates to the @items array and returns the
107
112
  # result directly. Well, almost directly. It checks if the
108
113
  # returned value is the @items object itself, and if so will
109
- # return the FileList object instead.
114
+ # return the PathList object instead.
110
115
  #
111
116
  # The second kind of delegation call is used in methods that
112
117
  # normally return a new Array object. We want to capture the
113
- # return value of these methods and wrap them in a new FileList
118
+ # return value of these methods and wrap them in a new PathList
114
119
  # object. We enumerate these methods in the +SPECIAL_RETURN+ list
115
120
  # below.
116
121
 
@@ -143,7 +148,7 @@ class FileList
143
148
  def #{sym}(*args, &block)
144
149
  resolve if @pending
145
150
  result = @items.send(:#{sym}, *args, &block)
146
- FileList.new.import(result)
151
+ PathList.new.import(result)
147
152
  end
148
153
  }, __FILE__, ln
149
154
  else
@@ -163,9 +168,9 @@ class FileList
163
168
  # time, use the "yield self" pattern.
164
169
  #
165
170
  # Example:
166
- # file_list = FileList.new['lib/**/*.rb', 'test/test*.rb']
171
+ # file_list = PathList.new['lib/**/*.rb', 'test/test*.rb']
167
172
  #
168
- # pkg_files = FileList.new['lib/**/*'] do |fl|
173
+ # pkg_files = PathList.new['lib/**/*'] do |fl|
169
174
  # fl.exclude(/\bCVS\b/)
170
175
  # end
171
176
  #
@@ -210,14 +215,14 @@ class FileList
210
215
  # will not exclude the file.
211
216
  #
212
217
  # Examples:
213
- # FileList['a.c', 'b.c'].exclude("a.c") => ['b.c']
214
- # FileList['a.c', 'b.c'].exclude(/^a/) => ['b.c']
218
+ # PathList['a.c', 'b.c'].exclude("a.c") => ['b.c']
219
+ # PathList['a.c', 'b.c'].exclude(/^a/) => ['b.c']
215
220
  #
216
221
  # If "a.c" is a file, then ...
217
- # FileList['a.c', 'b.c'].exclude("a.*") => ['b.c']
222
+ # PathList['a.c', 'b.c'].exclude("a.*") => ['b.c']
218
223
  #
219
224
  # If "a.c" is not a file, then ...
220
- # FileList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c']
225
+ # PathList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c']
221
226
  #
222
227
  def exclude(*patterns)
223
228
  patterns.each do |pat| @exclude_patterns << pat end
@@ -259,7 +264,7 @@ class FileList
259
264
  result = @items * other
260
265
  case result
261
266
  when Array
262
- FileList.new.import(result)
267
+ PathList.new.import(result)
263
268
  else
264
269
  result
265
270
  end
@@ -330,36 +335,36 @@ class FileList
330
335
  self
331
336
  end
332
337
 
333
- # Return a new FileList with the results of running +sub+ against
338
+ # Return a new PathList with the results of running +sub+ against
334
339
  # each element of the oringal list.
335
340
  #
336
341
  # Example:
337
- # FileList['a.c', 'b.c'].sub(/\.c$/, '.o') => ['a.o', 'b.o']
342
+ # PathList['a.c', 'b.c'].sub(/\.c$/, '.o') => ['a.o', 'b.o']
338
343
  #
339
- def sub(pat, rep)
340
- inject(FileList.new) { |res, fn| res << fn.sub(pat,rep) }
344
+ def sub(*args, &block)
345
+ inject(PathList.new) { |res, fn| res << fn.sub(*args, &block) }
341
346
  end
342
347
 
343
- # Return a new FileList with the results of running +gsub+ against
348
+ # Return a new PathList with the results of running +gsub+ against
344
349
  # each element of the original list.
345
350
  #
346
351
  # Example:
347
- # FileList['lib/test/file', 'x/y'].gsub(/\//, "\\")
352
+ # PathList['lib/test/file', 'x/y'].gsub(/\//, "\\")
348
353
  # => ['lib\\test\\file', 'x\\y']
349
354
  #
350
- def gsub(pat, rep)
351
- inject(FileList.new) { |res, fn| res << fn.gsub(pat,rep) }
355
+ def gsub(*args, &block)
356
+ inject(PathList.new) { |res, fn| res << fn.gsub(*args, &block) }
352
357
  end
353
358
 
354
359
  # Same as +sub+ except that the oringal file list is modified.
355
- def sub!(pat, rep)
356
- each_with_index { |fn, i| self[i] = fn.sub(pat,rep) }
360
+ def sub!(*args, &block)
361
+ each_with_index { |fn, i| self[i] = fn.sub(*args, &block) }
357
362
  self
358
363
  end
359
364
 
360
365
  # Same as +gsub+ except that the original file list is modified.
361
- def gsub!(pat, rep)
362
- each_with_index { |fn, i| self[i] = fn.gsub(pat,rep) }
366
+ def gsub!(*args, &block)
367
+ each_with_index { |fn, i| self[i] = fn.gsub(*args, &block) }
363
368
  self
364
369
  end
365
370
 
@@ -376,23 +381,28 @@ class FileList
376
381
  end
377
382
 
378
383
 
379
- # FileList version of partition. Needed because the nested arrays
380
- # should be FileLists in this version.
384
+ # PathList version of partition. Needed because the nested arrays
385
+ # should be PathLists in this version.
381
386
  def partition(&block) # :nodoc:
382
387
  resolve
383
388
  result = @items.partition(&block)
384
389
  [
385
- FileList.new.import(result[0]),
386
- FileList.new.import(result[1]),
390
+ PathList.new.import(result[0]),
391
+ PathList.new.import(result[1]),
387
392
  ]
388
393
  end
389
394
 
390
- # Convert a FileList to a string by joining all elements with a space.
395
+ # Convert a PathList to a string by joining all elements with a space.
391
396
  def to_s
392
397
  resolve if @pending
393
398
  self.join(' ')
394
399
  end
395
400
 
401
+ def to_yaml ( opts={} )
402
+ resolve if @pending
403
+ to_a.to_yaml(opts)
404
+ end
405
+
396
406
  # Add matching glob patterns.
397
407
  def add_matching(pattern)
398
408
  # <<<<
@@ -401,7 +411,9 @@ class FileList
401
411
  self << fn unless exclude?(fn)
402
412
  end
403
413
  end
404
- private :add_matching
414
+ # <<<<
415
+ protected :add_matching
416
+ # >>>>
405
417
 
406
418
  # Should the given file name be excluded?
407
419
  def exclude?(fn)
@@ -429,7 +441,7 @@ class FileList
429
441
  class << self
430
442
  # Create a new file list including the files listed. Similar to:
431
443
  #
432
- # FileList.new(*args)
444
+ # PathList.new(*args)
433
445
  def [](*args)
434
446
  new(*args)
435
447
  end
@@ -459,6 +471,9 @@ class FileList
459
471
  def require
460
472
  each { |x| x.require }
461
473
  end
474
+
475
+ def to_strings
476
+ map { |path| path.to_s }
477
+ end
462
478
  # >>>>
463
479
  end
464
-
@@ -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: rakefile_base.rf 280 2005-06-05 20:52:26Z ertai $
4
+ # Revision:: $Id: rakefile_base.rf 301 2005-06-23 20:57:05Z ertai $
5
5
 
6
6
  require 'core_ex'
7
7
  require 'ostruct'
@@ -73,10 +73,17 @@ task :default => [ :check ]
73
73
 
74
74
 
75
75
  # desc 'Setup the ttk command'
76
- task :ttk do
77
- # FIXME search a valid ttk
78
- def ttk ( *a )
79
- sh 'ttk', *a
76
+ task :ttk => [ :spec ] do
77
+ alias highline_ask ask
78
+ require_gem 'ttk', SPEC.ttk_version
79
+ alias ruby_ex_ask ask
80
+ alias ask highline_ask
81
+ def ttk ( *a, &b )
82
+ cmd = TTK.bin[*a]
83
+ cmd.input = b[] if b
84
+ cmd.output = STDOUT
85
+ cmd.error = STDERR
86
+ raise unless cmd.system.status == 0
80
87
  end
81
88
  end
82
89
 
@@ -98,22 +105,19 @@ task :distcheck => [ :ttk, :package ] do
98
105
  urls = []
99
106
  Pathname.glob('pkg/*') do |path|
100
107
  next unless path.file?
101
- next if path.to_s =~ /\.gem$/ # FIXME
102
108
  urls << "file://#{path.expand_path}"
103
109
  end
104
- inp = { # FIXME use a Each strategy
105
- 'Check generated packages' => {
106
- 'strategy' => 'Suite',
107
- 'attributes' => {
108
- 'strategy' => 'Import',
109
- 'import' => SPEC.root_test_suite
110
- },
111
- 'contents' => urls.map { |url| { url => { 'symbols' => {'url'=>url} } } }
112
- }
113
- }
114
- TempPath.new do |tmp|
115
- tmp.open('w') { |f| f.write inp.to_yaml }
116
- ttk '-l', 'distcheck-log.yml', tmp
110
+ ttk '-l', 'distcheck-log.yml' do %Q[
111
+ Check generated packages:
112
+ strategy: Iterate
113
+ over : #{urls.inspect}
114
+ iter : url
115
+ test :
116
+ 'Check the package: <<url>>':
117
+ strategy: Import
118
+ symbols : { url: <<url>> }
119
+ import : #{SPEC.root_test_suite}
120
+ ]
117
121
  end
118
122
  end
119
123
  clean_task :distcheck do
@@ -203,7 +207,7 @@ task :rdoc_spec => [ :spec ] do
203
207
  rdoc.main = SPEC.rdoc_files.first
204
208
  tail = SPEC.rdoc_tail_files || []
205
209
  fl = SPEC.rdoc_files - tail + tail
206
- rdoc.rdoc_files.include(fl)
210
+ rdoc.rdoc_files.include(fl.to_strings)
207
211
  end
208
212
  end
209
213
 
@@ -222,8 +226,9 @@ file GEM_SPEC.to_s => [ :spec, :dyn_spec, :rdoc_spec ] do
222
226
  s.executables = Pathname.glob(bin + '*').select do |path|
223
227
  path.executable? and not path.directory?
224
228
  end.map { |path| path.basename.to_s }
225
- s.files = SPEC.pkg_files.to_a
229
+ s.files = SPEC.pkg_files.to_strings
226
230
  s.require_path = 'lib'
231
+ s.autorequire = SPEC.autorequire if SPEC.autorequire
227
232
 
228
233
  if SPEC.dependencies
229
234
  SPEC.dependencies.each do |name, version|
@@ -231,9 +236,11 @@ file GEM_SPEC.to_s => [ :spec, :dyn_spec, :rdoc_spec ] do
231
236
  end
232
237
  end
233
238
 
234
- s.has_rdoc = true
235
- s.extra_rdoc_files = SPEC.rdoc.rdoc_files.to_a
236
- s.rdoc_options = SPEC.rdoc.option_list.map { |x| x[/^'?(.*?)'?$/, 1] }
239
+ if SPEC.has_rdoc
240
+ s.has_rdoc = true
241
+ s.extra_rdoc_files = SPEC.rdoc.rdoc_files.map { |x| x.to_s }
242
+ s.rdoc_options = SPEC.rdoc.option_list.map { |x| x[/^'?(.*?)'?$/, 1] }
243
+ end
237
244
 
238
245
  authors_file = YAML::load(AUTHORS.read).values.first
239
246
  list = authors_file.map { |x| /^(.*?)\s*<(.*)>/.match(x.keys.first)[1..2] }
@@ -263,7 +270,7 @@ task :gem_spec => [ GEM_SPEC.to_s ] do
263
270
  p.gem_spec = spec
264
271
  p.need_tar_gz = true
265
272
  p.need_tar_bz2 = true
266
- p.package_files = SPEC.pkg_files.to_a
273
+ p.package_files = SPEC.pkg_files.map { |x| x.to_s }
267
274
  end
268
275
  gtask.instance_eval { $gem = 'pkg'.to_path + gem_file }
269
276
  end
@@ -411,7 +418,7 @@ task :publish_package => [ :spec, :package ] do
411
418
  type_map.default = 9999
412
419
 
413
420
  pkg = 'pkg'.to_path
414
- files = FileList[pkg/"*{#{type_map.keys.join(',')}}"]
421
+ files = PathList[pkg/"*{#{type_map.keys.join(',')}}"]
415
422
 
416
423
  rubyforge_user = SPEC.rubyforge_user || SPEC.user || ENV['USER']
417
424
  rubyforge_project = SPEC.rubyforge_project || SPEC.name
@@ -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: require.rb 278 2005-06-05 16:30:48Z ertai $
4
+ # Revision:: $Id: require.rb 297 2005-06-18 21:51:39Z ertai $
5
5
 
6
6
  require 'core_ex/pathname'
7
7
  require 'set'
@@ -55,9 +55,20 @@ class RequireSystem
55
55
  private :cannot_found
56
56
 
57
57
 
58
+ def add_to_required ( aString )
59
+ return if $".include? aString
60
+ $" << aString
61
+ end
62
+
63
+
64
+ def required_include? ( aString )
65
+ $".include? aString
66
+ end
67
+
68
+
58
69
  def load ( aPathname )
59
70
  check_pathname(aPathname)
60
- abs = aPathname.expand_path_with($:, EXTENSIONS)
71
+ abs = aPathname.expand_path_with($:, EXTENSIONS + [aPathname.extname])
61
72
  cannot_found(aPathname) if abs.nil?
62
73
  @loaded << abs
63
74
  Kernel.__load__(abs)
@@ -146,17 +157,18 @@ class RequireSystem
146
157
  cannot_found(aPathname) if abs.nil?
147
158
  feature = aPathname.to_s
148
159
  feature += abs.extname if aPathname.extname.empty?
149
- if $".include? feature or $".include? abs.to_s
160
+ if required_include? feature or required_include? abs.to_s
150
161
  return false
151
162
  else
152
163
  if abs.extname =~ /^(\.rb)?$/
153
- $" << feature
164
+ add_to_required feature
165
+ add_to_required abs.to_s
154
166
  res = Kernel.__load__(abs)
155
167
  else
156
168
  res = Kernel.__require__(abs.extsplit.first.to_s)
157
- $" << feature unless $".include? feature
169
+ add_to_required feature
170
+ add_to_required abs.to_s
158
171
  end
159
- $" << abs.to_s
160
172
  return true
161
173
  end
162
174
  end
@@ -186,7 +198,7 @@ class RequireSystem
186
198
  cannot_found(aPathname) if abs.nil?
187
199
  feature = aPathname.to_s
188
200
  feature += abs.extname if aPathname.extname.empty?
189
- return $".include?(feature) || $".include?(abs)
201
+ return required_include?(feature)
190
202
  end
191
203
 
192
204
 
@@ -280,13 +292,16 @@ test_section __FILE__ do
280
292
  @p_so = @s_so.to_path
281
293
  @p_rb = @s_rb.to_path
282
294
  @ls = [ @s, @s_dne, @s_so, @s_rb ]
283
- @lp = [ @p, @p_dne, @p_so, @p_rb ]
295
+ @lp = [ @p, @p_dne, @p_rb ] # FIXME @p_so on mac
284
296
  @l = @ls + @lp
285
297
  $:.replace @@save_dirs.dup
286
- $".replace @@save_files.dup
287
298
  @mr = MockRequirable
288
299
  end
289
300
 
301
+ def teardown
302
+ $".delete_if { |x| x =~ /test_require/ }
303
+ end
304
+
290
305
  def test_0_initialize
291
306
  %w[
292
307
  load require
@@ -310,11 +325,6 @@ test_section __FILE__ do
310
325
  end
311
326
 
312
327
  def test_1_search
313
- @ls.each do |x|
314
- assert_raise(LoadError) do
315
- x.expand_path_with($:, RequireSystem::EXTENSIONS)
316
- end
317
- end
318
328
  @lp.each { |x| assert_search(x, nil) }
319
329
  end
320
330
 
@@ -375,4 +385,3 @@ test_section __FILE__ do
375
385
 
376
386
  end # RequireSystemTest
377
387
  end
378
-
@@ -2,8 +2,8 @@
2
2
  # Author: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License: Gnu General Public License.
4
4
 
5
- # $LastChangedBy: ertai $
6
- # $Id: temp_path.rb 283 2005-06-05 23:02:30Z ertai $
5
+ # $LastChangedBy: polrop $
6
+ # $Id: temp_path.rb 287 2005-06-10 13:25:50Z polrop $
7
7
 
8
8
  require 'core_ex'
9
9
  require 'tempfile'
@@ -30,10 +30,10 @@ class TempPath < Pathname
30
30
  # tmp.clean
31
31
  #
32
32
  # - # You can choose the basename and an extension.
33
- # TmpPath.new('the_base_file_name', 'rb')
33
+ # TempPath.new('the_base_file_name', 'rb')
34
34
  #
35
35
  # - # You can supply a block (recomended).
36
- # TmpPath.new('foo') do |tmp|
36
+ # TempPath.new('foo') do |tmp|
37
37
  # tmp.open('w') { |f| << 'foo' }
38
38
  # tmp.exist? == true
39
39
  # $tmp = tmp
@@ -41,7 +41,7 @@ class TempPath < Pathname
41
41
  # $tmp.exist? == false
42
42
  #
43
43
  # - # You can make a temporary directory.
44
- # TmpPath.new('adirectory') do |tmpdir|
44
+ # TempPath.new('adirectory') do |tmpdir|
45
45
  # tmpdir.mkpath
46
46
  # $file = tmpdir + 'foo'
47
47
  # $file.open('w') { |f| f << 'foo' }
@@ -126,7 +126,7 @@ class TempPath < Pathname
126
126
  block[] if block_given?
127
127
  ensure
128
128
  if @@tmpdir.exist?
129
- @@tmpdir.rmtree
129
+ @@tmpdir.rmtree
130
130
  @@initialized = false
131
131
  end
132
132
  end
@@ -2,8 +2,8 @@
2
2
  # Author: Nicolas Despres <polrop@lrde.epita.fr>.
3
3
  # License: Gnu General Public License.
4
4
 
5
- # $LastChangedBy: ertai $
6
- # $Id: version.rb 252 2005-05-31 23:41:42Z ertai $
5
+ # $LastChangedBy: polrop $
6
+ # $Id: version.rb 290 2005-06-11 06:48:17Z polrop $
7
7
 
8
8
  require 'core_ex'
9
9
 
@@ -20,7 +20,19 @@ class Version
20
20
  end
21
21
 
22
22
  def <=>(other)
23
- to_a <=> other.to_a
23
+ if @major == other.major
24
+ if @minor == other.minor
25
+ if @build == other.build
26
+ @revision <=> other.revision
27
+ else
28
+ @build <=> other.build
29
+ end
30
+ else
31
+ @minor <=> other.minor
32
+ end
33
+ else
34
+ @major <=> other.major
35
+ end
24
36
  end
25
37
 
26
38
  def pp
@@ -31,6 +43,10 @@ class Version
31
43
  "#@major.#@minor.#@build"
32
44
  end
33
45
 
46
+ def inspect
47
+ "#@major.#@minor.#@build-r#@revision"
48
+ end
49
+
34
50
  def to_a
35
51
  [ @major, @minor, @build, @revision ]
36
52
  end
data/lib/core_ex/yaml.rb CHANGED
@@ -1,24 +1,216 @@
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: yaml.rb 249 2005-05-31 13:23:42Z ertai $
4
+ # Revision:: $Id: yaml.rb 300 2005-06-23 20:45:47Z ertai $
5
5
 
6
6
  require 'yaml'
7
+ require 'core_ex'
8
+
9
+
10
+ class Class
11
+
12
+ def yaml_extension ( theYamlType=nil )
13
+ case theYamlType
14
+ when NilClass
15
+ theYamlType = "!#{self.name.downcase}"
16
+ when String
17
+ theYamlType = theYamlType
18
+ when Symbol
19
+ theYamlType = "!#{theYamlType}"
20
+ else
21
+ raise ArgumentError, "Expect a symbol or a string not: #{theYamlType}"
22
+ end
23
+
24
+ class_eval do
25
+ undef to_yaml_type
26
+ undef to_yaml
27
+ def to_yaml ( opts={} )
28
+ YAML::quick_emit(self.object_id, opts) do |out|
29
+ out << "#{to_yaml_type} #{to_yaml_string}"
30
+ end
31
+ end
32
+ end
33
+
34
+ class_eval %{
35
+ def to_yaml_type
36
+ '#{theYamlType}'
37
+ end
38
+ }
39
+
40
+ theClass = self
41
+ YAML.add_builtin_type(theYamlType) do |type, val|
42
+ theClass.yaml_load val
43
+ end
44
+ end
45
+
46
+ end # class Class
47
+
48
+
49
+
50
+ class Regexp
51
+ yaml_extension :re
52
+
53
+ def to_yaml_string
54
+ source
55
+ end
56
+
57
+ @@options =
58
+ {
59
+ 'm' => MULTILINE,
60
+ 'i' => IGNORECASE,
61
+ 'x' => EXTENDED
62
+ }
63
+
64
+ def self.yaml_load ( val )
65
+ if val.is_a? Array and val.size == 2
66
+ options = 0
67
+ val.last.split(//).each do |opt|
68
+ options |= @@options[opt]
69
+ end
70
+ new(val.first, options)
71
+ else
72
+ new(val.to_s)
73
+ end
74
+ end
75
+
76
+ end # class Regexp
77
+
78
+
79
+
80
+ class Range
81
+ yaml_extension
82
+
83
+ def to_yaml_string
84
+ to_s
85
+ end
86
+
87
+ def self.yaml_load ( val )
88
+ range = eval(val.to_s)
89
+ raise ArgumentError, "need a range not #{val}" unless range.is_a? Range
90
+ range
91
+ end
92
+
93
+ end # class Range
94
+
95
+
96
+
97
+ class Proc
98
+ yaml_extension
99
+
100
+ def self.yaml_load ( val )
101
+ DumpableProc.new(val.to_s)
102
+ end
103
+
104
+ def to_yaml_string
105
+ to_s
106
+ end
107
+
108
+ end # class Proc
7
109
 
8
- YAML.add_builtin_type('!re') do |type, val|
9
- Regexp.new(val.to_s)
10
- end
11
110
 
12
- YAML.add_builtin_type('!path') do |type, val|
13
- Pathname.new(val.to_s)
14
- end
15
111
 
16
- YAML.add_builtin_type('!proc') do |type, val|
17
- require 'dumpable_proc'
18
- DumpableProc.new(val.to_s)
112
+ class PathList
113
+ yaml_extension :filelist
114
+
115
+ def self.yaml_load ( val )
116
+ new(val)
117
+ end
118
+
119
+ undef to_yaml
120
+ def to_yaml ( opts={} )
121
+ to_a.to_yaml(opts)
122
+ end
123
+
124
+ end # class PathList
125
+
126
+
127
+ class Pathname
128
+ yaml_extension :path
129
+
130
+ def to_yaml_string
131
+ to_s
132
+ end
133
+
134
+ def self.yaml_load ( val )
135
+ new(val.to_s)
136
+ end
137
+
138
+ end # class Pathname
139
+
140
+
141
+
142
+ YAML.add_builtin_type('!ruby') do |type, val|
143
+ eval val.to_s
19
144
  end
20
145
 
21
- YAML.add_builtin_type('!filelist') do |type, val|
22
- require 'rake'
23
- FileList.new(val)
146
+
147
+
148
+ test_section __FILE__ do
149
+
150
+ class YamlExTest < Test::Unit::TestCase
151
+
152
+ def assert_yaml_load ( aString, aClass, anObject=nil )
153
+ assert_nothing_raised { @val = YAML::load(aString) }
154
+ assert_kind_of(aClass, @val)
155
+ assert_equal(anObject, @val) unless anObject.nil?
156
+ @ref = aString
157
+ end
158
+
159
+ def assert_yaml_dump ( anObject, aString )
160
+ assert_nothing_raised { @str = anObject.to_yaml }
161
+ assert_equal(aString, @str)
162
+ end
163
+
164
+
165
+
166
+ def test_regexp
167
+ @re = /a.*[bc]$/
168
+ assert_yaml_load '--- !re a.*[bc]$', Regexp, @re
169
+ assert_match(@val, 'afffc')
170
+ assert_no_match(@val, 'afffC')
171
+ assert_no_match(@val, 'fffb')
172
+ assert_no_match(@val, "af\nffb")
173
+ assert_yaml_dump @re, @ref
174
+ @re = /a.*[bc]$/mi
175
+ assert_yaml_load '--- !re ["a.*[bc]$", mi]', Regexp, @re
176
+ assert_match(@val, 'afffc')
177
+ assert_match(@val, 'afffC')
178
+ assert_no_match(@val, 'fffb')
179
+ assert_match(@val, "af\nffb")
180
+ end
181
+
182
+ def test_pathname
183
+ str = 'foo/bar/baz.rb'
184
+ assert_yaml_load "--- !path #{str}", Pathname, str.to_path
185
+ assert_equal('baz.rb', @val.basename.to_s)
186
+ assert_equal(str, @val.to_s)
187
+ assert_yaml_dump str.to_path, @ref
188
+ end
189
+
190
+ def test_range
191
+ assert_yaml_load "--- !range 0..10", Range, 0..10
192
+ assert_yaml_dump @val, @ref
193
+ assert_yaml_load "--- !range 0...10", Range, 0...10
194
+ assert_yaml_dump @val, @ref
195
+ end
196
+
197
+ def test_proc
198
+ assert_yaml_load "--- !proc 3 + 7", Proc
199
+ assert_yaml_dump @val, @ref
200
+ assert_equal(10, @val[])
201
+ end
202
+
203
+ def test_pathlist
204
+ ls = __FILE__.to_path.dirname + '*.rb'
205
+ assert_yaml_load "--- !filelist #{ls}", PathList, PathList[ls]
206
+ assert_yaml_dump @val, @val.to_a.to_yaml
207
+ end
208
+
209
+ def test_ruby
210
+ assert_yaml_load "--- !ruby 2 + 4", Integer, 6
211
+ assert_yaml_load "--- !ruby '[2, 4]'", Array, [2, 4]
212
+ end
213
+
214
+ end # class YamlExTest
215
+
24
216
  end
data/lib/core_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: core_ex.rb 278 2005-06-05 16:30:48Z ertai $
4
+ # Revision:: $Id: core_ex.rb 301 2005-06-23 20:57:05Z ertai $
5
5
 
6
6
  require 'pathname'
7
7
 
@@ -16,17 +16,18 @@ module CoreEx
16
16
  require "core_ex/#{aPath}"
17
17
  end
18
18
  RequireSystem.instance
19
- %w[ attr_once enumerable exception string fileutils yaml ].each do |aPath|
19
+ %w[ attr_once enumerable exception
20
+ string fileutils pathlist yaml ].each do |aPath|
20
21
  (@@core_ex + aPath).require
21
22
  end
22
23
 
23
24
  def self.each ( &block )
24
- @@core_list ||= FileList[@@core_ex + '**/*.rb']
25
+ @@core_list ||= PathList[@@core_ex + '**/*.rb']
25
26
  @@core_list.each(&block)
26
27
  end
27
28
 
28
29
  def self.require
29
- @@core_list ||= FileList[@@core_ex + '**/*.rb']
30
+ @@core_list ||= PathList[@@core_ex + '**/*.rb']
30
31
  @@core_list.require
31
32
  end
32
33
 
@@ -40,8 +41,8 @@ core_ex = CoreEx.dir + 'core_ex'
40
41
  {
41
42
  :Time => 'time',
42
43
  :DTime => 'dtime',
44
+ :DumpableProc => 'dumpable_proc',
43
45
  :Version => 'version',
44
- :FileList => 'filelist',
45
46
  :Test => 'test/unit/ui/yaml/testrunner',
46
47
  :TempPath => 'temp_path'
47
48
  }.each do |k, v|
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ raise 'Do not load CoreEx before me' if defined? CoreEx
2
3
  require 'pathname'
3
- unless defined? CoreEx
4
- $: << Pathname.new(__FILE__).dirname.parent + 'lib'
5
- require 'core_ex'
6
- else
7
- require 'core_ex/embedded_tests'
8
- end
4
+ $VERBOSE = true
5
+ $: << Pathname.new(__FILE__).dirname.parent + 'lib'
9
6
  args = ARGV.inject(nil) { |accu, x| (accu)? accu << x : ((x == '--')? [] : accu) } || ARGV
10
7
  path = Pathname.new(args[0]).expand_path.cleanpath
11
- test_mode Regexp.new(path)
8
+ EMBEDDED_TEST_MODE = Regexp.new(path)
9
+ require 'core_ex'
10
+ require 'core_ex/test/unit/ui/yaml/testrunner'
12
11
  require path.to_s
data/test/unit-suite.yml CHANGED
@@ -5,12 +5,10 @@ CoreEx Unit Test Suite:
5
5
  strategy: Glob
6
6
  glob : <<pwd>>/../lib/**/*.rb
7
7
  regexp : !re ([^/]*)\.rb$
8
- symbols : { core_ex: <<pwd>>/../lib }
9
8
 
10
9
  test:
11
10
  <<match>>:
12
11
  strategy: RUnit
13
- unit_file: <<pwd>>/test-unit-setup.rb
12
+ input: !path <<pwd>>/test-unit-setup.rb
14
13
  args: <<path>>
15
14
  verbose: true
16
- core_ex: true
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: core_ex
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2005-06-06
6
+ version: 0.2.0
7
+ date: 2005-06-24
8
8
  summary: CoreEx is a proposal for a standard library extension.
9
9
  require_paths:
10
10
  - lib
@@ -19,10 +19,10 @@ description: "CoreEx is designed to provides a simple but quite useful extens
19
19
  also some new features like attr_once, DTime, TempPath, Version,
20
20
  embedded_tests, filelist (almost from rake), a common Rakefile, and an
21
21
  extension of the require system."
22
- autorequire:
22
+ autorequire: core_ex
23
23
  default_executable:
24
24
  bindir: bin
25
- has_rdoc: true
25
+ has_rdoc: false
26
26
  required_ruby_version: !ruby/object:Gem::Version::Requirement
27
27
  requirements:
28
28
  -
@@ -38,11 +38,12 @@ files:
38
38
  - lib/core_ex.rb
39
39
  - lib/core_ex/attr_once.rb
40
40
  - lib/core_ex/dtime.rb
41
+ - lib/core_ex/dumpable_proc.rb
41
42
  - lib/core_ex/embedded_tests.rb
42
43
  - lib/core_ex/enumerable.rb
43
44
  - lib/core_ex/exception.rb
44
- - lib/core_ex/filelist.rb
45
45
  - lib/core_ex/fileutils.rb
46
+ - lib/core_ex/pathlist.rb
46
47
  - lib/core_ex/pathname.rb
47
48
  - lib/core_ex/rakefile_base.rf
48
49
  - lib/core_ex/require.rb
@@ -73,37 +74,10 @@ files:
73
74
  - Rakefile
74
75
  - README
75
76
  - SPEC.dyn.yml
76
- - SPEC.gemspec
77
77
  - SPEC.yml
78
78
  test_files: []
79
- rdoc_options:
80
- - "--inline-source"
81
- - "--main"
82
- - README
83
- - "--title"
84
- - "CoreEx -- A proposal for a standard library extension."
85
- - "-T"
86
- - html
87
- extra_rdoc_files:
88
- - README
89
- - AUTHORS
90
- - NEWS
91
- - lib/core_ex.rb
92
- - lib/core_ex/attr_once.rb
93
- - lib/core_ex/dtime.rb
94
- - lib/core_ex/embedded_tests.rb
95
- - lib/core_ex/enumerable.rb
96
- - lib/core_ex/exception.rb
97
- - lib/core_ex/filelist.rb
98
- - lib/core_ex/fileutils.rb
99
- - lib/core_ex/pathname.rb
100
- - lib/core_ex/require.rb
101
- - lib/core_ex/string.rb
102
- - lib/core_ex/temp_path.rb
103
- - lib/core_ex/time.rb
104
- - lib/core_ex/version.rb
105
- - lib/core_ex/yaml.rb
106
- - lib/core_ex/test/unit/ui/yaml/testrunner.rb
79
+ rdoc_options: []
80
+ extra_rdoc_files: []
107
81
  executables: []
108
82
  extensions: []
109
83
  requirements: []
data/SPEC.gemspec DELETED
@@ -1,15 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = %q{core_ex}
3
- s.version = "0.1.3"
4
- s.date = %q{2005-06-06}
5
- s.summary = %q{CoreEx is a proposal for a standard library extension.}
6
- s.email = ["nicolas.despres@gmail.com", "ertai@feydakins.org"]
7
- s.homepage = %q{http://api.feydakins.org/core_ex}
8
- s.rubyforge_project = %q{core_ex}
9
- s.description = %q{CoreEx is designed to provides a simple but quite useful extension of the standard library of Ruby. So some classes and modules like Pathname, Time, Enumerable, Exception, FileUtils, String, and YAML are extended. There is also some new features like attr_once, DTime, TempPath, Version, embedded_tests, filelist (almost from rake), a common Rakefile, and an extension of the require system.}
10
- s.has_rdoc = true
11
- s.authors = ["Nicolas Despr\350s", "Nicolas Pouillard"]
12
- s.files = ["lib/core_ex.rb", "lib/core_ex/attr_once.rb", "lib/core_ex/dtime.rb", "lib/core_ex/embedded_tests.rb", "lib/core_ex/enumerable.rb", "lib/core_ex/exception.rb", "lib/core_ex/filelist.rb", "lib/core_ex/fileutils.rb", "lib/core_ex/pathname.rb", "lib/core_ex/rakefile_base.rf", "lib/core_ex/require.rb", "lib/core_ex/string.rb", "lib/core_ex/temp_path.rb", "lib/core_ex/time.rb", "lib/core_ex/version.rb", "lib/core_ex/yaml.rb", "lib/core_ex/test/unit/ui/yaml/testrunner.rb", "test/check-core_ex.yml", "test/check-pkg-core_ex.yml", "test/resources", "test/sanity", "test/sanity-suite.yml", "test/test-unit-setup.rb", "test/unit-suite.yml", "test/resources/require", "test/resources/use-from-gems.rb", "test/resources/yaml_testrunner", "test/resources/require/test_require", "test/resources/require/test_require_rb.rb", "test/resources/require/test_require_so.so", "test/resources/yaml_testrunner/unit_test.rb", "test/sanity/multiple-requires.yml", "test/sanity/single-requires.yml", "AUTHORS", "NEWS", "Rakefile", "README", "SPEC.dyn.yml", "SPEC.gemspec", "SPEC.yml"]
13
- s.rdoc_options = ["--inline-source", "--main", "README", "--title", "CoreEx -- A proposal for a standard library extension.", "-T", "html"]
14
- s.extra_rdoc_files = ["README", "AUTHORS", "NEWS", "lib/core_ex.rb", "lib/core_ex/attr_once.rb", "lib/core_ex/dtime.rb", "lib/core_ex/embedded_tests.rb", "lib/core_ex/enumerable.rb", "lib/core_ex/exception.rb", "lib/core_ex/filelist.rb", "lib/core_ex/fileutils.rb", "lib/core_ex/pathname.rb", "lib/core_ex/require.rb", "lib/core_ex/string.rb", "lib/core_ex/temp_path.rb", "lib/core_ex/time.rb", "lib/core_ex/version.rb", "lib/core_ex/yaml.rb", "lib/core_ex/test/unit/ui/yaml/testrunner.rb"]
15
- end