cond 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/spec/symbols_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/common"
1
+ require File.dirname(__FILE__) + '/cond_spec_base'
2
2
 
3
3
  #
4
4
  # Try to demonstrate symbol recycling by calling GC.start on each pass
@@ -21,7 +21,7 @@ describe "generated symbols" do
21
21
  histogram = Hash.new { |hash, key| hash[key] = 0 }
22
22
 
23
23
  300.times { |n|
24
- obj = Cond::CondPrivate::CodeSection.new(:foo)
24
+ obj = Cond::CodeSection.new(:foo)
25
25
  leave, again = obj.instance_eval { [@leave, @again] }
26
26
  histogram[leave] += 1
27
27
  histogram[again] += 1
@@ -1,10 +1,10 @@
1
- require File.dirname(__FILE__) + "/common"
1
+ require File.dirname(__FILE__) + '/cond_spec_base'
2
2
 
3
3
  require 'ostruct'
4
4
 
5
5
  describe "ThreadLocal" do
6
6
  it "should keep independent values in separate threads" do
7
- a = Cond::CondPrivate::ThreadLocal.new { OpenStruct.new }
7
+ a = Cond::ThreadLocal.new { OpenStruct.new }
8
8
  a.value.x = 33
9
9
  other_value = nil
10
10
  Thread.new {
@@ -12,18 +12,18 @@ describe "ThreadLocal" do
12
12
  other_value = a.value.x
13
13
  }.join
14
14
 
15
- a.value.x.should == 33
16
- other_value.should == 44
15
+ a.value.x.should eql(33)
16
+ other_value.should eql(44)
17
17
  a.clear { 99 }
18
- a.value.should == 99
18
+ a.value.should eql(99)
19
19
  end
20
20
 
21
21
  it "should work with included accessor_module" do
22
22
  a = Class.new {
23
- include Cond::CondPrivate::ThreadLocal.accessor_module(:x) { 33 }
23
+ include Cond::ThreadLocal.accessor_module(:x) { 33 }
24
24
  }.new
25
- a.x.should == 33
25
+ a.x.should eql(33)
26
26
  a.x = 44
27
- a.x.should == 44
27
+ a.x.should eql(44)
28
28
  end
29
29
  end
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + "/common"
1
+ require File.dirname(__FILE__) + '/cond_spec_base'
2
2
 
3
- include Cond
3
+ require 'cond/dsl'
4
4
 
5
5
  describe "singleton method defined in C" do
6
6
  before :all do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cond
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James M. Lawrence
@@ -9,65 +9,133 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-22 00:00:00 -04:00
12
+ date: 2009-09-13 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: +Cond+ allows errors to be handled at the place where they occur. You decide whether or not the stack should be unwound, depending on the circumstance and the error.
17
- email: quixoticsycophant@gmail.com
16
+ description: Cond allows errors to be handled near the place where they occur, before the stack unwinds. It offers several advantages over exceptions while peacefully coexisting with the standard exception behavior.
17
+ email:
18
+ - quixoticsycophant@gmail.com
18
19
  executables: []
19
20
 
20
21
  extensions: []
21
22
 
22
23
  extra_rdoc_files:
23
- - README
24
+ - README.rdoc
24
25
  files:
25
- - README
26
- - cond.gemspec
27
- - ./examples/bad_example.rb
28
- - ./examples/calc_example.rb
29
- - ./examples/readme_example.rb
30
- - ./examples/restarts_example.rb
31
- - ./examples/seibel_example.rb
32
- - ./install.rb
33
- - ./lib/cond/cond_private/defaults.rb
34
- - ./lib/cond/cond_private/symbol_generator.rb
35
- - ./lib/cond/cond_private/thread_local.rb
36
- - ./lib/cond.rb
37
- - ./readmes/restarts.rb
38
- - ./readmes/seibel_pcl.rb
39
- - ./spec/basic_spec.rb
40
- - ./spec/common.rb
41
- - ./spec/error_spec.rb
42
- - ./spec/leave_again_spec.rb
43
- - ./spec/matching_spec.rb
44
- - ./spec/raise_spec.rb
45
- - ./spec/reraise_spec.rb
46
- - ./spec/specs_spec.rb
47
- - ./spec/symbols_spec.rb
48
- - ./spec/thread_local_spec.rb
49
- - ./spec/wrapping_spec.rb
50
- - ./support/quix/ruby.rb
51
- - ./support/quix/simple_installer.rb
52
- - ./Rakefile
26
+ - CHANGES.rdoc
27
+ - README.rdoc
28
+ - Rakefile
29
+ - devel/jumpstart.rb
30
+ - install.rb
31
+ - lib/cond.rb
32
+ - lib/cond/code_section.rb
33
+ - lib/cond/cond.rb
34
+ - lib/cond/defaults.rb
35
+ - lib/cond/dsl.rb
36
+ - lib/cond/dsl_definition.rb
37
+ - lib/cond/error.rb
38
+ - lib/cond/handler.rb
39
+ - lib/cond/handling_section.rb
40
+ - lib/cond/kernel_raise.rb
41
+ - lib/cond/message_proc.rb
42
+ - lib/cond/restart.rb
43
+ - lib/cond/restartable_section.rb
44
+ - lib/cond/symbol_generator.rb
45
+ - lib/cond/thread_local.rb
46
+ - lib/cond/wrapping.rb
47
+ - readmes/restarts.rb
48
+ - readmes/seibel_pcl.rb
49
+ - spec/bad_spec.rb
50
+ - spec/basic_spec.rb
51
+ - spec/calc_spec.rb
52
+ - spec/cond_spec_base.rb
53
+ - spec/error_spec.rb
54
+ - spec/leave_again_spec.rb
55
+ - spec/matching_spec.rb
56
+ - spec/raise_spec.rb
57
+ - spec/readme_spec.rb
58
+ - spec/reraise_spec.rb
59
+ - spec/restarts_spec.rb
60
+ - spec/seibel_spec.rb
61
+ - spec/symbols_spec.rb
62
+ - spec/thread_local_spec.rb
63
+ - spec/wrapping_spec.rb
64
+ - MANIFEST
53
65
  has_rdoc: true
54
- homepage: cond.rubyforge.org
66
+ homepage: http://cond.rubyforge.org
67
+ licenses: []
68
+
55
69
  post_install_message:
56
70
  rdoc_options:
57
71
  - --main
58
- - README
72
+ - README.rdoc
59
73
  - --title
60
74
  - "cond: Resolve errors without unwinding the stack."
61
75
  - --exclude
62
- - spec
76
+ - CHANGES.rdoc
77
+ - --exclude
78
+ - README.rdoc
79
+ - --exclude
80
+ - Rakefile
81
+ - --exclude
82
+ - devel/jumpstart.rb
83
+ - --exclude
84
+ - install.rb
85
+ - --exclude
86
+ - lib/cond.rb
87
+ - --exclude
88
+ - lib/cond/code_section.rb
89
+ - --exclude
90
+ - lib/cond/defaults.rb
91
+ - --exclude
92
+ - lib/cond/dsl.rb
93
+ - --exclude
94
+ - lib/cond/handling_section.rb
95
+ - --exclude
96
+ - lib/cond/kernel_raise.rb
97
+ - --exclude
98
+ - lib/cond/restartable_section.rb
99
+ - --exclude
100
+ - lib/cond/symbol_generator.rb
101
+ - --exclude
102
+ - lib/cond/thread_local.rb
103
+ - --exclude
104
+ - readmes/restarts.rb
105
+ - --exclude
106
+ - readmes/seibel_pcl.rb
107
+ - --exclude
108
+ - spec/bad_spec.rb
109
+ - --exclude
110
+ - spec/basic_spec.rb
111
+ - --exclude
112
+ - spec/calc_spec.rb
113
+ - --exclude
114
+ - spec/cond_spec_base.rb
115
+ - --exclude
116
+ - spec/error_spec.rb
117
+ - --exclude
118
+ - spec/leave_again_spec.rb
119
+ - --exclude
120
+ - spec/matching_spec.rb
121
+ - --exclude
122
+ - spec/raise_spec.rb
123
+ - --exclude
124
+ - spec/readme_spec.rb
125
+ - --exclude
126
+ - spec/reraise_spec.rb
127
+ - --exclude
128
+ - spec/restarts_spec.rb
129
+ - --exclude
130
+ - spec/seibel_spec.rb
63
131
  - --exclude
64
- - examples
132
+ - spec/symbols_spec.rb
65
133
  - --exclude
66
- - readmes
134
+ - spec/thread_local_spec.rb
67
135
  - --exclude
68
- - support
136
+ - spec/wrapping_spec.rb
69
137
  - --exclude
70
- - lib/cond/cond_private
138
+ - MANIFEST
71
139
  require_paths:
72
140
  - lib
73
141
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -85,9 +153,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
153
  requirements: []
86
154
 
87
155
  rubyforge_project: cond
88
- rubygems_version: 1.3.1
156
+ rubygems_version: 1.3.5
89
157
  signing_key:
90
- specification_version: 2
158
+ specification_version: 3
91
159
  summary: Resolve errors without unwinding the stack.
92
160
  test_files: []
93
161
 
data/cond.gemspec DELETED
@@ -1,37 +0,0 @@
1
-
2
- Gem::Specification.new { |t|
3
- t.author = "James M. Lawrence"
4
- t.email = "quixoticsycophant@gmail.com"
5
- t.summary = "Resolve errors without unwinding the stack."
6
- t.name = "cond"
7
- t.rubyforge_project = t.name
8
- t.homepage = "#{t.name}.rubyforge.org"
9
- t.version = "0.2.1"
10
- t.description = <<-EOS
11
- +Cond+ allows errors to be handled at the place where they occur.
12
- You decide whether or not the stack should be unwound, depending on
13
- the circumstance and the error.
14
- EOS
15
- t.files = (
16
- %W[README #{t.name}.gemspec] +
17
- Dir["./**/*.rb"] +
18
- Dir["./**/Rakefile"]
19
- )
20
- rdoc_exclude = %w[
21
- spec
22
- examples
23
- readmes
24
- support
25
- lib/cond/cond_private
26
- ]
27
- t.has_rdoc = true
28
- t.extra_rdoc_files = %w[README]
29
- t.rdoc_options += [
30
- "--main",
31
- "README",
32
- "--title",
33
- "#{t.name}: #{t.summary}",
34
- ] + rdoc_exclude.inject(Array.new) { |acc, pattern|
35
- acc + ["--exclude", pattern]
36
- }
37
- }
@@ -1,27 +0,0 @@
1
- require File.dirname(__FILE__) + "/../spec/common"
2
-
3
- require 'quix/ruby'
4
-
5
- root = Pathname(__FILE__).dirname + ".."
6
- file = root + "README"
7
- lib = root + "lib"
8
-
9
- describe file do
10
- ["Synopsis",
11
- "Raw Form",
12
- "Synopsis 2.0",
13
- ].each { |section|
14
- it "#{section} should run as claimed" do
15
- contents = file.read
16
-
17
- code = %{
18
- $LOAD_PATH.unshift "#{lib.expand_path}"
19
- require 'cond'
20
- include Cond
21
- } + contents.match(%r!== #{section}.*?\n(.*?)^\S!m)[1]
22
-
23
- expected = code.scan(%r!\# => (.*?)\n!).flatten.join("\n")
24
- pipe_to_ruby(code).chomp.should == expected
25
- end
26
- }
27
- end
@@ -1,78 +0,0 @@
1
-
2
- require 'cond/cond_private/symbol_generator'
3
- require 'enumerator' if RUBY_VERSION <= "1.8.6"
4
-
5
- module Cond
6
- module CondPrivate
7
- class Defaults
8
- def initialize
9
- @stream_in = STDIN
10
- @stream_out = STDERR
11
- end
12
-
13
- attr_accessor :stream_in, :stream_out
14
-
15
- def handlers
16
- {
17
- Exception => method(:handler)
18
- }
19
- end
20
-
21
- def handler(exception)
22
- stream_out.puts exception.backtrace.last
23
-
24
- if exception.respond_to? :message
25
- stream_out.puts exception.message, ""
26
- end
27
-
28
- #
29
- # Show restarts in the order they appear on the stack (via
30
- # partial differences).
31
- #
32
- # grr:
33
- #
34
- # % ruby186 -ve 'p({:x => 33}.eql?({:x => 33}))'
35
- # ruby 1.8.6 (2009-03-10 patchlevel 362) [i686-darwin9.6.0]
36
- # false
37
- #
38
- # % ruby187 -ve 'p({:x => 33}.eql?({:x => 33}))'
39
- # ruby 1.8.7 (2009-03-09 patchlevel 150) [i686-darwin9.6.0]
40
- # true
41
- #
42
- stack_arrays = Cond.restarts_stack.map { |level|
43
- level.to_a.sort_by { |t| t.first.to_s }
44
- }
45
- restart_names = stack_arrays.to_enum(:each_with_index).map {
46
- |level, index|
47
- if index == 0
48
- level
49
- else
50
- level - stack_arrays[index - 1]
51
- end
52
- }.map { |level| level.map { |t| t.first } }.flatten
53
-
54
- restart_index = loop {
55
- restart_names.each_with_index { |name, index|
56
- func = Cond.available_restarts[name]
57
- message = (
58
- if func.respond_to?(:message) and func.message != ""
59
- func.message + " "
60
- else
61
- ""
62
- end
63
- )
64
- stream_out.printf("%3d: %s(%s)\n", index, message, name.inspect)
65
- }
66
- stream_out.print "Choose number: "
67
- stream_out.flush
68
- input = stream_in.readline.strip
69
- if input =~ %r!\A\d+\Z! and
70
- (0...restart_names.size).include?(input.to_i)
71
- break input.to_i
72
- end
73
- }
74
- Cond.invoke_restart(restart_names[restart_index])
75
- end
76
- end
77
- end
78
- end
@@ -1,45 +0,0 @@
1
-
2
- require 'thread'
3
-
4
- module Cond
5
- module CondPrivate
6
- module SymbolGenerator
7
- @count = 'a'
8
- @mutex = Mutex.new
9
- @recycled = []
10
- @object_id_to_sym_list = Hash.new
11
- @finalizer = lambda { |id|
12
- recycle(@object_id_to_sym_list.delete(id))
13
- }
14
-
15
- class << self
16
- def gensym
17
- @mutex.synchronize {
18
- if @recycled.empty?
19
- @count.succ!
20
- :"|#{@count}"
21
- else
22
- @recycled.shift
23
- end
24
- }
25
- end
26
-
27
- def recycle(syms)
28
- @mutex.synchronize {
29
- @recycled.concat(syms)
30
- }
31
- end
32
-
33
- def track(object, syms)
34
- @mutex.synchronize {
35
- @object_id_to_sym_list[object.object_id] = syms.dup
36
- ObjectSpace.define_finalizer(object, @finalizer)
37
- }
38
- end
39
- end
40
-
41
- define_method :gensym, &method(:gensym)
42
- private :gensym
43
- end
44
- end
45
- end