cond 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/CHANGES.rdoc +12 -0
  2. data/MANIFEST +39 -0
  3. data/{README → README.rdoc} +23 -28
  4. data/Rakefile +23 -180
  5. data/devel/jumpstart.rb +970 -0
  6. data/install.rb +2 -3
  7. data/lib/cond.rb +38 -453
  8. data/lib/cond/code_section.rb +51 -0
  9. data/lib/cond/cond.rb +159 -0
  10. data/lib/cond/defaults.rb +73 -0
  11. data/lib/cond/dsl.rb +2 -0
  12. data/lib/cond/dsl_definition.rb +74 -0
  13. data/lib/cond/error.rb +17 -0
  14. data/lib/cond/handler.rb +10 -0
  15. data/lib/cond/handling_section.rb +12 -0
  16. data/lib/cond/kernel_raise.rb +59 -0
  17. data/lib/cond/message_proc.rb +15 -0
  18. data/lib/cond/restart.rb +10 -0
  19. data/lib/cond/restartable_section.rb +12 -0
  20. data/lib/cond/symbol_generator.rb +41 -0
  21. data/lib/cond/thread_local.rb +71 -0
  22. data/lib/cond/wrapping.rb +45 -0
  23. data/readmes/restarts.rb +1 -2
  24. data/readmes/seibel_pcl.rb +1 -2
  25. data/{examples/bad_example.rb → spec/bad_spec.rb} +2 -2
  26. data/spec/basic_spec.rb +2 -2
  27. data/{examples/calc_example.rb → spec/calc_spec.rb} +2 -2
  28. data/spec/{common.rb → cond_spec_base.rb} +3 -20
  29. data/spec/error_spec.rb +2 -2
  30. data/spec/leave_again_spec.rb +10 -10
  31. data/spec/matching_spec.rb +1 -1
  32. data/spec/raise_spec.rb +1 -1
  33. data/spec/readme_spec.rb +10 -0
  34. data/spec/reraise_spec.rb +2 -2
  35. data/{examples/restarts_example.rb → spec/restarts_spec.rb} +7 -4
  36. data/{examples/seibel_example.rb → spec/seibel_spec.rb} +4 -6
  37. data/spec/symbols_spec.rb +2 -2
  38. data/spec/thread_local_spec.rb +8 -8
  39. data/spec/wrapping_spec.rb +2 -2
  40. metadata +110 -42
  41. data/cond.gemspec +0 -37
  42. data/examples/readme_example.rb +0 -27
  43. data/lib/cond/cond_private/defaults.rb +0 -78
  44. data/lib/cond/cond_private/symbol_generator.rb +0 -45
  45. data/lib/cond/cond_private/thread_local.rb +0 -77
  46. data/spec/specs_spec.rb +0 -16
  47. data/support/quix/ruby.rb +0 -51
  48. data/support/quix/simple_installer.rb +0 -88
@@ -1,77 +0,0 @@
1
-
2
- require 'thread'
3
- require 'cond/cond_private/symbol_generator'
4
-
5
- module Cond
6
- module CondPrivate
7
- #
8
- # Thread-local variable.
9
- #
10
- class ThreadLocal
11
- include SymbolGenerator
12
-
13
- #
14
- # If +value+ is called before +value=+ then the result of
15
- # &default is used.
16
- #
17
- # &default normally creates a new object, otherwise the returned
18
- # object will be shared across threads.
19
- #
20
- def initialize(&default)
21
- @name = gensym
22
- @accessed = gensym
23
- @default = default
24
- SymbolGenerator.track(self, [@name, @accessed])
25
- end
26
-
27
- #
28
- # Reset to just-initialized state for all threads.
29
- #
30
- def clear(&default)
31
- Thread.exclusive {
32
- @default = default
33
- Thread.list.each { |thread|
34
- thread[@accessed] = nil
35
- thread[@name] = nil
36
- }
37
- }
38
- end
39
-
40
- def value
41
- unless Thread.current[@accessed]
42
- if @default
43
- Thread.current[@name] = @default.call
44
- end
45
- Thread.current[@accessed] = true
46
- end
47
- Thread.current[@name]
48
- end
49
-
50
- def value=(value)
51
- Thread.current[@accessed] = true
52
- Thread.current[@name] = value
53
- end
54
-
55
- class << self
56
- def accessor_module(name, subclass = self, &block)
57
- var = subclass.new(&block)
58
- Module.new {
59
- define_method(name) {
60
- var.value
61
- }
62
- define_method("#{name}=") { |value|
63
- var.value = value
64
- }
65
- }
66
- end
67
-
68
- def reader_module(name, subclass = self, &block)
69
- accessor_module(name, subclass, &block).instance_eval {
70
- remove_method "#{name}="
71
- self
72
- }
73
- end
74
- end
75
- end
76
- end
77
- end
data/spec/specs_spec.rb DELETED
@@ -1,16 +0,0 @@
1
- here = File.dirname(__FILE__)
2
- require here + "/common"
3
-
4
- require 'quix/ruby'
5
-
6
- describe "specs" do
7
- it "should run individually" do
8
- (Dir["#{here}/*_spec.rb"] + Dir["#{here}/../examples/*_example.rb"]).each {
9
- |spec|
10
- unless File.basename(spec) == File.basename(__FILE__)
11
- `"#{Quix::Ruby::EXECUTABLE}" "#{spec}"`
12
- $?.exitstatus.should == 0
13
- end
14
- }
15
- end
16
- end
data/support/quix/ruby.rb DELETED
@@ -1,51 +0,0 @@
1
-
2
- require 'rbconfig'
3
-
4
- module Quix
5
- module Ruby
6
- EXECUTABLE = lambda {
7
- name = File.join(
8
- Config::CONFIG["bindir"],
9
- Config::CONFIG["RUBY_INSTALL_NAME"]
10
- )
11
-
12
- if Config::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
13
- File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
14
- name + ".exe"
15
- else
16
- name
17
- end
18
- }.call
19
-
20
- class << self
21
- def run(*args)
22
- system(EXECUTABLE, *args)
23
- end
24
-
25
- def run_or_raise(*args)
26
- cmd = [EXECUTABLE, *args]
27
- unless system(*cmd)
28
- msg = (
29
- "failed to launch ruby: " +
30
- "system(*#{cmd.inspect}) failed with status #{$?.exitstatus}"
31
- )
32
- raise msg
33
- end
34
- end
35
-
36
- def with_warnings(value = true)
37
- previous = $VERBOSE
38
- $VERBOSE = value
39
- begin
40
- yield
41
- ensure
42
- $VERBOSE = previous
43
- end
44
- end
45
-
46
- def no_warnings(&block)
47
- with_warnings(false, &block)
48
- end
49
- end
50
- end
51
- end
@@ -1,88 +0,0 @@
1
-
2
- require 'rbconfig'
3
- require 'fileutils'
4
- require 'find'
5
-
6
- module Quix
7
- class SimpleInstaller
8
- def initialize
9
- dest_root = Config::CONFIG["sitelibdir"]
10
- sources = []
11
- Find.find("./lib") { |source|
12
- if install_file?(source)
13
- sources << source
14
- end
15
- }
16
- @spec = sources.inject(Array.new) { |acc, source|
17
- if source == "./lib"
18
- acc
19
- else
20
- dest = File.join(dest_root, source.sub(%r!\A\./lib!, ""))
21
-
22
- install = lambda {
23
- if File.directory?(source)
24
- unless File.directory?(dest)
25
- puts "mkdir #{dest}"
26
- FileUtils.mkdir(dest)
27
- end
28
- else
29
- puts "install #{source} --> #{dest}"
30
- FileUtils.install(source, dest)
31
- end
32
- }
33
-
34
- uninstall = lambda {
35
- if File.directory?(source)
36
- if File.directory?(dest)
37
- puts "rmdir #{dest}"
38
- FileUtils.rmdir(dest)
39
- end
40
- else
41
- if File.file?(dest)
42
- puts "rm #{dest}"
43
- FileUtils.rm(dest)
44
- end
45
- end
46
- }
47
-
48
- acc << {
49
- :source => source,
50
- :dest => dest,
51
- :install => install,
52
- :uninstall => uninstall,
53
- }
54
- end
55
- }
56
- end
57
-
58
- def install_file?(source)
59
- !File.symlink?(source) and
60
- (File.directory?(source) or
61
- (File.file?(source) and File.extname(source) == ".rb"))
62
- end
63
-
64
- attr_accessor :spec
65
-
66
- def install
67
- @spec.each { |entry|
68
- entry[:install].call
69
- }
70
- end
71
-
72
- def uninstall
73
- @spec.reverse.each { |entry|
74
- entry[:uninstall].call
75
- }
76
- end
77
-
78
- def run(args = ARGV)
79
- if args.empty? or (args.size == 1 and args.first == "install")
80
- install
81
- elsif args.size == 1 and args.first == "--uninstall"
82
- uninstall
83
- else
84
- raise "unrecognized arguments: #{args.inspect}"
85
- end
86
- end
87
- end
88
- end