rescuable_errors 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +169 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +37 -0
  8. data/Rakefile +31 -0
  9. data/VERSION +1 -0
  10. data/Vagrantfile +10 -0
  11. data/lib/engine.rb +4 -0
  12. data/lib/rescuable_errors.rb +24 -0
  13. data/lib/rescuable_errors/application_error.rb +5 -0
  14. data/rescuable_errors.gemspec +108 -0
  15. data/spec/dummy/.gitignore +13 -0
  16. data/spec/dummy/Gemfile +43 -0
  17. data/spec/dummy/Gemfile.lock +159 -0
  18. data/spec/dummy/README.rdoc +28 -0
  19. data/spec/dummy/Rakefile +6 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  21. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  22. data/spec/dummy/app/controllers/users_controller.rb +13 -0
  23. data/spec/dummy/app/errors/model_validation_error.rb +9 -0
  24. data/spec/dummy/app/errors/routing_error.rb +8 -0
  25. data/spec/dummy/app/errors/unauthenticated_error.rb +8 -0
  26. data/spec/dummy/bin/bundle +3 -0
  27. data/spec/dummy/bin/rails +8 -0
  28. data/spec/dummy/bin/rake +8 -0
  29. data/spec/dummy/bin/setup +29 -0
  30. data/spec/dummy/bin/spring +15 -0
  31. data/spec/dummy/config.ru +4 -0
  32. data/spec/dummy/config/application.rb +32 -0
  33. data/spec/dummy/config/boot.rb +3 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +38 -0
  36. data/spec/dummy/config/environments/production.rb +76 -0
  37. data/spec/dummy/config/environments/test.rb +42 -0
  38. data/spec/dummy/config/initializers/assets.rb +11 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  41. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/spec/dummy/config/initializers/inflections.rb +16 -0
  43. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  44. data/spec/dummy/config/initializers/rescue.rb +5 -0
  45. data/spec/dummy/config/initializers/session_store.rb +3 -0
  46. data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
  47. data/spec/dummy/config/locales/pt-BR.yml +4 -0
  48. data/spec/dummy/config/routes.rb +10 -0
  49. data/spec/dummy/config/secrets.yml +22 -0
  50. data/spec/dummy/lib/assets/.keep +0 -0
  51. data/spec/dummy/lib/tasks/.keep +0 -0
  52. data/spec/dummy/log/.keep +0 -0
  53. data/spec/rescuable_errors_spec.rb +47 -0
  54. data/spec/spec_helper.rb +31 -0
  55. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1c4ae419a431a09406a5317c8d0462dfa17da24
4
+ data.tar.gz: 5867052380b252552a1b1e824d76c273e3360f2f
5
+ SHA512:
6
+ metadata.gz: 073e9f2eff59656fbe96ee953c4295ee33a8517fc0141721453eadac5e2a3ec84774a4b10c026644dac2c1028c51ae59c0a0966bb8a982590fa3ef35c370288a
7
+ data.tar.gz: c652901cbbdeb5beecc23a6ac65aafce474d9a7b9a8f5c8fabc7a5c19d98da38a8ae2af4d25f5e3904f0ddb873371e7c8de5042eb951f1623e46ae25c40fcd18
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rails", "~> 4.2.0"
10
+ gem "rspec-rails", "~> 3.0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.0"
13
+ gem "jeweler", "~> 2.0.1"
14
+ gem "simplecov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,169 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (4.2.0)
5
+ actionpack (= 4.2.0)
6
+ actionview (= 4.2.0)
7
+ activejob (= 4.2.0)
8
+ mail (~> 2.5, >= 2.5.4)
9
+ rails-dom-testing (~> 1.0, >= 1.0.5)
10
+ actionpack (4.2.0)
11
+ actionview (= 4.2.0)
12
+ activesupport (= 4.2.0)
13
+ rack (~> 1.6.0)
14
+ rack-test (~> 0.6.2)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
17
+ actionview (4.2.0)
18
+ activesupport (= 4.2.0)
19
+ builder (~> 3.1)
20
+ erubis (~> 2.7.0)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ activejob (4.2.0)
24
+ activesupport (= 4.2.0)
25
+ globalid (>= 0.3.0)
26
+ activemodel (4.2.0)
27
+ activesupport (= 4.2.0)
28
+ builder (~> 3.1)
29
+ activerecord (4.2.0)
30
+ activemodel (= 4.2.0)
31
+ activesupport (= 4.2.0)
32
+ arel (~> 6.0)
33
+ activesupport (4.2.0)
34
+ i18n (~> 0.7)
35
+ json (~> 1.7, >= 1.7.7)
36
+ minitest (~> 5.1)
37
+ thread_safe (~> 0.3, >= 0.3.4)
38
+ tzinfo (~> 1.1)
39
+ addressable (2.3.7)
40
+ arel (6.0.0)
41
+ builder (3.2.2)
42
+ descendants_tracker (0.0.4)
43
+ thread_safe (~> 0.3, >= 0.3.1)
44
+ diff-lcs (1.2.5)
45
+ docile (1.1.5)
46
+ erubis (2.7.0)
47
+ faraday (0.9.1)
48
+ multipart-post (>= 1.2, < 3)
49
+ git (1.2.9.1)
50
+ github_api (0.12.3)
51
+ addressable (~> 2.3)
52
+ descendants_tracker (~> 0.0.4)
53
+ faraday (~> 0.8, < 0.10)
54
+ hashie (>= 3.3)
55
+ multi_json (>= 1.7.5, < 2.0)
56
+ nokogiri (~> 1.6.3)
57
+ oauth2
58
+ globalid (0.3.3)
59
+ activesupport (>= 4.1.0)
60
+ hashie (3.4.0)
61
+ highline (1.7.1)
62
+ hike (1.2.3)
63
+ i18n (0.7.0)
64
+ jeweler (2.0.1)
65
+ builder
66
+ bundler (>= 1.0)
67
+ git (>= 1.2.5)
68
+ github_api
69
+ highline (>= 1.6.15)
70
+ nokogiri (>= 1.5.10)
71
+ rake
72
+ rdoc
73
+ json (1.8.2)
74
+ jwt (1.4.1)
75
+ loofah (2.0.1)
76
+ nokogiri (>= 1.5.9)
77
+ mail (2.6.3)
78
+ mime-types (>= 1.16, < 3)
79
+ mime-types (2.4.3)
80
+ mini_portile (0.6.2)
81
+ minitest (5.5.1)
82
+ multi_json (1.11.0)
83
+ multi_xml (0.5.5)
84
+ multipart-post (2.0.0)
85
+ nokogiri (1.6.6.2)
86
+ mini_portile (~> 0.6.0)
87
+ oauth2 (1.0.0)
88
+ faraday (>= 0.8, < 0.10)
89
+ jwt (~> 1.0)
90
+ multi_json (~> 1.3)
91
+ multi_xml (~> 0.5)
92
+ rack (~> 1.2)
93
+ rack (1.6.0)
94
+ rack-test (0.6.3)
95
+ rack (>= 1.0)
96
+ rails (4.2.0)
97
+ actionmailer (= 4.2.0)
98
+ actionpack (= 4.2.0)
99
+ actionview (= 4.2.0)
100
+ activejob (= 4.2.0)
101
+ activemodel (= 4.2.0)
102
+ activerecord (= 4.2.0)
103
+ activesupport (= 4.2.0)
104
+ bundler (>= 1.3.0, < 2.0)
105
+ railties (= 4.2.0)
106
+ sprockets-rails
107
+ rails-deprecated_sanitizer (1.0.3)
108
+ activesupport (>= 4.2.0.alpha)
109
+ rails-dom-testing (1.0.5)
110
+ activesupport (>= 4.2.0.beta, < 5.0)
111
+ nokogiri (~> 1.6.0)
112
+ rails-deprecated_sanitizer (>= 1.0.1)
113
+ rails-html-sanitizer (1.0.2)
114
+ loofah (~> 2.0)
115
+ railties (4.2.0)
116
+ actionpack (= 4.2.0)
117
+ activesupport (= 4.2.0)
118
+ rake (>= 0.8.7)
119
+ thor (>= 0.18.1, < 2.0)
120
+ rake (10.4.2)
121
+ rdoc (3.12.2)
122
+ json (~> 1.4)
123
+ rspec-core (3.2.2)
124
+ rspec-support (~> 3.2.0)
125
+ rspec-expectations (3.2.0)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.2.0)
128
+ rspec-mocks (3.2.1)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.2.0)
131
+ rspec-rails (3.2.1)
132
+ actionpack (>= 3.0, < 4.3)
133
+ activesupport (>= 3.0, < 4.3)
134
+ railties (>= 3.0, < 4.3)
135
+ rspec-core (~> 3.2.0)
136
+ rspec-expectations (~> 3.2.0)
137
+ rspec-mocks (~> 3.2.0)
138
+ rspec-support (~> 3.2.0)
139
+ rspec-support (3.2.2)
140
+ simplecov (0.9.2)
141
+ docile (~> 1.1.0)
142
+ multi_json (~> 1.0)
143
+ simplecov-html (~> 0.9.0)
144
+ simplecov-html (0.9.0)
145
+ sprockets (2.12.3)
146
+ hike (~> 1.2)
147
+ multi_json (~> 1.0)
148
+ rack (~> 1.0)
149
+ tilt (~> 1.1, != 1.3.0)
150
+ sprockets-rails (2.2.4)
151
+ actionpack (>= 3.0)
152
+ activesupport (>= 3.0)
153
+ sprockets (>= 2.8, < 4.0)
154
+ thor (0.19.1)
155
+ thread_safe (0.3.5)
156
+ tilt (1.4.1)
157
+ tzinfo (1.2.2)
158
+ thread_safe (~> 0.1)
159
+
160
+ PLATFORMS
161
+ ruby
162
+
163
+ DEPENDENCIES
164
+ bundler (~> 1.0)
165
+ jeweler (~> 2.0.1)
166
+ rails (~> 4.2.0)
167
+ rdoc (~> 3.12)
168
+ rspec-rails (~> 3.0)
169
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Victor Antoniazzi
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/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # RescuableErrors
2
+
3
+ Rescue correctly your application erros.
4
+
5
+
6
+ # Create new error classes
7
+
8
+ Follow spec/dummy/app/errors or example below
9
+
10
+ You can create errors into gem or in your application. Create errors/routing_error.rb in your application:
11
+
12
+ ```
13
+ module RescuableErrors
14
+ class RoutingError < RescuableErrors::ApplicationError
15
+ def initialize
16
+ @code = 404
17
+ @status = 404
18
+ @class = "RescuableErrors::RoutingError"
19
+ super I18n.t("errors.routing")
20
+ end
21
+ end
22
+ end
23
+
24
+ ```
25
+
26
+ and fail in controller with ```fail RescuableErrors::RoutingError.new```. Now will automaticaly render a JSON response with status 404:
27
+ ```
28
+ "error": {
29
+ "code": 404,
30
+ "class": "RescuableErrors::RoutingError",
31
+ "message": "Routing not found."
32
+ }
33
+ ```
34
+
35
+ # Tests
36
+
37
+ In rescuable_errors_spec has some tests. Just copy to your tests. In `spec/dummy` has an application with all detais that how to use this lib
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "rescuable_errors"
17
+ gem.homepage = "http://github.com/vgsantoniazzi/rescuable-errors"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{Rescuable Errors gem}
20
+ gem.description = %Q{Rescuable Gem for any application}
21
+ gem.email = "vgsantoniazzi@gmail.com"
22
+ gem.authors = ["Victor Antoniazzi"]
23
+ end
24
+
25
+ require 'rspec/core'
26
+ require 'rspec/core/rake_task'
27
+ RSpec::Core::RakeTask.new(:spec) do |spec|
28
+ spec.pattern = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/Vagrantfile ADDED
@@ -0,0 +1,10 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure(2) do |config|
5
+ config.vm.box = "vgsantoniazzi/dev-box"
6
+
7
+ config.vm.provider "virtualbox" do |vb|
8
+ vb.memory = "2048"
9
+ end
10
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,4 @@
1
+ module RescuableErrors
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,24 @@
1
+ require_relative './engine.rb'
2
+ Dir[File.dirname(__FILE__) + '/rescuable_errors/**/*.rb'].each {|file| require file }
3
+
4
+ module RescuableErrors
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ rescue_from RescuableErrors::ApplicationError do |e|
9
+ render json: {
10
+ error: {
11
+ code: e.code, class: e.class, message: parse(e.message)
12
+ }
13
+ }, status: e.status
14
+ end
15
+
16
+ def parse(response)
17
+ begin
18
+ return JSON.parse(response)
19
+ rescue JSON::ParserError
20
+ return response
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module RescuableErrors
2
+ class ApplicationError < StandardError
3
+ attr_accessor :code, :class, :status
4
+ end
5
+ end
@@ -0,0 +1,108 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: rescuable_errors 1.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "rescuable_errors"
9
+ s.version = "1.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Victor Antoniazzi"]
14
+ s.date = "2015-03-31"
15
+ s.description = "Rescuable Gem for any application"
16
+ s.email = "vgsantoniazzi@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "Vagrantfile",
31
+ "lib/engine.rb",
32
+ "lib/rescuable_errors.rb",
33
+ "lib/rescuable_errors/application_error.rb",
34
+ "rescuable_errors.gemspec",
35
+ "spec/dummy/.gitignore",
36
+ "spec/dummy/Gemfile",
37
+ "spec/dummy/Gemfile.lock",
38
+ "spec/dummy/README.rdoc",
39
+ "spec/dummy/Rakefile",
40
+ "spec/dummy/app/controllers/application_controller.rb",
41
+ "spec/dummy/app/controllers/concerns/.keep",
42
+ "spec/dummy/app/controllers/users_controller.rb",
43
+ "spec/dummy/app/errors/model_validation_error.rb",
44
+ "spec/dummy/app/errors/routing_error.rb",
45
+ "spec/dummy/app/errors/unauthenticated_error.rb",
46
+ "spec/dummy/bin/bundle",
47
+ "spec/dummy/bin/rails",
48
+ "spec/dummy/bin/rake",
49
+ "spec/dummy/bin/setup",
50
+ "spec/dummy/bin/spring",
51
+ "spec/dummy/config.ru",
52
+ "spec/dummy/config/application.rb",
53
+ "spec/dummy/config/boot.rb",
54
+ "spec/dummy/config/environment.rb",
55
+ "spec/dummy/config/environments/development.rb",
56
+ "spec/dummy/config/environments/production.rb",
57
+ "spec/dummy/config/environments/test.rb",
58
+ "spec/dummy/config/initializers/assets.rb",
59
+ "spec/dummy/config/initializers/backtrace_silencers.rb",
60
+ "spec/dummy/config/initializers/cookies_serializer.rb",
61
+ "spec/dummy/config/initializers/filter_parameter_logging.rb",
62
+ "spec/dummy/config/initializers/inflections.rb",
63
+ "spec/dummy/config/initializers/mime_types.rb",
64
+ "spec/dummy/config/initializers/rescue.rb",
65
+ "spec/dummy/config/initializers/session_store.rb",
66
+ "spec/dummy/config/initializers/wrap_parameters.rb",
67
+ "spec/dummy/config/locales/pt-BR.yml",
68
+ "spec/dummy/config/routes.rb",
69
+ "spec/dummy/config/secrets.yml",
70
+ "spec/dummy/lib/assets/.keep",
71
+ "spec/dummy/lib/tasks/.keep",
72
+ "spec/dummy/log/.keep",
73
+ "spec/rescuable_errors_spec.rb",
74
+ "spec/spec_helper.rb"
75
+ ]
76
+ s.homepage = "http://github.com/vgsantoniazzi/rescuable-errors"
77
+ s.licenses = ["MIT"]
78
+ s.rubygems_version = "2.4.6"
79
+ s.summary = "Rescuable Errors gem"
80
+
81
+ if s.respond_to? :specification_version then
82
+ s.specification_version = 4
83
+
84
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
85
+ s.add_development_dependency(%q<rails>, ["~> 4.2.0"])
86
+ s.add_development_dependency(%q<rspec-rails>, ["~> 3.0"])
87
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
88
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
89
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
90
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
91
+ else
92
+ s.add_dependency(%q<rails>, ["~> 4.2.0"])
93
+ s.add_dependency(%q<rspec-rails>, ["~> 3.0"])
94
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
95
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
96
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
97
+ s.add_dependency(%q<simplecov>, [">= 0"])
98
+ end
99
+ else
100
+ s.add_dependency(%q<rails>, ["~> 4.2.0"])
101
+ s.add_dependency(%q<rspec-rails>, ["~> 3.0"])
102
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
103
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
104
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
105
+ s.add_dependency(%q<simplecov>, [">= 0"])
106
+ end
107
+ end
108
+