comp_tree 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,5 +1,13 @@
1
1
 
2
- = CompTree ChangeLog
2
+ = comp_tree Changes
3
+
4
+ == Version 1.1.0
5
+
6
+ * lazily spawn threads as needed -- no longer pre-allocates possibly
7
+ unused threads
8
+
9
+ * no longer required to specify the number of threads (pass 0 to the
10
+ second argument of +compute+).
3
11
 
4
12
  == Version 1.0.1
5
13
 
data/MANIFEST CHANGED
@@ -2,17 +2,16 @@ CHANGES.rdoc
2
2
  MANIFEST
3
3
  README.rdoc
4
4
  Rakefile
5
- devel/jumpstart.rb
6
- install.rb
5
+ devel/levitate.rb
7
6
  lib/comp_tree.rb
8
7
  lib/comp_tree/algorithm.rb
9
- lib/comp_tree/comp_tree.rb
10
8
  lib/comp_tree/driver.rb
11
9
  lib/comp_tree/error.rb
12
10
  lib/comp_tree/node.rb
13
11
  lib/comp_tree/queue/queue.rb
14
12
  lib/comp_tree/queue/queue_18.rb
15
13
  lib/comp_tree/queue/queue_19.rb
14
+ lib/comp_tree/version.rb
16
15
  test/basic_test.rb
17
16
  test/circular_test.rb
18
17
  test/comp_tree_test_base.rb
data/README.rdoc CHANGED
@@ -31,7 +31,7 @@ A simple framework for automatic parallelism.
31
31
  2
32
32
  }
33
33
 
34
- # Compute the area using four parallel threads.
34
+ # Compute the area using up to four parallel threads.
35
35
  puts driver.compute(:area, 4)
36
36
  # => 63
37
37
 
@@ -44,15 +44,26 @@ A simple framework for automatic parallelism.
44
44
 
45
45
  % gem install comp_tree
46
46
 
47
- Or for the (non-gem) .tgz package,
48
-
49
- % ruby install.rb [--uninstall]
47
+ Or from inside an unpacked .tgz download, <code>rake install</code> /
48
+ <code>rake uninstall</code>.
50
49
 
51
50
  == Description
52
51
 
53
52
  CompTree is a parallel computation tree structure based upon concepts
54
53
  from pure functional programming.
55
54
 
55
+ CompTree has been tested on MRI versions 1.8.6, 1.8.7, 1.9.1, 1.9.2,
56
+ and jruby versions 1.4, 1.5, 1.6.
57
+
58
+ == Links
59
+
60
+ * Home: http://quix.github.com/comp_tree
61
+ * Feature Requests, Bug Reports: http://github.com/quix/comp_tree/issues
62
+ * Manual Download: http://github.com/quix/comp_tree/archives/master
63
+ * Repository: http://github.com/quix/comp_tree
64
+
65
+ == Background
66
+
56
67
  The user should have a basic understanding of functional programming
57
68
  (see for example http://en.wikipedia.org/wiki/Functional_programming)
58
69
  and the meaning of <em>side effects</em>.
@@ -88,20 +99,13 @@ Note however it is OK affect a state as long as <em>no other function
88
99
  depends on that state</em>. This is the principle under which
89
100
  CompTree parallelizes Rake tasks (http://drake.rubyforge.org).
90
101
 
91
- == Links
92
-
93
- * Documentation: http://comptree.rubyforge.org
94
- * Download: http://rubyforge.org/frs/?group_id=6917
95
- * Rubyforge home: http://rubyforge.org/projects/comptree
96
- * Repository: http://github.com/quix/comp_tree
97
-
98
102
  == Author
99
103
 
100
104
  * James M. Lawrence <quixoticsycophant@gmail.com>
101
105
 
102
106
  == License
103
107
 
104
- Copyright (c) 2008, 2009 James M. Lawrence. All rights reserved.
108
+ Copyright (c) 2008-2011 James M. Lawrence. All rights reserved.
105
109
 
106
110
  Permission is hereby granted, free of charge, to any person
107
111
  obtaining a copy of this software and associated documentation files
data/Rakefile CHANGED
@@ -1,10 +1,11 @@
1
1
  $LOAD_PATH.unshift 'devel'
2
2
 
3
- require 'jumpstart'
3
+ require 'levitate'
4
4
 
5
- Jumpstart.new "comp_tree" do |s|
6
- s.developer "James M. Lawrence", "quixoticsycophant@gmail.com"
7
- s.rubyforge_user = "quix"
5
+ Levitate.new "comp_tree" do |s|
6
+ s.developers << ["James M. Lawrence", "quixoticsycophant@gmail.com"]
7
+ s.rubyforge_info = ["quix", "comptree"]
8
+ s.github_user = "quix"
8
9
  s.rdoc_files = %w[
9
10
  lib/comp_tree/comp_tree.rb
10
11
  lib/comp_tree/driver.rb
@@ -1,11 +1,11 @@
1
1
 
2
- class Jumpstart
3
- class SimpleInstaller
2
+ class Levitate
3
+ class Installer
4
4
  def initialize
5
5
  require 'fileutils'
6
6
  require 'rbconfig'
7
7
  require 'find'
8
- dest_root = Config::CONFIG["sitelibdir"]
8
+ dest_root = RbConfig::CONFIG["sitelibdir"]
9
9
  sources = []
10
10
  Find.find("./lib") { |source|
11
11
  if install_file?(source)
@@ -146,13 +146,13 @@ class Jumpstart
146
146
  require 'rbconfig'
147
147
 
148
148
  name = File.join(
149
- Config::CONFIG["bindir"],
150
- Config::CONFIG["RUBY_INSTALL_NAME"]
149
+ RbConfig::CONFIG["bindir"],
150
+ RbConfig::CONFIG["RUBY_INSTALL_NAME"]
151
151
  )
152
152
 
153
- if Config::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
153
+ if RbConfig::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
154
154
  File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
155
- name + Config::CONFIG["EXEEXT"]
155
+ name + RbConfig::CONFIG["EXEEXT"]
156
156
  else
157
157
  name
158
158
  end
@@ -219,17 +219,6 @@ class Jumpstart
219
219
  }
220
220
  contents
221
221
  end
222
-
223
- def replace_file(file)
224
- old_contents = File.read(file)
225
- new_contents = yield(old_contents)
226
- if old_contents != new_contents
227
- File.open(file, "wb") { |output|
228
- output.print(new_contents)
229
- }
230
- end
231
- new_contents
232
- end
233
222
  end
234
223
 
235
224
  module InstanceEvalWithArgs
@@ -260,20 +249,18 @@ class Jumpstart
260
249
  include AttrLazy
261
250
  include Util
262
251
 
263
- def initialize(project_name)
252
+ def initialize(gem_name)
264
253
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
265
- $LOAD_PATH.unshift File.dirname(__FILE__)
266
254
 
267
- require 'rake/gempackagetask'
268
- require 'rake/clean'
255
+ require 'rubygems/package_task'
269
256
 
270
- @project_name = project_name
257
+ @gem_name = gem_name
271
258
 
272
259
  yield self
273
260
 
274
261
  self.class.instance_methods(false).select { |t|
275
262
  t.to_s =~ %r!\Adefine_!
276
- }.each { |method_name|
263
+ }.sort.each { |method_name|
277
264
  send(method_name)
278
265
  }
279
266
  end
@@ -282,35 +269,32 @@ class Jumpstart
282
269
  alias_method :attribute, :attr_lazy_accessor
283
270
  end
284
271
 
285
- attribute :name do
286
- @project_name
287
- end
272
+ attr_reader :gem_name
288
273
 
289
274
  attribute :version_constant_name do
290
275
  "VERSION"
291
276
  end
292
277
 
278
+ attribute :camel_name do
279
+ to_camel_case(gem_name)
280
+ end
281
+
293
282
  attribute :version do
294
- require name
295
- mod_name = to_camel_case(name)
296
- begin
297
- mod = Kernel.const_get(mod_name)
298
- if mod.constants.include?(version_constant_name)
299
- mod.const_get(version_constant_name)
283
+ catch :bail do
284
+ if File.file?(version_file = "./lib/#{gem_name}/version.rb")
285
+ require version_file
286
+ elsif File.file?("./lib/#{gem_name}.rb")
287
+ require gem_name
300
288
  else
301
- raise
289
+ throw :bail
302
290
  end
303
- rescue
304
- "0.0.0"
305
- end
306
- end
307
-
308
- attribute :rubyforge_name do
309
- name.gsub('_', '')
310
- end
311
-
312
- attribute :rubyforge_user do
313
- email.first[%r!^.*(?=@)!]
291
+ mod = Kernel.const_get(camel_name)
292
+ constants = mod.constants.map { |t| t.to_sym }
293
+ unless constants.include?(version_constant_name.to_sym)
294
+ throw :bail
295
+ end
296
+ mod.const_get(version_constant_name)
297
+ end or "0.0.0"
314
298
  end
315
299
 
316
300
  attribute :readme_file do
@@ -322,7 +306,7 @@ class Jumpstart
322
306
  end
323
307
 
324
308
  attribute :doc_dir do
325
- "documentation"
309
+ "doc"
326
310
  end
327
311
 
328
312
  attribute :spec_files do
@@ -333,7 +317,7 @@ class Jumpstart
333
317
  (Dir["./test/test_*.rb"] + Dir["./test/*_test.rb"]).uniq
334
318
  end
335
319
 
336
- attribute :rcov_dir do
320
+ attribute :cov_dir do
337
321
  "coverage"
338
322
  end
339
323
 
@@ -351,7 +335,7 @@ class Jumpstart
351
335
 
352
336
  [:gem, :tgz].each { |ext|
353
337
  attribute ext do
354
- "pkg/#{name}-#{version}.#{ext}"
338
+ "pkg/#{gem_name}-#{version}.#{ext}"
355
339
  end
356
340
  }
357
341
 
@@ -379,90 +363,86 @@ class Jumpstart
379
363
  end
380
364
 
381
365
  attribute :files do
382
- if File.exist?(manifest_file)
366
+ if File.file? manifest_file
383
367
  File.read(manifest_file).split("\n")
384
- else
385
- `git ls-files`.split("\n") + [manifest_file] + generated_files
386
- end
368
+ elsif source_control?
369
+ IO.popen("git ls-files") { |pipe| pipe.read.split "\n" }
370
+ end.to_a + [manifest_file] + generated_files
371
+ end
372
+
373
+ def files_in_require_paths
374
+ require_paths.inject([]) { |acc, dir|
375
+ acc + Dir.glob("#{dir}/**/*.rb")
376
+ }
387
377
  end
388
378
 
389
379
  attribute :rdoc_files do
390
- Dir["lib/**/*.rb"]
380
+ files_in_require_paths
391
381
  end
392
382
 
393
- attribute :extra_rdoc_files do
394
- if File.exist?(readme_file)
395
- [readme_file]
396
- else
397
- []
398
- end
383
+ attribute :rdoc_title do
384
+ "#{gem_name}: #{summary}"
385
+ end
386
+
387
+ attribute :require_paths do
388
+ ["lib"]
399
389
  end
400
390
 
401
391
  attribute :rdoc_options do
402
- if File.exist?(readme_file)
392
+ if File.file?(readme_file)
403
393
  ["--main", readme_file]
404
394
  else
405
395
  []
406
396
  end + [
407
- "--title", "#{name}: #{summary}",
408
- ] + (files - rdoc_files).inject(Array.new) { |acc, file|
397
+ "--title", rdoc_title,
398
+ ] + (files_in_require_paths - rdoc_files).inject(Array.new) {
399
+ |acc, file|
409
400
  acc + ["--exclude", file]
410
401
  }
411
402
  end
412
403
 
404
+ attribute :extra_rdoc_files do
405
+ result = []
406
+ [readme_file, history_file].each { |file|
407
+ result << file if File.file?(file)
408
+ }
409
+ result
410
+ end
411
+
413
412
  attribute :browser do
414
413
  require 'rbconfig'
415
- if Config::CONFIG["host"] =~ %r!darwin!
416
- app = %w[Firefox Safari].map { |t|
417
- "/Applications/#{t}.app"
418
- }.select { |t|
419
- File.exist? t
420
- }.first
421
- if app
422
- ["open", app]
423
- else
424
- raise "need to set `browser'"
425
- end
414
+ if RbConfig::CONFIG["host"] =~ %r!darwin!
415
+ "open"
426
416
  else
427
417
  "firefox"
428
418
  end
429
419
  end
430
420
 
431
421
  attribute :gemspec do
432
- Gem::Specification.new { |g|
433
- g.has_rdoc = true
422
+ Gem::Specification.new do |g|
434
423
  %w[
435
- name
436
424
  authors
437
425
  email
438
426
  summary
439
427
  version
440
428
  description
441
429
  files
442
- extra_rdoc_files
443
430
  rdoc_options
444
- ].each { |param|
445
- value = send(param) and (
446
- g.send("#{param}=", value)
447
- )
448
- }
449
-
450
- if rubyforge_name
451
- g.rubyforge_project = rubyforge_name
452
- end
453
-
454
- if url
455
- g.homepage = url
431
+ extra_rdoc_files
432
+ require_paths
433
+ ].each do |param|
434
+ t = send(param) and g.send("#{param}=", t)
456
435
  end
457
-
458
- extra_deps.each { |dep|
436
+ g.name = gem_name
437
+ g.has_rdoc = true
438
+ g.homepage = url if url
439
+ dependencies.each { |dep|
459
440
  g.add_dependency(*dep)
460
441
  }
461
-
462
- extra_dev_deps.each { |dep|
442
+ development_dependencies.each { |dep|
463
443
  g.add_development_dependency(*dep)
464
444
  }
465
- }
445
+ end
466
446
  end
467
447
 
468
448
  attribute :readme_contents do
@@ -470,10 +450,9 @@ class Jumpstart
470
450
  end
471
451
 
472
452
  attribute :sections do
473
- require 'enumerator'
474
453
  begin
475
454
  data = readme_contents.split(%r!^==\s*(.*?)\s*$!)
476
- pairs = data[1..-1].enum_slice(2).map { |section, contents|
455
+ pairs = data[1..-1].each_slice(2).map { |section, contents|
477
456
  [section.downcase, contents.strip]
478
457
  }
479
458
  Hash[*pairs.flatten]
@@ -513,58 +492,60 @@ class Jumpstart
513
492
  }
514
493
 
515
494
  attribute :url do
516
- begin
517
- readme_contents.match(%r!^\*.*?(http://\S+)!)[1]
518
- rescue
519
- "http://#{rubyforge_name}.rubyforge.org"
520
- end
495
+ "http://#{github_user}.github.com/#{gem_name}"
521
496
  end
522
497
 
523
- attribute :extra_deps do
524
- []
498
+ attribute :github_user do
499
+ raise "github_user not set"
525
500
  end
526
501
 
527
- attribute :extra_dev_deps do
528
- []
502
+ attribute :rubyforge_info do
503
+ nil
529
504
  end
530
505
 
531
506
  attribute :authors do
532
- Array.new
507
+ developers.map { |d| d[0] }
533
508
  end
534
509
 
535
510
  attribute :email do
536
- Array.new
511
+ developers.map { |d| d[1] }
537
512
  end
538
513
 
539
- def developer(name, email)
540
- authors << name
541
- self.email << email
514
+ attribute :dependencies do
515
+ []
542
516
  end
543
517
 
544
- def dependency(name, version)
545
- extra_deps << [name, version]
518
+ attribute :development_dependencies do
519
+ []
520
+ end
521
+
522
+ attribute :developers do
523
+ []
546
524
  end
547
525
 
548
526
  def define_clean
549
- task :clean do
527
+ require 'rake/clean'
528
+ task :clean do
550
529
  Rake::Task[:clobber].invoke
551
530
  end
552
531
  end
553
532
 
554
533
  def define_package
555
- task manifest_file do
556
- create_manifest
534
+ if source_control?
535
+ task manifest_file do
536
+ create_manifest
537
+ end
538
+ CLEAN.add manifest_file
539
+ task :package => :clean
540
+ Gem::PackageTask.new(gemspec).define
557
541
  end
558
- CLEAN.include manifest_file
559
- task :package => :clean
560
- Rake::GemPackageTask.new(gemspec) { |t|
561
- t.need_tar = true
562
- }
563
542
  end
564
543
 
565
544
  def define_spec
566
545
  unless spec_files.empty?
567
- require 'spec/rake/spectask'
546
+ Ruby.no_warnings {
547
+ require 'spec/rake/spectask'
548
+ }
568
549
 
569
550
  desc "run specs"
570
551
  Spec::Rake::SpecTask.new('spec') do |t|
@@ -585,9 +566,11 @@ class Jumpstart
585
566
  t.spec_opts = ["-fh:#{spec_output}"]
586
567
  end
587
568
 
569
+ suppress_task_warnings :spec, :full_spec, :text_spec
570
+
588
571
  desc "run full_spec then open browser"
589
572
  task :show_spec => :full_spec do
590
- open_browser(spec_output, rcov_dir + "/index.html")
573
+ open_browser(spec_output, cov_dir + "/index.html")
591
574
  end
592
575
 
593
576
  desc "run specs individually"
@@ -598,7 +581,7 @@ class Jumpstart
598
581
  task :prerelease => [:spec, :spec_deps]
599
582
  task :default => :spec
600
583
 
601
- CLEAN.include spec_output_dir
584
+ CLEAN.add spec_output_dir
602
585
  end
603
586
  end
604
587
 
@@ -606,23 +589,44 @@ class Jumpstart
606
589
  unless test_files.empty?
607
590
  desc "run tests"
608
591
  task :test do
609
- test_files.each { |file|
610
- require file
611
- }
592
+ test_files.each { |file| require file }
593
+
594
+ # if we use at_exit hook instead, it won't run before :release
595
+ MiniTest::Unit.new.run ARGV
612
596
  end
613
597
 
614
- desc "run tests with rcov"
615
- task :full_test do
616
- verbose(false) {
617
- sh("rcov", "-o", rcov_dir, "--text-report",
618
- *(test_files + rcov_options)
619
- )
620
- }
598
+ desc "run tests with coverage"
599
+ if ruby_18?
600
+ task :full_test do
601
+ verbose(false) {
602
+ sh("rcov", "-o", cov_dir, "--text-report",
603
+ *(test_files + rcov_options)
604
+ )
605
+ }
606
+ end
607
+ else
608
+ task :full_test do
609
+ rm_rf cov_dir
610
+ require 'simplecov'
611
+ SimpleCov.start do
612
+ add_filter "test/"
613
+ add_filter "devel/"
614
+ end
615
+ Rake::Task[:test].invoke
616
+ end
621
617
  end
622
618
 
623
619
  desc "run full_test then open browser"
624
620
  task :show_test => :full_test do
625
- open_browser(rcov_dir + "/index.html")
621
+ show = lambda { open_browser(cov_dir + "/index.html") }
622
+ if ruby_18?
623
+ show.call
624
+ else
625
+ SimpleCov.at_exit do
626
+ SimpleCov.result.format!
627
+ show.call
628
+ end
629
+ end
626
630
  end
627
631
 
628
632
  desc "run tests individually"
@@ -633,13 +637,14 @@ class Jumpstart
633
637
  task :prerelease => [:test, :test_deps]
634
638
  task :default => :test
635
639
 
636
- CLEAN.include rcov_dir
640
+ CLEAN.add cov_dir
637
641
  end
638
642
  end
639
643
 
640
644
  def define_doc
641
645
  desc "run rdoc"
642
646
  task :doc => :clean_doc do
647
+ Kernel.send :gem, 'rdoc' rescue nil
643
648
  require 'rdoc/rdoc'
644
649
  args = (
645
650
  gemspec.rdoc_options +
@@ -665,108 +670,48 @@ class Jumpstart
665
670
  end
666
671
 
667
672
  def define_publish
668
- desc "upload docs"
669
- task :publish => [:clean_doc, :doc] do
670
- require 'rake/contrib/sshpublisher'
671
- Rake::SshDirPublisher.new(
672
- "#{rubyforge_user}@rubyforge.org",
673
- "/var/www/gforge-projects/#{rubyforge_name}",
674
- doc_dir
675
- ).upload
673
+ if source_control?
674
+ desc "publish docs"
675
+ task :publish => [:clean, :check_directory, :doc] do
676
+ if rubyforge_info
677
+ user, project = rubyforge_info
678
+ Dir.chdir(doc_dir) do
679
+ sh "scp", "-r",
680
+ ".",
681
+ "#{user}@rubyforge.org:/var/www/gforge-projects/#{project}"
682
+ end
683
+ end
684
+ git "branch", "-D", "gh-pages"
685
+ git "checkout", "--orphan", "gh-pages"
686
+ FileUtils.rm ".git/index"
687
+ git "clean", "-fdx", "-e", "doc"
688
+ Dir["doc/*"].each { |path|
689
+ FileUtils.mv path, "."
690
+ }
691
+ FileUtils.rmdir "doc"
692
+ git "add", "."
693
+ git "commit", "-m", "generated by rdoc"
694
+ git "push", "-f", "origin", "gh-pages"
695
+ end
676
696
  end
677
697
  end
678
698
 
679
699
  def define_install
680
700
  desc "direct install (no gem)"
681
701
  task :install do
682
- SimpleInstaller.new.run([])
702
+ Installer.new.run([])
683
703
  end
684
704
 
685
705
  desc "direct uninstall (no gem)"
686
706
  task :uninstall do
687
- SimpleInstaller.new.run(["--uninstall"])
707
+ Installer.new.run(["--uninstall"])
688
708
  end
689
709
  end
690
710
 
691
- def define_debug
692
- runner = Class.new do
693
- def comment_src_dst(on)
694
- on ? ["", "#"] : ["#", ""]
695
- end
696
-
697
- def comment_regions(on, contents, start)
698
- src, dst = comment_src_dst(on)
699
- contents.gsub(%r!^(\s+)#{src}#{start}.*?^\1#{src}(\}|end)!m) { |chunk|
700
- indent = $1
701
- chunk.gsub(%r!^#{indent}#{src}!, "#{indent}#{dst}")
702
- }
703
- end
704
-
705
- def comment_lines(on, contents, start)
706
- src, dst = comment_src_dst(on)
707
- contents.gsub(%r!^(\s*)#{src}#{start}!) {
708
- $1 + dst + start
709
- }
710
- end
711
-
712
- def debug_info(enable)
713
- require 'find'
714
- Find.find("lib", "test") { |path|
715
- if path =~ %r!\.rb\Z!
716
- replace_file(path) { |contents|
717
- result = comment_regions(!enable, contents, "debug")
718
- comment_lines(!enable, result, "trace")
719
- }
720
- end
721
- }
722
- end
723
- end
724
-
725
- desc "enable debug and trace calls"
726
- task :debug_on do
727
- runner.new.debug_info(true)
728
- end
729
-
730
- desc "disable debug and trace calls"
731
- task :debug_off do
732
- runner.new.debug_info(false)
733
- end
734
- end
735
-
736
- def define_columns
737
- desc "check for columns > 80"
738
- task :check_columns do
739
- Dir["**/*.rb"].each { |file|
740
- File.read(file).scan(%r!^.{81}!) { |match|
741
- unless match =~ %r!http://!
742
- raise "#{file} greater than 80 columns: #{match}"
743
- end
744
- }
745
- }
746
- end
747
- task :prerelease => :check_columns
748
- end
749
-
750
- def define_comments
751
- task :comments do
752
- file = "comments.txt"
753
- write_file(file) {
754
- result = Array.new
755
- (["Rakefile"] + Dir["**/*.{rb,rake}"]).each { |f|
756
- File.read(f).scan(%r!\#[^\{].*$!) { |match|
757
- result << match
758
- }
759
- }
760
- result.join("\n")
761
- }
762
- CLEAN.include file
763
- end
764
- end
765
-
766
711
  def define_check_directory
767
712
  task :check_directory do
768
713
  unless `git status` =~ %r!nothing to commit \(working directory clean\)!
769
- raise "Directory not clean"
714
+ raise "directory not clean"
770
715
  end
771
716
  end
772
717
  end
@@ -774,9 +719,9 @@ class Jumpstart
774
719
  def define_ping
775
720
  task :ping do
776
721
  require 'rbconfig'
777
- %w[github.com rubyforge.org].each { |server|
722
+ %w[github.com].each { |server|
778
723
  cmd = "ping " + (
779
- if Config::CONFIG["host"] =~ %r!darwin!
724
+ if RbConfig::CONFIG["host"] =~ %r!darwin!
780
725
  "-c2 #{server}"
781
726
  else
782
727
  "#{server} 2 2"
@@ -789,24 +734,45 @@ class Jumpstart
789
734
  end
790
735
  end
791
736
 
792
- def define_update_jumpstart
793
- url = ENV["RUBY_JUMPSTART"] || "git://github.com/quix/jumpstart.git"
794
- task :update_jumpstart do
795
- git "clone", url
796
- rm_rf "devel/jumpstart"
797
- Dir["jumpstart/**/*.rb"].each { |source|
798
- dest = source.sub(%r!\Ajumpstart/!, "devel/")
799
- dest_dir = File.dirname(dest)
800
- mkdir_p(dest_dir) unless File.directory?(dest_dir)
801
- cp source, dest
802
- }
803
- rm_r "jumpstart"
804
- git "commit", "devel", "-m", "update jumpstart"
737
+ def define_update_levitate
738
+ url = ENV["LEVITATE"] ||
739
+ "https://github.com/quix/levitate/raw/master/levitate.rb"
740
+ task :update_levitate do
741
+ if system "curl", "-s", "-o", __FILE__, url
742
+ if `git diff #{__FILE__}` == ""
743
+ puts "Already up-to-date."
744
+ else
745
+ git "commit", __FILE__, "-m", "updated levitate"
746
+ puts "Updated levitate."
747
+ end
748
+ else
749
+ raise "levitate download failed"
750
+ end
805
751
  end
806
752
  end
807
753
 
754
+ def define_changes
755
+ task :changes do
756
+ header = "\n\n== Version ____\n\n"
757
+
758
+ bullets = `git log --format=%s #{last_release}..HEAD`.lines.map { |line|
759
+ "* #{line}"
760
+ }.join.chomp
761
+
762
+ write_file(history_file) do
763
+ File.read(history_file).sub(/(?<=#{gem_name} Changes)/) {
764
+ header + bullets
765
+ }
766
+ end
767
+ end
768
+ end
769
+
770
+ def last_release
771
+ `git tag`.lines.select { |t| t.index(gem_name) == 0 }.last.chomp
772
+ end
773
+
808
774
  def git(*args)
809
- sh("git", *args)
775
+ sh "git", *args
810
776
  end
811
777
 
812
778
  def create_manifest
@@ -815,38 +781,16 @@ class Jumpstart
815
781
  }
816
782
  end
817
783
 
818
- def rubyforge(mode, file, *options)
819
- command = ["rubyforge", mode] + options + [
820
- rubyforge_name,
821
- rubyforge_name,
822
- version.to_s,
823
- file,
824
- ]
825
- sh(*command)
826
- end
827
-
828
784
  def define_release
829
785
  task :prerelease => [:clean, :check_directory, :ping, history_file]
830
786
 
831
787
  task :finish_release do
832
- gem_md5, tgz_md5 = [gem, tgz].map { |file|
833
- md5 = "#{file}.md5"
834
- sh("md5sum #{file} > #{md5}")
835
- md5
836
- }
837
-
838
- rubyforge(
839
- "add_release", gem, "--release_changes", history_file, "--preformatted"
840
- )
841
- [gem_md5, tgz, tgz_md5].each { |file|
842
- rubyforge("add_file", file)
843
- }
844
-
845
- git("tag", "#{name}-" + version.to_s)
846
- git(*%w(push --tags origin master))
788
+ git "tag", "#{gem_name}-" + version.to_s
789
+ git "push", "--tags", "origin", "master"
790
+ sh "gem", "push", gem
847
791
  end
848
792
 
849
- task :release => [:prerelease, :package, :publish, :finish_release]
793
+ task :release => [:prerelease, :package, :finish_release]
850
794
  end
851
795
 
852
796
  def define_debug_gem
@@ -859,6 +803,26 @@ class Jumpstart
859
803
  sh(*([browser].flatten + files))
860
804
  end
861
805
 
806
+ def suppress_task_warnings(*task_names)
807
+ task_names.each { |task_name|
808
+ Rake::Task[task_name].actions.map! { |action|
809
+ lambda { |*args|
810
+ Ruby.no_warnings {
811
+ action.call(*args)
812
+ }
813
+ }
814
+ }
815
+ }
816
+ end
817
+
818
+ def ruby_18?
819
+ RUBY_VERSION =~ %r!\A1\.8!
820
+ end
821
+
822
+ def source_control?
823
+ File.directory? ".git"
824
+ end
825
+
862
826
  class << self
863
827
  include Util
864
828
  include InstanceEvalWithArgs
@@ -883,12 +847,11 @@ class Jumpstart
883
847
  lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
884
848
  header = %{
885
849
  $LOAD_PATH.unshift "#{lib}"
886
- require 'rubygems'
887
850
  begin
888
851
  }
889
852
  footer = %{
890
- rescue Exception => __jumpstart_exception
891
- puts "raises \#{__jumpstart_exception.class}"
853
+ rescue Exception => __levitate_exception
854
+ puts "raises \#{__levitate_exception.class}"
892
855
  end
893
856
  }
894
857
  final_code = header + code + footer
@@ -931,15 +894,15 @@ class Jumpstart
931
894
  end
932
895
 
933
896
  def doc_to_spec(file, *sections, &block)
934
- jump = self
897
+ levitate = self
935
898
  describe file do
936
899
  sections.each { |section|
937
900
  describe "section `#{section}'" do
938
901
  it "should run as claimed" do
939
902
  if block
940
- jump.run_doc_section(file, section, self, &block)
903
+ levitate.run_doc_section(file, section, self, &block)
941
904
  else
942
- jump.run_doc_section(file, section, self) {
905
+ levitate.run_doc_section(file, section, self) {
943
906
  |expected, actual, index|
944
907
  actual.should == expected
945
908
  }
@@ -951,14 +914,14 @@ class Jumpstart
951
914
  end
952
915
 
953
916
  def doc_to_test(file, *sections, &block)
954
- jump = self
955
- klass = Class.new Test::Unit::TestCase do
917
+ levitate = self
918
+ klass = Class.new MiniTest::Unit::TestCase do
956
919
  sections.each { |section|
957
920
  define_method "test_#{file}_#{section}" do
958
921
  if block
959
- jump.run_doc_section(file, section, self, &block)
922
+ levitate.run_doc_section(file, section, self, &block)
960
923
  else
961
- jump.run_doc_section(file, section, self) {
924
+ levitate.run_doc_section(file, section, self) {
962
925
  |expected, actual, index|
963
926
  assert_equal expected, actual
964
927
  }