core_ex 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +39 -1
- data/SPEC.dyn.yml +6 -6
- data/SPEC.gemspec +13 -0
- data/SPEC.yml +3 -3
- data/lib/core_ex/dependencies_ext/constant_load_path.rb +23 -0
- data/lib/core_ex/embedded_tests.rb +29 -23
- data/lib/core_ex/enumerable.rb +10 -18
- data/lib/core_ex/exception.rb +24 -21
- data/lib/core_ex/file_utils.rb +51 -0
- data/lib/core_ex/module/attr_once.rb +41 -0
- data/lib/core_ex/module/import.rb +28 -0
- data/lib/core_ex/module/mix_in_with_args.rb +267 -0
- data/lib/core_ex/object/instance_eval_with_args.rb +56 -0
- data/lib/core_ex/object/singleton_class.rb +78 -0
- data/lib/core_ex/object/the_first_time.rb +32 -0
- data/lib/core_ex/pathname.rb +268 -164
- data/lib/core_ex/proc.rb +77 -0
- data/lib/core_ex/rakefile_base.rf +93 -51
- data/lib/core_ex/require.rb +43 -384
- data/lib/core_ex/string.rb +52 -41
- data/lib/core_ex/time.rb +26 -41
- data/lib/core_ex/try_dup.rb +68 -0
- data/lib/core_ex/yaml.rb +103 -100
- data/lib/core_ex.rb +246 -35
- data/lib/{core_ex/dtime.rb → d_time.rb} +36 -22
- data/lib/{core_ex/dumpable_proc.rb → dumpable_proc.rb} +1 -2
- data/lib/{core_ex/pathlist.rb → path_list.rb} +111 -63
- data/lib/{core_ex/temp_path.rb → temp_path.rb} +55 -41
- data/lib/{core_ex/test/unit/ui/yaml/testrunner.rb → test/unit/u_i/yaml/test_runner.rb} +7 -10
- data/lib/{core_ex/version.rb → version.rb} +4 -7
- data/lib/yaml_extension.rb +78 -0
- data/test/check-core_ex.yml +6 -8
- data/test/check-pkg-core_ex.yml +3 -6
- data/test/sanity/multiple-requires.yml +41 -17
- data/test/sanity/single-requires.yml +36 -20
- data/test/sanity-suite.yml +5 -7
- data/test/test-unit-setup.rb +11 -3
- data/test/unit-suite.yml +8 -9
- metadata +35 -13
- data/lib/core_ex/attr_once.rb +0 -36
- data/lib/core_ex/fileutils.rb +0 -44
data/lib/core_ex/proc.rb
ADDED
@@ -0,0 +1,77 @@
|
|
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: proc.rb 334 2005-09-04 14:29:40Z ertai $
|
5
|
+
|
6
|
+
|
7
|
+
module CoreEx
|
8
|
+
|
9
|
+
module Proc
|
10
|
+
|
11
|
+
setup do
|
12
|
+
have YamlExtension
|
13
|
+
end
|
14
|
+
|
15
|
+
def source_file
|
16
|
+
to_s[/#<#{self.class}:.*@(.*):\d*>/, 1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def source_line
|
20
|
+
to_s[/#<#{self.class}:.*@.*:(\d*)>/, 1].to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def source_location
|
24
|
+
to_s[/#<#{self.class}:.*@(.*:\d*)>/, 1]
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_yaml_string
|
28
|
+
to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
def yaml_load ( val )
|
33
|
+
DumpableProc.new(val.to_s)
|
34
|
+
end
|
35
|
+
end # module ClassMethods
|
36
|
+
|
37
|
+
end # module Proc
|
38
|
+
|
39
|
+
test_section __FILE__ do
|
40
|
+
|
41
|
+
class TestProc < ::Test::Unit::TestCase
|
42
|
+
include YamlExtension::Assertions
|
43
|
+
|
44
|
+
def setup
|
45
|
+
@procs = {
|
46
|
+
proc {} => __LINE__,
|
47
|
+
method(:teardown).to_proc => __LINE__,
|
48
|
+
TestProc.instance_method(:setup).bind(self).to_proc => __LINE__
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def teardown
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_simple
|
56
|
+
assert_nothing_raised do
|
57
|
+
@procs.each do |block, __line__|
|
58
|
+
assert_equal __FILE__, block.source_file, 'bad source_file'
|
59
|
+
assert_equal __line__, block.source_line, 'bad source_line'
|
60
|
+
assert_equal "#{__FILE__}:#{__line__}",
|
61
|
+
block.source_location,
|
62
|
+
'bad source_location'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_yaml
|
68
|
+
assert_yaml_load "--- !proc 3 + 7", Proc
|
69
|
+
assert_yaml_dump @val, @ref
|
70
|
+
assert_equal(10, @val[])
|
71
|
+
end
|
72
|
+
|
73
|
+
end # class TestProc
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end # module CoreEx
|
@@ -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
|
4
|
+
# Revision:: $Id: rakefile_base.rf 352 2005-09-15 01:43:03Z ertai $
|
5
5
|
|
6
6
|
require 'core_ex'
|
7
7
|
require 'ostruct'
|
@@ -12,15 +12,17 @@ require 'rake/packagetask'
|
|
12
12
|
require 'rake/rdoctask'
|
13
13
|
require 'rake/gempackagetask'
|
14
14
|
require 'rake/contrib/rubyforgepublisher'
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
suppress(NoMethodError) { require_gem 'highline' }
|
16
|
+
suppress(LoadError) { require 'highline/import' }
|
17
|
+
|
18
|
+
PathList.import!
|
18
19
|
|
19
20
|
|
20
21
|
AUTHORS = Pathname.new('AUTHORS')
|
21
22
|
SPEC_YML = Pathname.new('SPEC.yml')
|
22
23
|
SPEC_DYN_YML = Pathname.new('SPEC.dyn.yml')
|
23
|
-
GEM_SPEC = Pathname.new(
|
24
|
+
GEM_SPEC = Pathname.new('SPEC.gemspec')
|
25
|
+
VENDOR = Pathname.new('vendor')
|
24
26
|
RakefileBase = __FILE__
|
25
27
|
EDITOR = ENV['EDITOR'] || 'vi'
|
26
28
|
|
@@ -42,13 +44,16 @@ svn = MiniSvn.new
|
|
42
44
|
|
43
45
|
def clean_task ( arg, &block )
|
44
46
|
if arg.is_a? Hash
|
45
|
-
name =
|
46
|
-
task(name => arg.values.first, &block)
|
47
|
+
name, deps = arg.to_a.first
|
47
48
|
else
|
48
|
-
name =
|
49
|
-
|
49
|
+
name, deps = arg, []
|
50
|
+
end
|
51
|
+
clobber_name = :"clobber_#{name}"
|
52
|
+
task clobber_name => deps do
|
53
|
+
Task[name].instance_eval { @already_invoked = false }
|
54
|
+
block[] unless block.nil?
|
50
55
|
end
|
51
|
-
task :clobber =>
|
56
|
+
task :clobber => clobber_name
|
52
57
|
end
|
53
58
|
|
54
59
|
|
@@ -72,12 +77,17 @@ task :default => [ :check ]
|
|
72
77
|
|
73
78
|
|
74
79
|
|
80
|
+
task :ruby_ex => [ :spec ] do
|
81
|
+
require_gem('ruby_ex', SPEC.ruby_ex_version || '~> 0.2.0')
|
82
|
+
require 'ruby_ex'
|
83
|
+
end
|
84
|
+
|
85
|
+
|
75
86
|
# desc 'Setup the ttk command'
|
76
|
-
task :ttk => [ :spec ] do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
alias ask highline_ask
|
87
|
+
task :ttk => [ :spec, :ruby_ex ] do
|
88
|
+
require_gem('ttk', SPEC.ttk_version || '~> 0.3.0')
|
89
|
+
require 'ttk'
|
90
|
+
Commands.import!
|
81
91
|
def ttk ( *a, &b )
|
82
92
|
cmd = TTK.bin[*a]
|
83
93
|
cmd.input = b[] if b
|
@@ -91,11 +101,11 @@ end
|
|
91
101
|
|
92
102
|
desc 'Launch all test suites'
|
93
103
|
task :check => [ :ttk, :spec, :dyn_spec ] do
|
94
|
-
ttk '-l', 'check-log
|
104
|
+
ttk '-l', 'check-log', '-S', 'url: file://<<pwd>>', '-C',
|
95
105
|
SPEC.root_test_suite
|
96
106
|
end
|
97
107
|
clean_task :check do
|
98
|
-
'check-log
|
108
|
+
PathList['check-log.*'].each { |x| x.rm_f }
|
99
109
|
end
|
100
110
|
|
101
111
|
|
@@ -107,7 +117,7 @@ task :distcheck => [ :ttk, :package ] do
|
|
107
117
|
next unless path.file?
|
108
118
|
urls << "file://#{path.expand_path}"
|
109
119
|
end
|
110
|
-
ttk '-l', 'distcheck-log
|
120
|
+
ttk '-l', 'distcheck-log' do %Q[
|
111
121
|
Check generated packages:
|
112
122
|
strategy: Iterate
|
113
123
|
over : #{urls.inspect}
|
@@ -121,7 +131,7 @@ task :distcheck => [ :ttk, :package ] do
|
|
121
131
|
end
|
122
132
|
end
|
123
133
|
clean_task :distcheck do
|
124
|
-
'distcheck-log
|
134
|
+
PathList['distcheck-log.*'].each { |x| x.rm_f }
|
125
135
|
end
|
126
136
|
|
127
137
|
|
@@ -129,7 +139,9 @@ end
|
|
129
139
|
# desc "Load the #{SPEC_YML} file"
|
130
140
|
task :spec => [ SPEC_YML.to_s ] do
|
131
141
|
Kernel.const_set(:SPEC, OpenStruct.new(YAML.load(SPEC_YML.read)))
|
142
|
+
task :spec_pkg_files => SPEC.pkg_files
|
132
143
|
end
|
144
|
+
task :spec_pkg_files
|
133
145
|
|
134
146
|
|
135
147
|
|
@@ -172,26 +184,38 @@ end
|
|
172
184
|
|
173
185
|
desc 'Generate the full documentation'
|
174
186
|
task :doc => [ :rdoc_spec, :rdoc_real ]
|
187
|
+
|
175
188
|
clean_task :doc => [ :rdoc_spec, :clobber_rdoc_real ]
|
189
|
+
|
176
190
|
task :redoc => [ :clobber_doc, :doc ]
|
177
191
|
|
178
192
|
|
193
|
+
task :tarballs => [ :dyn_spec, :vendor ] do
|
194
|
+
Rake::PackageTask.new(SPEC.name, SPEC.dyn.version.to_s) do |p|
|
195
|
+
p.need_tar_gz = true
|
196
|
+
p.need_tar_bz2 = true
|
197
|
+
p.package_files = (SPEC.pkg_files + PathList['vendor/**/*']).map { |x| x.to_s }
|
198
|
+
end
|
199
|
+
end
|
179
200
|
|
180
|
-
desc 'Generate all packages'
|
181
|
-
task :package => [ :gem_spec, :gem ]
|
182
|
-
clean_task :package => [ :gem_spec ]
|
183
201
|
|
202
|
+
desc 'Generate all packages'
|
203
|
+
task :package => [ :tarballs, :gem_spec, :gem ]
|
184
204
|
|
205
|
+
clean_task :package => [ :spec, :clobber_vendor, :clobber_gem_spec ]
|
185
206
|
|
186
207
|
desc 'Re-generate all packages'
|
187
|
-
task :repackage
|
208
|
+
task :repackage => [ :clobber_package, :package ]
|
188
209
|
|
189
210
|
|
190
211
|
|
191
212
|
desc 'Generate a GEM package'
|
192
213
|
task :gem => [ :gem_spec ]
|
193
214
|
|
194
|
-
|
215
|
+
# desc 'Remove the GEM package file'
|
216
|
+
clean_task :gem => [ :gem_spec ] do
|
217
|
+
$gem.rm_f
|
218
|
+
end
|
195
219
|
|
196
220
|
desc 'Re-generate a GEM package'
|
197
221
|
task :regem => [ :clobber_gem, :gem ]
|
@@ -207,14 +231,14 @@ task :rdoc_spec => [ :spec ] do
|
|
207
231
|
rdoc.main = SPEC.rdoc_files.first
|
208
232
|
tail = SPEC.rdoc_tail_files || []
|
209
233
|
fl = SPEC.rdoc_files - tail + tail
|
210
|
-
rdoc.rdoc_files.include(fl.
|
234
|
+
rdoc.rdoc_files.include(fl.stringify)
|
211
235
|
end
|
212
236
|
end
|
213
237
|
|
214
238
|
|
215
239
|
|
216
240
|
# desc 'Update the Gem specification'
|
217
|
-
file GEM_SPEC.to_s => [ :spec, :dyn_spec, :rdoc_spec ] do
|
241
|
+
file GEM_SPEC.to_s => [ :spec, :spec_pkg_files, :dyn_spec, :rdoc_spec ] do
|
218
242
|
spec = Gem::Specification.new do |s|
|
219
243
|
s.platform = Gem::Platform::RUBY
|
220
244
|
s.name = SPEC.name
|
@@ -226,13 +250,13 @@ file GEM_SPEC.to_s => [ :spec, :dyn_spec, :rdoc_spec ] do
|
|
226
250
|
s.executables = Pathname.glob(bin + '*').select do |path|
|
227
251
|
path.executable? and not path.directory?
|
228
252
|
end.map { |path| path.basename.to_s }
|
229
|
-
s.files = SPEC.pkg_files.
|
253
|
+
s.files = SPEC.pkg_files.stringify
|
230
254
|
s.require_path = 'lib'
|
231
255
|
s.autorequire = SPEC.autorequire if SPEC.autorequire
|
232
256
|
|
233
257
|
if SPEC.dependencies
|
234
258
|
SPEC.dependencies.each do |name, version|
|
235
|
-
s.add_dependency(name, version)
|
259
|
+
s.add_dependency(name, (version.is_a? Array)? version.first : version)
|
236
260
|
end
|
237
261
|
end
|
238
262
|
|
@@ -255,46 +279,32 @@ end
|
|
255
279
|
|
256
280
|
|
257
281
|
|
258
|
-
# desc "Remove the #{GEM_SPEC} file"
|
259
|
-
clean_task :gem_spec do
|
260
|
-
GEM_SPEC.rm_f
|
261
|
-
end
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
# desc 'Load the GEM spec and create tasks for packages'
|
266
282
|
task :gem_spec => [ GEM_SPEC.to_s ] do
|
267
283
|
spec = eval(GEM_SPEC.read)
|
268
284
|
|
269
285
|
gtask = Rake::GemPackageTask.new(spec) do |p|
|
270
286
|
p.gem_spec = spec
|
271
|
-
p.need_tar_gz = true
|
272
|
-
p.need_tar_bz2 = true
|
273
287
|
p.package_files = SPEC.pkg_files.map { |x| x.to_s }
|
274
288
|
end
|
275
289
|
gtask.instance_eval { $gem = 'pkg'.to_path + gem_file }
|
276
290
|
end
|
291
|
+
clean_task :gem_spec do
|
292
|
+
GEM_SPEC.rm_f
|
293
|
+
end
|
277
294
|
|
278
295
|
|
279
|
-
|
280
|
-
|
281
|
-
clean_task :gem => [ :gem_spec ] do
|
282
|
-
$gem.rm_f
|
296
|
+
task :vcs do
|
297
|
+
require_gem('vcs', SPEC.vcs_version || '~> 0.3.0')
|
283
298
|
end
|
284
299
|
|
285
300
|
|
286
|
-
|
287
301
|
desc 'Commit with Vcs'
|
288
|
-
task :commit => [ :
|
289
|
-
subject = ask('Commit subject: ') do |q|
|
290
|
-
q.confirm = true
|
291
|
-
q.validate = /^[^a-z].*\.$/
|
292
|
-
end
|
302
|
+
task :commit => [ :vcs ] do
|
293
303
|
pos = ARGV.index('--')
|
294
304
|
args = (pos.nil?)? [] : ARGV[pos .. -1]
|
295
|
-
cmd = SPEC.commit_command || 'commit'
|
305
|
+
cmd = SPEC.commit_command || 'commit'
|
296
306
|
Dir.chdir(SPEC.commit_dir || '.') do
|
297
|
-
sh 'vcs-svn', cmd,
|
307
|
+
sh 'vcs-svn', cmd, *args
|
298
308
|
end
|
299
309
|
end
|
300
310
|
|
@@ -341,6 +351,9 @@ end
|
|
341
351
|
# desc 'Common tasks for a release'
|
342
352
|
task :common_release =>
|
343
353
|
[
|
354
|
+
:ttk,
|
355
|
+
:vcs,
|
356
|
+
|
344
357
|
:release_confirm,
|
345
358
|
:check,
|
346
359
|
:doc,
|
@@ -460,7 +473,7 @@ task :publish_package => [ :spec, :package ] do
|
|
460
473
|
release_data.gsub(/name="package_id" value="(\d+)"/) { ids << $1 ; nil }
|
461
474
|
release_data.gsub(/name="package_name" value="([^"]+)"/) { names << $1 ; nil }
|
462
475
|
package_name = SPEC.rubyforge_sub_package_name || SPEC.name
|
463
|
-
|
476
|
+
|
464
477
|
package_id = names.zip(ids).find { |name, id| name == package_name }.last
|
465
478
|
raise "Couldn't get package id or package name" unless package_id
|
466
479
|
|
@@ -550,3 +563,32 @@ clean_task :publish_package do
|
|
550
563
|
x.rm_f
|
551
564
|
end
|
552
565
|
end
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
task :vendor => [ :spec, :ruby_ex ] do
|
570
|
+
unless VENDOR.directory?
|
571
|
+
say "Creating the vendor directory..."
|
572
|
+
VENDOR.mkpath
|
573
|
+
require 'uri_ex'
|
574
|
+
if SPEC.dependencies
|
575
|
+
SPEC.dependencies.each do |name, version|
|
576
|
+
next unless version.is_a? Array
|
577
|
+
url = version.last
|
578
|
+
if url =~ /^\d+\/[^\/]+$/
|
579
|
+
url = "http://rubyforge.org/frs/download.php/#{url}"
|
580
|
+
end
|
581
|
+
url = URI.parse(url)
|
582
|
+
dest = VENDOR + url.pathname.basename.ext.to_s.sub(/\.tar$/, '').to_path
|
583
|
+
STDERR.puts "#{url} => #{dest}"
|
584
|
+
FileType.guess(url.checkout).extract.path.mv(dest)
|
585
|
+
end
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
clean_task :vendor do
|
591
|
+
VENDOR.rm_rf
|
592
|
+
end
|
593
|
+
|
594
|
+
task :revendor => [:clobber_vendor, :vendor]
|