rescuer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb1cf739c264df062124c8278d07ae5c5045b82c
4
+ data.tar.gz: 9202313bc83a069afc537d62a6c64074d969b8f0
5
+ SHA512:
6
+ metadata.gz: e2092f82656031cce05dd6eee1a75d0b8c6a49fee76a649c2456528ab054ec910b8467bd3e42d3846a01d695358de487cfcbe44e370ff5347a60516bb0bcb235
7
+ data.tar.gz: 7d61b9f169eb50a91a2cdaf87a03d40b3ad3166ad2ff4a603e7d705eb3726410a590d10a62a5dbcc1ec60281479d928b7cf705233d0f03cb0103da59a7eb7673
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /.idea
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1,2 @@
1
+ rescuer
2
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.0
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - 1.9.2
8
+ - jruby-19mode
9
+ - rbx-2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify gem's dependencies in rescuer.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Marc Siegel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Rescuer
2
+ [![Gem Version](https://badge.fury.io/rb/rescuer.png)](http://badge.fury.io/rb/rescuer)
3
+ [![Build Status](https://travis-ci.org/ms-ati/rescuer.png)](https://travis-ci.org/ms-ati/rescuer)
4
+ [![Dependency Status](https://gemnasium.com/ms-ati/rescuer.png)](https://gemnasium.com/ms-ati/rescuer)
5
+ [![Code Climate](https://codeclimate.com/github/ms-ati/rescuer.png)](https://codeclimate.com/github/ms-ati/rescuer)
6
+ [![Coverage Status](https://coveralls.io/repos/ms-ati/rescuer/badge.png)](https://coveralls.io/r/ms-ati/rescuer)
7
+
8
+ A functional abstraction of rescuing exceptions inspired by Scala's Try class
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rake/clean'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Default task for `rake` is to run rspec
6
+ task :default => [:spec]
7
+
8
+ # Use default rspec rake task
9
+ RSpec::Core::RakeTask.new
10
+
11
+ # Configure `rake clobber` to delete all generated files
12
+ CLOBBER.include('pkg', 'doc', 'coverage')
13
+
14
+ # Only configure yard doc generation when *not* on Travis or JRuby
15
+ if ENV['CI'] != 'true' && !(defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
16
+ require 'github/markup'
17
+ require 'redcarpet'
18
+ require 'yard'
19
+ require 'yard/rake/yardoc_task'
20
+
21
+ YARD::Rake::YardocTask.new do |t|
22
+ OTHER_PATHS = %w()
23
+ t.files = ['lib/**/*.rb', OTHER_PATHS]
24
+ t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md)
25
+ end
26
+ end
data/lib/rescuer.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rescuer/version'
2
+
3
+ module Rescuer
4
+ DEFAULT_EXCEPTIONS = [StandardError]
5
+
6
+ def new(*exceptions)
7
+ exceptions = DEFAULT_EXCEPTIONS if exceptions.nil? || exceptions.empty?
8
+ Success.new(yield)
9
+ rescue *exceptions => ex
10
+ Failure.new(ex)
11
+ end
12
+ module_function :new
13
+
14
+ Success = Struct.new(:value)
15
+ Failure = Struct.new(:cause)
16
+ end
@@ -0,0 +1,4 @@
1
+ module Rescuer
2
+ # The current version of this gem
3
+ VERSION = '0.0.1'
4
+ end
data/rescuer.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
+ require 'rescuer/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'rescuer'
6
+ s.version = Rescuer::VERSION
7
+ s.author = 'Marc Siegel'
8
+ s.email = 'msiegel@usainnov.com'
9
+ s.homepage = 'http://ms-ati.github.com/rescuer/'
10
+ s.summary = 'Rescuer rescues the composability of exception-raising code blocks'
11
+ s.description = 'Rescuer is a functional abstraction of exception handling inspired by Scala\'s Try class'
12
+ s.license = 'MIT'
13
+
14
+ s.rubyforge_project = 'rescuer'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = %w(lib)
20
+
21
+ # Running rspec tests from rake
22
+ s.add_development_dependency 'rake', '~> 10.3.0'
23
+ s.add_development_dependency 'rspec', '3.0.0.beta2'
24
+
25
+ if !(defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
26
+ # Github flavored markdown in YARD documentation
27
+ # http://blog.nikosd.com/2011/11/github-flavored-markdown-in-yard.html
28
+ s.add_development_dependency 'yard'
29
+ s.add_development_dependency 'redcarpet'
30
+ s.add_development_dependency 'github-markup'
31
+ end
32
+
33
+ # Coveralls test coverage tool
34
+ s.add_development_dependency 'coveralls'
35
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'rescuer'
3
+
4
+ describe Rescuer do
5
+
6
+ describe '.new' do
7
+
8
+ context 'when block does *not* raise' do
9
+ subject { Rescuer.new { 1 + 1 } }
10
+ it { is_expected.to eq(Rescuer::Success.new(2)) }
11
+ end
12
+
13
+ context 'when block raises and no arguments' do
14
+ context 'when raise StandardError' do
15
+ let(:e) { StandardError.new('a standard error') }
16
+ subject { Rescuer.new { raise e } }
17
+ it { is_expected.to eq(Rescuer::Failure.new(e)) }
18
+ end
19
+
20
+ context 'when raise NoMemoryError' do
21
+ subject { lambda { Rescuer.new { raise NoMemoryError } } }
22
+ it { is_expected.to raise_error(NoMemoryError) }
23
+ end
24
+ end
25
+
26
+ context 'when block raises and Exception is an argument' do
27
+ context 'when raise NoMemoryError' do
28
+ let(:e) { NoMemoryError.new }
29
+ subject { Rescuer.new(Exception) { raise e } }
30
+ it { is_expected.to eq(Rescuer::Failure.new(e)) }
31
+ end
32
+ end
33
+
34
+ context 'when block raises and two subclasses of Exception are arguments' do
35
+ exceptions = [NoMemoryError, SyntaxError]
36
+
37
+ context 'when raise StandardError' do
38
+ subject { lambda { Rescuer.new(exceptions) { raise StandardError } } }
39
+ it { is_expected.to raise_error(StandardError) }
40
+ end
41
+
42
+ context 'when raise NoMemoryError' do
43
+ let(:e) { NoMemoryError.new }
44
+ subject { Rescuer.new(Exception) { raise e } }
45
+ it { is_expected.to eq(Rescuer::Failure.new(e)) }
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,25 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ # On Ruby 1.9+ use SimpleCov and publish to Coveralls.io
5
+ if !RUBY_VERSION.start_with? '1.8'
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start do
11
+ add_filter '/spec/' # exclude test code
12
+ add_filter '/vendor/' # exclude gems which are vendored on Travis CI
13
+ end
14
+ end
15
+
16
+ lib_dir = File.join(File.dirname(File.dirname(__FILE__)), 'lib')
17
+ $LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include? lib_dir
18
+
19
+ require 'rspec'
20
+
21
+ RSpec.configure do |config|
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = :expect
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rescuer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marc Siegel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 10.3.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 10.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0.beta2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0.beta2
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: github-markup
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Rescuer is a functional abstraction of exception handling inspired by
98
+ Scala's Try class
99
+ email: msiegel@usainnov.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - lib/rescuer.rb
114
+ - lib/rescuer/version.rb
115
+ - rescuer.gemspec
116
+ - spec/rescuer_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: http://ms-ati.github.com/rescuer/
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project: rescuer
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Rescuer rescues the composability of exception-raising code blocks
142
+ test_files: []
143
+ has_rdoc: