mattscilipoti-nestegg 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ #IDE related
2
+ .idea
data/History.txt ADDED
@@ -0,0 +1,16 @@
1
+ == 0.0.4 2009-10-07
2
+
3
+ * Message defaults to cause's message
4
+
5
+ == 0.0.3
6
+
7
+ * Can pass message to Nesting Exception
8
+
9
+ == 0.0.2 2007-06-26
10
+
11
+ * Minor tweaks to backtrace formatting and addition of example code.
12
+
13
+ == 0.0.1 2007-06-24
14
+
15
+ * 1 major enhancement:
16
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 FIXME full name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,19 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ examples/nestegg_example.rb
7
+ lib/nestegg.rb
8
+ lib/nestegg/nesting_exception.rb
9
+ lib/nestegg/version.rb
10
+ scripts/txt2html
11
+ setup.rb
12
+ spec/nestegg/nesting_exception_spec.rb
13
+ spec/spec.opts
14
+ spec/spec_helper.rb
15
+ website/index.html
16
+ website/index.txt
17
+ website/javascripts/rounded_corners_lite.inc.js
18
+ website/stylesheets/screen.css
19
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,3 @@
1
+ git con= Nestegg
2
+
3
+ * http://nestegg.rubyforge.org
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "mattscilipoti-nestegg"
5
+ gemspec.summary = "Nested exceptions for ruby"
6
+ gemspec.description = "Module to add a 'cause' field to exceptions and automatically chains exceptions on re-raise"
7
+ gemspec.email = "matt at scilipoti.name"
8
+ gemspec.homepage = "http://nestegg.rubyforge.org"
9
+ gemspec.authors = ["John D. Hume, Matt Scilipoti"]
10
+ end
11
+ rescue LoadError
12
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
13
+ return
14
+ end
15
+
16
+ begin
17
+ require 'spec/rake/spectask'
18
+ rescue LoadError
19
+ puts 'To use rspec for testing you must install rspec gem:'
20
+ puts '$ sudo gem install rspec'
21
+ exit
22
+ end
23
+
24
+ Spec::Rake::SpecTask.new do |t|
25
+ t.spec_opts = ['--options', "spec/spec.opts"]
26
+ t.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.4
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'nestegg'
3
+
4
+ class ConfigurationError < StandardError
5
+ include Nestegg::NestingException
6
+ end
7
+
8
+ def read_config_file
9
+ File.open('missing_config_file') do |f|
10
+ f.readlines
11
+ end
12
+ end
13
+
14
+ def load_config
15
+ begin
16
+ lines = read_config_file
17
+ # ... then use it to do stuff
18
+ # ... stuff that might fail for other reasons
19
+ rescue
20
+ raise ConfigurationError
21
+ end
22
+ end
23
+
24
+ load_config
data/lib/nestegg.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'nestegg/version'
2
+ require 'nestegg/nesting_exception'
@@ -0,0 +1,27 @@
1
+ module Nestegg
2
+ module NestingException
3
+
4
+ attr_reader :cause
5
+
6
+ def initialize message = nil, cause = $!
7
+ @cause = cause
8
+ super(message ||= cause.message)
9
+ end
10
+
11
+ def set_backtrace bt
12
+ if cause
13
+ cause.backtrace.reverse.each do |line|
14
+ if bt.last == line
15
+ bt.pop
16
+ else
17
+ break
18
+ end
19
+ end
20
+ bt << "cause: #{cause.class.name}: #{cause}"
21
+ bt.concat cause.backtrace
22
+ end
23
+ super bt
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module Nestegg #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 2
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+
3
+ describe Nestegg::NestingException do
4
+
5
+ class TestNestingError < StandardError
6
+ include Nestegg::NestingException
7
+ end
8
+
9
+ def create_cause(klass = StandardError, message = "cause msg", backtrace = ["line_one", "line_two"])
10
+ e = klass.new(message)
11
+ e.set_backtrace backtrace
12
+ e
13
+ end
14
+
15
+ def with_exception exception
16
+ begin
17
+ raise exception
18
+ rescue exception.class => e
19
+ yield e
20
+ end
21
+ end
22
+
23
+ it "includes cause in backtrace" do
24
+ cause = create_cause(StandardError)
25
+ with_exception TestNestingError.new("some message", cause) do |e|
26
+ e.backtrace.should include("cause: StandardError: #{cause.message}")
27
+ end
28
+ end
29
+
30
+ it "includes cause's backtrace after cause in backtrace" do
31
+ cause = create_cause(StandardError)
32
+ with_exception TestNestingError.new("some message", cause) do |e|
33
+ e.backtrace[-3..-1].should == ["cause: StandardError: #{cause.message}", "line_one", "line_two"]
34
+ end
35
+ end
36
+
37
+ it "removes duplicated backtrace elements from nesting exception" do
38
+ cause_bt = caller.unshift "some_other_line"
39
+ cause = create_cause(StandardError, "msg", cause_bt)
40
+ begin
41
+ line = __LINE__ + 1
42
+ raise TestNestingError.new("msg", cause)
43
+ rescue TestNestingError => e
44
+ e.backtrace[0..1].should == ["#{__FILE__}:#{line}", "cause: StandardError: msg"]
45
+ end
46
+ end
47
+
48
+ it "defaults cause to current raised exception ($!)" do
49
+ expected_cause = StandardError.new
50
+ raised_error = nil
51
+ begin
52
+ begin
53
+ raise expected_cause
54
+ rescue
55
+ raise TestNestingError
56
+ end
57
+ rescue TestNestingError => e
58
+ raised_error = e
59
+ end
60
+ raised_error.cause.should == expected_cause
61
+ end
62
+
63
+ it "uses passed message" do
64
+ begin
65
+ begin
66
+ raise StandardError, 'STD MSG'
67
+ rescue StandardError
68
+ raise TestNestingError, 'NESTED MESSAGE'
69
+ end
70
+ rescue TestNestingError => e
71
+ e.message.should == 'NESTED MESSAGE'
72
+ end
73
+ end
74
+
75
+ it "defaults message to cause's message" do
76
+ begin
77
+ begin
78
+ raise StandardError, 'STD MSG'
79
+ rescue StandardError
80
+ raise TestNestingError
81
+ end
82
+ rescue TestNestingError => e
83
+ e.message.should == 'STD MSG'
84
+ end
85
+ end
86
+
87
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour -f specdoc
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ #Replaced this `require` with `$LOAD_PATH.unshift`
5
+ #to ensure the file is used instead of the gem.
6
+ #lib/nestegg.rb was loading nestegg/version from the gem
7
+ #instead of lib/nestegg/version.rb
8
+ #require File.dirname(__FILE__) + '/../lib/nestegg'
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
10
+ require 'nestegg'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mattscilipoti-nestegg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - John D. Hume, Matt Scilipoti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-08 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Module to add a 'cause' field to exceptions and automatically chains exceptions on re-raise
17
+ email: matt at scilipoti.name
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.txt
24
+ files:
25
+ - .gitignore
26
+ - History.txt
27
+ - License.txt
28
+ - Manifest.txt
29
+ - README.txt
30
+ - Rakefile
31
+ - VERSION
32
+ - examples/nestegg_example.rb
33
+ - lib/nestegg.rb
34
+ - lib/nestegg/nesting_exception.rb
35
+ - lib/nestegg/version.rb
36
+ - spec/nestegg/nesting_exception_spec.rb
37
+ - spec/spec.opts
38
+ - spec/spec_helper.rb
39
+ has_rdoc: true
40
+ homepage: http://nestegg.rubyforge.org
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --charset=UTF-8
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.4
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Nested exceptions for ruby
67
+ test_files:
68
+ - spec/nestegg/nesting_exception_spec.rb
69
+ - spec/spec_helper.rb
70
+ - examples/nestegg_example.rb