contextual_exceptions 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +12 -0
- data/contextual_exceptions.gemspec +28 -0
- data/lib/contextual_exceptions.rb +7 -0
- data/lib/contextual_exceptions/class_refinement.rb +23 -0
- data/lib/contextual_exceptions/contextual_error.rb +9 -0
- data/lib/contextual_exceptions/version.rb +3 -0
- data/spec/class_refinement_spec.rb +25 -0
- data/spec/contextual_error_spec.rb +24 -0
- data/spec/support/spec_helper.rb +32 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1202832b3c7fb5ca26292277e3cb65b6287dfab8
|
4
|
+
data.tar.gz: bbb05451dce2daa869c22273ad42d923c45ec174
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 326de1e725571bec2401ba1525679fddb3329919ef58deaff84539c0ffd99fe2e8397b9953f517a78aee9d4546240328611fd000e9520beaca3d5d639a5b9723
|
7
|
+
data.tar.gz: 13698b7de2dc0a495e9f001737fd3184a4ae35becc0d7b5a8938da5f50031105cf22fa56ee7e12a6746da54473db7cab465188319b2bb6da8a014e456942e6c9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dustin Morrill
|
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
|
+
# ContextualExceptions
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'contextual_exceptions'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install contextual_exceptions
|
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 'Add 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,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs << "lib" << 'spec/support'
|
9
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
10
|
+
t.verbose = false
|
11
|
+
t.warning = false # pry-rescue has a lot of warnings
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'contextual_exceptions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "contextual_exceptions"
|
8
|
+
spec.version = ContextualExceptions::VERSION
|
9
|
+
spec.authors = ["Dustin Morrill"]
|
10
|
+
spec.email = ["dmorrill10@gmail.com"]
|
11
|
+
spec.description = %q{ Provides an easy way to create and raise custom exceptions with the contextual information of previously raised system exceptions in Ruby >= 2.0.0 }
|
12
|
+
spec.summary = %q{ Provides an easy way to create and raise custom exceptions with the contextual information of previously raised system exceptions in Ruby >= 2.0.0 }
|
13
|
+
spec.homepage = "https://github.com/dmorrill10/contextual_exceptions"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($\)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'turn', '~> 0.9'
|
24
|
+
spec.add_development_dependency 'minitest', '~> 4.7'
|
25
|
+
spec.add_development_dependency 'awesome_print', '~> 1.0'
|
26
|
+
spec.add_development_dependency 'pry-rescue', '~> 1.0'
|
27
|
+
spec.add_development_dependency 'simplecov', '~> 0.7'
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'contextual_exceptions/contextual_error'
|
2
|
+
|
3
|
+
module ContextualExceptions
|
4
|
+
# @return This string in camel-case class name form.
|
5
|
+
def self.string_to_camel_case(string)
|
6
|
+
class_name = string.to_s.capitalize
|
7
|
+
class_name.gsub(/[_\s]+./) { |match| match = match[1,].capitalize }
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassRefinement
|
11
|
+
refine Class do
|
12
|
+
# @param [Array] names A list of exception names that the calling class would
|
13
|
+
# like to define.
|
14
|
+
def exceptions(*names)
|
15
|
+
names.each do |name|
|
16
|
+
error_name = ContextualExceptions.string_to_camel_case name
|
17
|
+
const_set(error_name, Class.new(StandardError))
|
18
|
+
const_get(error_name).extend ContextualError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'support/spec_helper'
|
2
|
+
|
3
|
+
require 'contextual_exceptions/class_refinement'
|
4
|
+
|
5
|
+
include ContextualExceptions
|
6
|
+
using ClassRefinement
|
7
|
+
|
8
|
+
class SubjectClass
|
9
|
+
exceptions :subject_error
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ClassRefinement do
|
13
|
+
it '::with_context should work' do
|
14
|
+
local_message = 'local message'
|
15
|
+
full_context = nil
|
16
|
+
begin
|
17
|
+
raise
|
18
|
+
rescue => full_context
|
19
|
+
end
|
20
|
+
patient = SubjectClass::SubjectError.with_context(local_message, full_context)
|
21
|
+
|
22
|
+
patient.message.must_equal(local_message << ": #{full_context.message}")
|
23
|
+
patient.backtrace.must_equal full_context.backtrace
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require_relative 'support/spec_helper'
|
3
|
+
|
4
|
+
require 'contextual_exceptions/contextual_error'
|
5
|
+
|
6
|
+
include ContextualExceptions
|
7
|
+
|
8
|
+
SubjectError = Class.new(StandardError)
|
9
|
+
SubjectError.extend ContextualError
|
10
|
+
|
11
|
+
describe ContextualError do
|
12
|
+
it '::with_context should work' do
|
13
|
+
local_message = 'local message'
|
14
|
+
full_context = nil
|
15
|
+
begin
|
16
|
+
raise
|
17
|
+
rescue => full_context
|
18
|
+
end
|
19
|
+
patient = SubjectError.with_context(local_message, full_context)
|
20
|
+
|
21
|
+
patient.message.must_equal(local_message << ": #{full_context.message}")
|
22
|
+
patient.backtrace.must_equal full_context.backtrace
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'minitest/spec'
|
5
|
+
require 'minitest/mock'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'turn/autorun'
|
9
|
+
|
10
|
+
Turn.config do |c|
|
11
|
+
# use one of output formats:
|
12
|
+
# :outline - turn's original case/test outline mode [default]
|
13
|
+
# :progress - indicates progress with progress bar
|
14
|
+
# :dotted - test/unit's traditional dot-progress mode
|
15
|
+
# :pretty - new pretty reporter
|
16
|
+
# :marshal - dump output as YAML (normal run mode only)
|
17
|
+
# :cue - interactive testing
|
18
|
+
c.format = :dotted
|
19
|
+
# use humanized test names (works only with :outline format)
|
20
|
+
c.natural = true
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'awesome_print'
|
24
|
+
module Minitest::Assertions
|
25
|
+
def mu_pp(obj)
|
26
|
+
obj.awesome_inspect
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'pry-rescue/minitest'
|
31
|
+
rescue LoadError
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contextual_exceptions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dustin Morrill
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: turn
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-rescue
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.7'
|
111
|
+
description: ' Provides an easy way to create and raise custom exceptions with the
|
112
|
+
contextual information of previously raised system exceptions in Ruby >= 2.0.0 '
|
113
|
+
email:
|
114
|
+
- dmorrill10@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- contextual_exceptions.gemspec
|
125
|
+
- lib/contextual_exceptions.rb
|
126
|
+
- lib/contextual_exceptions/class_refinement.rb
|
127
|
+
- lib/contextual_exceptions/contextual_error.rb
|
128
|
+
- lib/contextual_exceptions/version.rb
|
129
|
+
- spec/class_refinement_spec.rb
|
130
|
+
- spec/contextual_error_spec.rb
|
131
|
+
- spec/support/spec_helper.rb
|
132
|
+
homepage: https://github.com/dmorrill10/contextual_exceptions
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.0.0.rc.2
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Provides an easy way to create and raise custom exceptions with the contextual
|
156
|
+
information of previously raised system exceptions in Ruby >= 2.0.0
|
157
|
+
test_files:
|
158
|
+
- spec/class_refinement_spec.rb
|
159
|
+
- spec/contextual_error_spec.rb
|
160
|
+
- spec/support/spec_helper.rb
|