deal_with_it 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +57 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/deal_with_it.gemspec +28 -0
- data/dealwithit.png +0 -0
- data/lib/deal_with_it/handler.rb +22 -0
- data/lib/deal_with_it/version.rb +3 -0
- data/lib/deal_with_it.rb +16 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c68a2b9abea04e90b31d188e47c93996b11755d37840e3f6c29718c10393090
|
4
|
+
data.tar.gz: 0fcc8b0788d4cc4f88e0e0b13ec20956dc0df60e5bdd499b943f0ad2fcb041aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e79efae87ed25e0718ef9207c1cb0889af428c3544ba2d79146006c1eb78bda3f827b638606dc79307bc1d4612685be1bbef724b0c1c184d7eee8de7a2ff3851
|
7
|
+
data.tar.gz: 9817428a2c49cb8061e307f6d2e1f85c8ae43bbf95c505df9c7773da75d1a7ccf45d7d9871d88fa00d49937cc0ec8e763571f1ece5a00440cf0a5e70867dbc18
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
deal_with_it (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.3.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
parallel (1.12.0)
|
12
|
+
parser (2.4.0.2)
|
13
|
+
ast (~> 2.3)
|
14
|
+
powerpack (0.1.1)
|
15
|
+
rainbow (2.2.2)
|
16
|
+
rake
|
17
|
+
rake (10.5.0)
|
18
|
+
rspec (3.7.0)
|
19
|
+
rspec-core (~> 3.7.0)
|
20
|
+
rspec-expectations (~> 3.7.0)
|
21
|
+
rspec-mocks (~> 3.7.0)
|
22
|
+
rspec-core (3.7.0)
|
23
|
+
rspec-support (~> 3.7.0)
|
24
|
+
rspec-expectations (3.7.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-mocks (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-support (3.7.0)
|
31
|
+
rubocop (0.51.0)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.3.3.1, < 3.0)
|
34
|
+
powerpack (~> 0.1)
|
35
|
+
rainbow (>= 2.2.2, < 3.0)
|
36
|
+
ruby-progressbar (~> 1.7)
|
37
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
38
|
+
rubocop-rspec (1.20.1)
|
39
|
+
rubocop (>= 0.51.0)
|
40
|
+
ruby-progressbar (1.9.0)
|
41
|
+
unicode-display_width (1.3.0)
|
42
|
+
wonder-ruby-style (0.0.5)
|
43
|
+
rubocop (~> 0.49)
|
44
|
+
rubocop-rspec (~> 1.15)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 1.16)
|
51
|
+
deal_with_it!
|
52
|
+
rake (~> 10.0)
|
53
|
+
rspec (~> 3.0)
|
54
|
+
wonder-ruby-style
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Leonardo Falk
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# DealWithIt
|
2
|
+
|
3
|
+
![DealWithIt](./dealwithit.png)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'deal_with_it'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include the handler base on your ApplicationController or in any class you wish to handle.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class ApplicationController < ActionController::Base
|
25
|
+
include DealWithIt
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Create your custom handler anywhere in the app.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# app/handlers/record_not_found_handler.rb
|
33
|
+
class RecordNotFoundHandler < DealWithIt::Handler
|
34
|
+
deal ActiveRecord::RecordNotFound, with: ->(error) do
|
35
|
+
render json: { 'Oopsie, we didn\'t found that stuff' }, status: :not_found
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Note that `render` is a method that comes from the ActionController itself, it could be any method from the class that included the DealWithIt module.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/leonardofalk/deal_with_it>.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'deal_with_it'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deal_with_it/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'deal_with_it'
|
8
|
+
spec.version = DealWithIt::VERSION
|
9
|
+
spec.authors = ['Leonardo Falk']
|
10
|
+
spec.email = ['leonardo.falk@hotmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'DealWithIt is an exception handler for Ruby applications.'
|
13
|
+
spec.homepage = 'https://github.com/leonardofalk/deal_with_it.git'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'wonder-ruby-style'
|
28
|
+
end
|
data/dealwithit.png
ADDED
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class DealWithIt::Handler
|
2
|
+
DEFAULT_EXCEPTION_HANDLER = ->(error) do
|
3
|
+
raise error
|
4
|
+
end.freeze
|
5
|
+
|
6
|
+
attr_reader :exception, :callback
|
7
|
+
|
8
|
+
def self.deal(exception, with: DEFAULT_EXCEPTION_HANDLER)
|
9
|
+
@handler = new(exception, with)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.descendants
|
13
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def initialize(exception, with)
|
19
|
+
@exception = exception
|
20
|
+
@callback = with
|
21
|
+
end
|
22
|
+
end
|
data/lib/deal_with_it.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'deal_with_it/version'
|
2
|
+
require 'deal_with_it/handler'
|
3
|
+
|
4
|
+
module DealWithIt
|
5
|
+
def self.included(klass)
|
6
|
+
Rails.application.eager_load! if defined?(Rails) && !Rails.env.production?
|
7
|
+
|
8
|
+
klass.class_eval do
|
9
|
+
DealWithIt::Handler.descendants.each do |rescuer|
|
10
|
+
rescuer_instance = rescuer.instance_variable_get(:@handler)
|
11
|
+
|
12
|
+
rescue_from rescuer_instance.exception, with: rescuer_instance.callback
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deal_with_it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leonardo Falk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-28 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: wonder-ruby-style
|
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
|
+
description:
|
70
|
+
email:
|
71
|
+
- leonardo.falk@hotmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- deal_with_it.gemspec
|
87
|
+
- dealwithit.png
|
88
|
+
- lib/deal_with_it.rb
|
89
|
+
- lib/deal_with_it/handler.rb
|
90
|
+
- lib/deal_with_it/version.rb
|
91
|
+
homepage: https://github.com/leonardofalk/deal_with_it.git
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.7.0
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: DealWithIt is an exception handler for Ruby applications.
|
115
|
+
test_files: []
|