rescue-me 0.9.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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - ree
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rescue-me.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ if RUBY_PLATFORM =~ /darwin/i
8
+ gem 'rb-fsevent'
9
+ gem 'ruby_gntp'
10
+ else
11
+ gem 'rb-fsevent', :require => false
12
+ gem 'growl', :require => false
13
+ end
14
+ if RUBY_PLATFORM =~ /linux/i
15
+ gem 'rb-inotify'
16
+ gem 'libnotify'
17
+ else
18
+ gem 'rb-inotify', :require => false
19
+ gem 'libnotify', :require => false
20
+ end
21
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'rspec', :version => 2, :cli => '-c --format progress', :all_on_start => false do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ryan Schlesinger
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RescueMe [![Build Status](https://secure.travis-ci.org/ryansch/rescue-me.png?branch=master)](http://travis-ci.org/ryansch/rescue-me)
2
+
3
+ Instead of hardcoding lists of exceptions to rescue, put them in one place!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rescue-me'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rescue-me
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = ["-c", "--format progress"]
7
+ end
8
+
9
+ task :default => :spec
data/lib/rescue-me.rb ADDED
@@ -0,0 +1,81 @@
1
+ require "rescue_me/version"
2
+ require 'net/http'
3
+ require 'net/smtp'
4
+
5
+ # Example:
6
+ # begin
7
+ # method_here
8
+ # rescue RescueMe.net_http_errors => error
9
+ # notify_airbrake error
10
+ # end
11
+
12
+ module RescueMe
13
+ extend self
14
+
15
+ def net_http_errors(opts = {})
16
+ err = [Timeout::Error,
17
+ Errno::EINVAL,
18
+ Errno::ECONNRESET,
19
+ EOFError,
20
+ SocketError,
21
+ Net::HTTPBadResponse,
22
+ Net::HTTPHeaderSyntaxError,
23
+ Net::ProtocolError]
24
+
25
+ err << Net::HTTP::Persistent::Error if defined? Net::HTTP::Persistent::Error
26
+
27
+ err
28
+ end
29
+
30
+ def net_smtp_server_errors(opts = {})
31
+ with_auth = opts.fetch(:with_auth, true)
32
+
33
+ err = [Timeout::Error,
34
+ IOError,
35
+ Net::SMTPUnknownError,
36
+ Net::SMTPServerBusy]
37
+
38
+ err << Net::SMTPAuthenticationError if with_auth
39
+
40
+ err
41
+ end
42
+
43
+ def net_smtp_client_errors(opts = {})
44
+ with_auth = opts.fetch(:with_auth, false)
45
+
46
+ err = [Net::SMTPFatalError,
47
+ Net::SMTPSyntaxError]
48
+
49
+ err << Net::SMTPAuthenticationError if with_auth
50
+
51
+ err
52
+ end
53
+
54
+ def net_smtp_errors(opts = {})
55
+ net_smtp_server_errors + net_smtp_client_errors
56
+ end
57
+
58
+ %w[net_http net_smtp_server net_smtp_client net_smtp].each do |type|
59
+ define_method(type + '_errors_with') do |arg, *opts|
60
+ opts = opts.first || Hash.new
61
+ errors_with((type + '_errors').to_sym, arg, opts)
62
+ end
63
+ end
64
+
65
+ private
66
+ def errors_with(errors_sym, arg, opts = {})
67
+ if arg.kind_of? Array
68
+ ary = arg
69
+ elsif arg.is_a?(Class) && arg.ancestors.include?(Exception)
70
+ ary = [arg]
71
+ elsif arg.respond_to?(:each)
72
+ ary = []
73
+ arg.each {|a| ary << a }
74
+ else
75
+ raise ArgumentError, "Must be an Array, Exception, or respond to each."
76
+ end
77
+
78
+ self.send(errors_sym, opts) + ary
79
+ end
80
+ end
81
+
@@ -0,0 +1,3 @@
1
+ module RescueMe
2
+ VERSION = "0.9.0"
3
+ end
data/rescue-me.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rescue_me/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ryan Schlesinger"]
6
+ gem.email = ["ryan@instanceinc.com"]
7
+ gem.summary = %q{Provides common exception rescue lists}
8
+ gem.description = %q{Instead of hardcoding lists of exceptions to rescue, put them in one place!}
9
+ gem.homepage = "http://github.com/ryansch/rescue-me"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "rescue-me"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = RescueMe::VERSION
17
+
18
+ gem.add_development_dependency 'rspec', '~> 2.7.0'
19
+ gem.add_development_dependency 'rake', '~> 0.9.2'
20
+ gem.add_development_dependency "guard", "~> 0.10.0"
21
+ gem.add_development_dependency "guard-rspec", "~> 0.6.0"
22
+ gem.add_development_dependency "guard-bundler", "~> 0.1.3"
23
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe RescueMe do
4
+ subject { RescueMe }
5
+
6
+ def should_return_a_list_of_errors(method)
7
+ errors = subject.send(method)
8
+ errors.class.should == Array
9
+ errors.empty?.should be_false
10
+ end
11
+
12
+ describe '.net_http_errors' do
13
+ before :each do
14
+ Net::HTTP.send(:remove_const, :Persistent) if defined? Net::HTTP::Persistent
15
+ end
16
+
17
+ it 'should return a list of errors' do
18
+ should_return_a_list_of_errors(:net_http_errors)
19
+ end
20
+
21
+ it 'should include Net::HTTP:Persistent::Error if that library is defined' do
22
+ class Net::HTTP::Persistent
23
+ class Error < Exception; end
24
+ end
25
+
26
+ subject.net_http_errors.include?(Net::HTTP::Persistent::Error).should be_true
27
+ end
28
+
29
+ it 'should not include Net::HTTP:Persistent::Error if that library is not defined' do
30
+ errors = subject.net_http_errors
31
+
32
+ # Define this after the method so we can ask the array if it's included.
33
+ class Net::HTTP::Persistent
34
+ class Error < Exception; end
35
+ end
36
+
37
+ errors.include?(Net::HTTP::Persistent::Error).should be_false
38
+ end
39
+ end
40
+
41
+ describe '.net_smtp_server_errors' do
42
+ it 'should return a list of errors' do
43
+ should_return_a_list_of_errors(:net_smtp_server_errors)
44
+ end
45
+
46
+ it 'should include Net::SMTPAuthenticationError' do
47
+ subject.net_smtp_server_errors.include?(Net::SMTPAuthenticationError).should be_true
48
+ end
49
+
50
+ it 'should not include Net::SMTPAuthenticationError when disabled' do
51
+ subject.net_smtp_server_errors(:with_auth => false).include?(Net::SMTPAuthenticationError).should be_false
52
+ end
53
+ end
54
+
55
+ describe '.net_smtp_client_errors' do
56
+ it 'should return a list of errors' do
57
+ should_return_a_list_of_errors(:net_smtp_client_errors)
58
+ end
59
+
60
+ it 'should not include Net::SMTPAuthenticationError' do
61
+ subject.net_smtp_client_errors.include?(Net::SMTPAuthenticationError).should be_false
62
+ end
63
+ it 'should include Net::SMTPAuthenticationError when enabled' do
64
+ subject.net_smtp_client_errors(:with_auth => true).include?(Net::SMTPAuthenticationError).should be_true
65
+ end
66
+ end
67
+
68
+ describe '.net_smtp_errors' do
69
+ it 'should return a list of errors' do
70
+ should_return_a_list_of_errors(:net_smtp_errors)
71
+ end
72
+ end
73
+
74
+ context 'errors with' do
75
+ before :all do
76
+ class FooError < StandardError; end
77
+ class BarError < StandardError; end
78
+ class OrigError < StandardError; end
79
+ end
80
+
81
+ let(:test_ary) { [FooError, BarError] }
82
+
83
+ before :each do
84
+ subject.stub(:errors => [OrigError])
85
+ end
86
+
87
+ context 'a passed array' do
88
+ it 'should include the array' do
89
+ errors = subject.send(:errors_with, :errors, test_ary)
90
+
91
+ test_ary.each do |a|
92
+ errors.include?(a).should be_true
93
+ end
94
+ end
95
+
96
+ it 'should have the original elements' do
97
+ subject.send(:errors_with, :errors, [FooError, BarError]).include?(OrigError).should be_true
98
+ end
99
+ end
100
+
101
+ context 'a single exception' do
102
+ it 'should add the exception' do
103
+ subject.send(:errors_with, :errors, FooError).include?(FooError).should be_true
104
+ end
105
+
106
+ it 'should have the original elements' do
107
+ subject.send(:errors_with, :errors, FooError).include?(OrigError).should be_true
108
+ end
109
+ end
110
+
111
+ context 'a set' do
112
+ let(:set) { Set.new(test_ary) }
113
+
114
+ it 'should add the elements of the set' do
115
+ errors = subject.send(:errors_with, :errors, set)
116
+
117
+ set.each do |s|
118
+ errors.include?(s).should be_true
119
+ end
120
+ end
121
+
122
+ it 'should have the original elements' do
123
+ errors = subject.send(:errors_with, :errors, set).include?(OrigError).should be_true
124
+ end
125
+ end
126
+
127
+ it 'should raise an ArgumentError when a bad argument is passed' do
128
+ lambda { subject.send(:errors_with, :errors, 42) }.should raise_error ArgumentError
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,7 @@
1
+ require 'rescue-me'
2
+
3
+ RSpec.configure do |c|
4
+ c.filter_run :focus => true
5
+ c.run_all_when_everything_filtered = true
6
+ c.treat_symbols_as_metadata_keys_with_true_values = true
7
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rescue-me
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Schlesinger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70360855075900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70360855075900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70360855075320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70360855075320
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard
38
+ requirement: &70360855074720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.10.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70360855074720
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-rspec
49
+ requirement: &70360855074000 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70360855074000
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-bundler
60
+ requirement: &70360855073160 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.1.3
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70360855073160
69
+ description: Instead of hardcoding lists of exceptions to rescue, put them in one
70
+ place!
71
+ email:
72
+ - ryan@instanceinc.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .travis.yml
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - lib/rescue-me.rb
85
+ - lib/rescue_me/version.rb
86
+ - rescue-me.gemspec
87
+ - spec/lib/rescue-me_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: http://github.com/ryansch/rescue-me
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.10
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Provides common exception rescue lists
113
+ test_files:
114
+ - spec/lib/rescue-me_spec.rb
115
+ - spec/spec_helper.rb