restful_error 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmQwYzRkYTQwZTcxMDU2MzU1NzFjYTNkMzE5MzA1MWQ3NTk3OTgyYQ==
5
- data.tar.gz: !binary |-
6
- OGEzYjE1MGYwNzBhZGE2NGQ2YTM1MWYzMTRjZjIxYjJjMzYxM2M1NA==
2
+ SHA1:
3
+ metadata.gz: 531e0d0ab7c318aa830b7fae7e8345c431997eac
4
+ data.tar.gz: f2208e621889dc0d28ea114fe89d8915bbf3cda1
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Yzk0MWYyMGI4MTA5OWEwNjNiNTU0YTFlMzNmZDFmYzI0MzA0MDJhOWU1M2Iy
10
- NjViOTk0YjJkMzAyNzgzMzVhMDFmOWE1YWJhOGViN2Y5YWQzOWJlOWE3YmQy
11
- NWVjNmI4OThiZWIyNzg0YjUzMDRmYWM3MWIwYjY5NWU2Mjk0NGI=
12
- data.tar.gz: !binary |-
13
- OWVmMzYyNjVkNTgzOGJmZWI0ZDFiZDk2MDM2YjUwOWRkNDY0YjU3ZjU4YmFm
14
- NWNjNTRiYzVhZTE3NjUwMmE1ZDJhNDQ1NDY0OWE2YTgzOTk5NzhmNGZhZTEw
15
- NTIzNzRhZWFjZWMzMmI3ODI5YTI0NWE0N2UxNzA5YzI4ZDg1ZGM=
6
+ metadata.gz: 0f96bd006ec470bfbd0445ddfca29f0e1967bb2f4f94a925c04e26b85a6c91db121111057ed30c94ca371b622ef70aa4d3274eb649334af8c1311ae46aef9743
7
+ data.tar.gz: fc974acde63a27c7df58aca1ece014f837b8a699b5e3582e849e9c76e7dc17019b8786f66c8fa73416088add2159090b8b0637c27ca54cb9a5543b1dc63d4b74
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # RestfulError
2
2
 
3
+ [![Join the chat at https://gitter.im/kuboon/restful_error](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kuboon/restful_error?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
3
5
  Define your error with status code. Raise it and you will get formatted response with i18nized message.
4
6
 
5
7
  ## Installation
@@ -0,0 +1,4 @@
1
+ <div class="'page_header">
2
+ <h1><%= @status_code %> <%= @reason_phrase %></h1>
3
+ <p><%= @message %></p>
4
+ </div>
@@ -1,3 +1,8 @@
1
- json.status_code @status_code
2
- json.reason_phrase @reason_phrase
3
- json.message @message
1
+ json.errors do
2
+ json.array! do
3
+ json.status @status_code
4
+ json.title @reason_phrase
5
+ json.detail @message
6
+ # json.source
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module RestfulError
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/restful_error.rb CHANGED
@@ -6,6 +6,8 @@ RestfulError = WEBrick::HTTPStatus
6
6
  load "restful_error/version.rb"
7
7
  require 'restful_error/engine'
8
8
  require 'restful_error/wrapper'
9
+ require 'abstract_controller'
10
+ require 'action_controller/metal'
9
11
 
10
12
  module RestfulError
11
13
  CodeToError.each do |_, klass|
@@ -43,4 +45,26 @@ module RestfulError
43
45
  end
44
46
  end
45
47
  end
48
+
49
+ class ExceptionsController < ::ActionController::Metal
50
+ include AbstractController::Rendering
51
+ include ActionView::Layouts
52
+
53
+ append_view_path File.join(File.dirname(__FILE__), '../app/views')
54
+
55
+ def show
56
+ ex = env["action_dispatch.exception"]
57
+ @exception = ex.extend(Helper)
58
+ ex.restful.set_env(env)
59
+ @status_code = ex.restful.status_code
60
+ @reason_phrase = ex.restful.reason_phrase
61
+ @message = ex.restful.message
62
+
63
+ self.status = @status_code
64
+ render 'restful_error/show'
65
+ end
66
+ end
67
+ def self.exceptions_app
68
+ ExceptionsController.action(:show)
69
+ end
46
70
  end
data/spec/rack_spec.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'RestfulError' do
4
+ describe RestfulError::ExceptionsController do
5
+ include Rack::Test::Methods
6
+ def app
7
+ RestfulError::ExceptionsController.action(:show)
8
+ end
9
+ describe '404' do
10
+ before do
11
+ env "action_dispatch.exception", RestfulError[404].new
12
+ end
13
+ it do
14
+ get '/hoge'
15
+ expect(last_response.status).to eq 404
16
+ end
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_error
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kuboon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2016-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>'
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>'
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3'
69
69
  description: Define status_code method on your error. Views and messages are fully
@@ -74,13 +74,14 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
78
- - .rspec
79
- - .travis.yml
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
80
  - Gemfile
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
+ - app/views/restful_error/show.html.erb
84
85
  - app/views/restful_error/show.html.haml
85
86
  - app/views/restful_error/show.json.jbuilder
86
87
  - app/views/restful_error/show.xml.erb
@@ -91,6 +92,7 @@ files:
91
92
  - lib/restful_error/version.rb
92
93
  - lib/restful_error/wrapper.rb
93
94
  - restful_error.gemspec
95
+ - spec/rack_spec.rb
94
96
  - spec/restful_error_spec.rb
95
97
  - spec/spec_helper.rb
96
98
  homepage: https://github.com/kuboon/restful_error
@@ -103,21 +105,22 @@ require_paths:
103
105
  - lib
104
106
  required_ruby_version: !ruby/object:Gem::Requirement
105
107
  requirements:
106
- - - ! '>='
108
+ - - ">="
107
109
  - !ruby/object:Gem::Version
108
110
  version: '0'
109
111
  required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
- - - ! '>='
113
+ - - ">="
112
114
  - !ruby/object:Gem::Version
113
115
  version: '0'
114
116
  requirements: []
115
117
  rubyforge_project:
116
- rubygems_version: 2.4.5
118
+ rubygems_version: 2.2.2
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: Define your error with status code. Raise it and you will get formatted response
120
122
  with i18nized message.
121
123
  test_files:
124
+ - spec/rack_spec.rb
122
125
  - spec/restful_error_spec.rb
123
126
  - spec/spec_helper.rb