restful_error 0.0.10 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b3fff4f822826b410486c8fd4e0a96d93e68a360
4
- data.tar.gz: d5444371ca2ab9bbd33882b9ba23ba70c7daad85
2
+ SHA256:
3
+ metadata.gz: ed41c4445374dd04c3bc55400525f9e436f7adc503485be8d77faa764251d172
4
+ data.tar.gz: 8f9c8e4199d621f75ea4983749c728332024b0217aa5a28650b32077f035087f
5
5
  SHA512:
6
- metadata.gz: 273d0f7b854eeb21a7b0041c21154f3ad71f4a99935f2192263fbde59d44cf64f1136b31fa9e160211f2e6a9d77807beca314f1011de34ff9cdf9b7879f5a816
7
- data.tar.gz: 10e0c2bea56bb5e4cc85d60873234a711e409dcee8060af65a38fcca81459536560f7810f25604c677dd4843a5065f57833af5cc535d44bb51444130ac7c96bb
6
+ metadata.gz: b215a5616379e7efcd84d0945512b72ea757558d1d987725f5097f4c2eb3e1f8df3b5b4191c03ea5653204b6f9e56a9765012015de1e58b81a8db8359daa4c0f
7
+ data.tar.gz: 0d7ef8d2754453d72759e754634ef452f4f06104f6e3747bc5f7fd9ccbb1744badb98442bab74ac91ececd2021b68f96ccf0639e02364dae4029e2a8661d31f7
File without changes
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RestfulError
4
+ module Inflector
5
+ module_function
6
+
7
+ def underscore(word_)
8
+ return word_.underscore if word_.respond_to?(:underscore)
9
+
10
+ word = word_.dup
11
+ word.gsub!("::", "/")
12
+ word.gsub!(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_")
13
+ word.tr!("-", "_")
14
+ word.downcase!
15
+ end
16
+
17
+ def camelize(word_)
18
+ return word_.camelize if word_.respond_to?(:camelize)
19
+
20
+ word = word_.dup
21
+ word.sub!(/^[a-z\d]*/) { ::Regexp.last_match(0).capitalize }
22
+ word.gsub!(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
23
+ word.gsub!("/", "::")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ require "abstract_controller"
2
+ require "action_controller/metal"
3
+
4
+ module RestfulError
5
+ class ExceptionsController < ::ActionController::Metal
6
+ include AbstractController::Rendering
7
+ include ActionView::Layouts
8
+
9
+ append_view_path File.join(File.dirname(__FILE__), "../../app/views")
10
+
11
+ def show
12
+ @exception = request.env["action_dispatch.exception"]
13
+ status = Status.new(request.path_info[1..].to_i)
14
+ @status_code = status.code
15
+ @reason_phrase = status.reason_phrase
16
+ @message = @exception.try(:response_message)
17
+ unless @message
18
+ class_name = @exception.class.name
19
+ class_key = RestfulError::Inflector.underscore(class_name)
20
+ @message = I18n.t class_key, default: [ status.symbol, @reason_phrase ], scope: :restful_error
21
+ end
22
+
23
+ self.status = status.code
24
+ render "restful_error/show"
25
+ end
26
+ end
27
+
28
+ def self.exceptions_app
29
+ ExceptionsController.action(:show)
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "restful_error/inflector"
4
+ require "rack/utils"
5
+
6
+ module RestfulError
7
+ STATUS_CODE_TO_SYMBOL = Rack::Utils::SYMBOL_TO_STATUS_CODE.invert
8
+ def self.code_from(code_or_sym_or_const_name)
9
+ case code_or_sym_or_const_name
10
+ when Integer
11
+ code_or_sym_or_const_name
12
+ when Symbol
13
+ str = code_or_sym_or_const_name.to_s
14
+ sym = /[A-Z]/.match?(str[0]) ? RestfulError::Inflector.underscore(str).to_sym : code_or_sym_or_const_name
15
+ begin
16
+ Rack::Utils.status_code(sym)
17
+ rescue ArgumentError
18
+ nil
19
+ end
20
+ when /\A\d{3}\z/
21
+ code_from(code_or_sym_or_const_name.to_i)
22
+ else
23
+ raise ArgumentError, "Invalid argument: #{code_or_sym_or_const_name.inspect}"
24
+ end
25
+ end
26
+
27
+ Status = Data.define(:code, :reason_phrase, :symbol, :const_name) do
28
+ def initialize(code:)
29
+ reason_phrase = Rack::Utils::HTTP_STATUS_CODES[code]
30
+ raise ArgumentError, "Invalid status code: #{code}" unless reason_phrase
31
+
32
+ symbol = STATUS_CODE_TO_SYMBOL[code]
33
+ const_name = Inflector.camelize(symbol.to_s)
34
+ super(code:, reason_phrase:, symbol:, const_name:)
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RestfulError
2
- VERSION = "0.0.10"
4
+ VERSION = "1.0.1"
3
5
  end
File without changes
data/lib/restful_error.rb CHANGED
@@ -1,70 +1,54 @@
1
- require 'webrick/httpstatus'
2
- require 'webrick/accesslog'
1
+ # frozen_string_literal: true
3
2
 
4
- RestfulError = WEBrick::HTTPStatus
3
+ require "rack/utils"
4
+ require "restful_error/railtie" if defined? ActionController
5
+ require "restful_error/status"
5
6
 
6
- load "restful_error/version.rb"
7
- require 'restful_error/engine'
8
- require 'restful_error/wrapper'
9
- require 'abstract_controller'
10
- require 'action_controller/metal'
7
+ I18n.load_path += Dir["#{File.expand_path("../config/locales")}/*.yml"] if defined? I18n
11
8
 
12
9
  module RestfulError
13
- CodeToError.each do |_, klass|
14
- code = klass::code
15
- reason_phrase = klass::reason_phrase
16
- klass.class_exec do
17
- define_method(:status_code, ->{ code })
18
- define_method(:reason_phrase, ->{ reason_phrase })
19
- end
20
- end
10
+ class BaseError < StandardError; end
21
11
 
22
12
  module Helper
23
13
  def restful
24
- @restful ||= Wrapper.new(self)
14
+ raise NotImplementedError, "http_status must be implemented by including class" unless respond_to?(:http_status)
15
+
16
+ @restful ||= Status.new(RestfulError.code_from(http_status))
25
17
  end
26
18
  end
27
19
 
28
- module ActionController
29
- def render_exception(ex)
30
- @exception = ex.extend(Helper)
31
- ex.restful.set_env(request.env)
32
- @status_code = ex.restful.status_code
33
- @reason_phrase = ex.restful.reason_phrase
34
- @message = ex.restful.message
35
-
36
- raise if @status_code == 500 && Rails.configuration.consider_all_requests_local
37
-
38
- respond_to do |format|
39
- format.any(:json, :xml, :html){ render 'restful_error/show', status: @status_code }
40
- end
20
+ @cache = {}
21
+ class << self
22
+ def [](code_like)
23
+ code = RestfulError.code_from(code_like)
24
+ @cache[code] ||= build_error_class_for(code)
41
25
  end
42
- def self.included(base)
43
- base.rescue_from StandardError do |ex|
44
- render_exception ex
45
- end
46
- end
47
- end
48
26
 
49
- class ExceptionsController < ::ActionController::Metal
50
- include AbstractController::Rendering
51
- include ActionView::Layouts
27
+ def const_missing(const_name)
28
+ code = RestfulError.code_from(const_name)
29
+ return super unless code
52
30
 
53
- append_view_path File.join(File.dirname(__FILE__), '../app/views')
31
+ @cache[code] ||= build_error_class_for(code)
32
+ end
54
33
 
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
34
+ private
62
35
 
63
- self.status = @status_code
64
- render 'restful_error/show'
36
+ def build_error_class_for(code)
37
+ status = Status.new(code)
38
+ message = defined?(I18n) ? I18n.t(status.symbol, default: status.reason_phrase, scope: :restful_error) : status.reason_phrase
39
+ klass = Class.new(BaseError) do
40
+ define_method(:http_status) { status.code }
41
+ define_method(:restful) { status }
42
+ define_method(:message) { message }
43
+ end
44
+ const_set(status.const_name, klass)
45
+ if defined? ActionDispatch::ExceptionWrapper
46
+ ActionDispatch::ExceptionWrapper.rescue_responses[klass.name] = status.code
47
+ klass.define_singleton_method(:inherited) do |subclass|
48
+ ActionDispatch::ExceptionWrapper.rescue_responses[subclass.name] = status.code
49
+ end
50
+ end
51
+ klass
65
52
  end
66
53
  end
67
- def self.exceptions_app
68
- ExceptionsController.action(:show)
69
- end
70
54
  end
data/spec/rack_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'action_controller'
1
2
  require 'spec_helper'
2
3
 
3
4
  describe 'RestfulError' do
@@ -11,7 +12,7 @@ describe 'RestfulError' do
11
12
  env "action_dispatch.exception", RestfulError[404].new
12
13
  end
13
14
  it do
14
- get '/hoge'
15
+ get '/404'
15
16
  expect(last_response.status).to eq 404
16
17
  end
17
18
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_controller"
4
+ require "spec_helper"
5
+
6
+ RSpec.describe "RestfulError.exceptions_app" do
7
+ let(:app) { RestfulError.exceptions_app }
8
+ let(:env) { {} }
9
+ let(:request) { Rack::MockRequest.new(app) }
10
+
11
+ it "renders 404" do
12
+ env["action_dispatch.exception"] = ActionController::RoutingError.new("Not Found")
13
+ env["PATH_INFO"] = "/404"
14
+ response = request.get("/404", env)
15
+ expect(response.status).to eq 404
16
+ expect(response.body).to include "Not Found"
17
+ end
18
+ end
@@ -1,24 +1,47 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe RestfulError do
4
- it 'has a version number' do
5
- expect(RestfulError::VERSION).not_to be nil
6
+ describe "RestfullError[404]" do
7
+ subject { described_class[404].new }
8
+
9
+ it do
10
+ expect(subject.http_status).to eq 404
11
+ expect(subject.restful.reason_phrase).to eq "Not Found"
12
+ end
6
13
  end
7
14
 
8
- describe 'Wrapper' do
9
- require 'active_record/errors'
10
- subject { ex.extend(RestfulError::Helper) }
11
- context 'with number' do
12
- let(:ex){ Class.new(RestfulError[404]).new }
13
- it do
14
- expect(subject.restful.status_code).to eq 404
15
- end
15
+ describe "RestfullError[:bad_request]" do
16
+ subject { described_class[:bad_request].new }
17
+
18
+ it do
19
+ expect(subject.http_status).to eq 400
20
+ expect(subject.restful.reason_phrase).to eq "Bad Request"
21
+ end
22
+ end
23
+
24
+ describe described_class::Forbidden do
25
+ subject { described_class.new }
26
+
27
+ it do
28
+ expect(subject.http_status).to eq 403
29
+ expect(subject.restful.reason_phrase).to eq "Forbidden"
16
30
  end
17
- context 'with phrase' do
18
- let(:ex){ Class.new(RestfulError::NotFound).new }
19
- it do
20
- expect(subject.restful.status_code).to eq 404
31
+ end
32
+
33
+ describe "custom class" do
34
+ subject { klass.new }
35
+
36
+ let(:klass) do
37
+ Class.new(StandardError) do
38
+ include RestfulError::Helper
39
+ def http_status = 404
21
40
  end
22
41
  end
42
+
43
+ it do
44
+ expect(subject.restful.symbol).to eq :not_found
45
+ end
23
46
  end
24
47
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,6 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'restful_error'
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+
5
+ require "debug"
6
+ require "restful_error"
metadata CHANGED
@@ -1,105 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_error
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kuboon
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-21 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '4.1'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '4.1'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.6'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.6'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
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: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3'
11
+ date: 2025-01-28 00:00:00.000000000 Z
12
+ dependencies: []
69
13
  description: Define status_code method on your error. Views and messages are fully
70
14
  customizable on rails way.
71
15
  email:
72
- - ohkubo@magician.jp
16
+ - o@kbn.one
73
17
  executables: []
74
18
  extensions: []
75
19
  extra_rdoc_files: []
76
20
  files:
77
- - ".gitignore"
78
- - ".rspec"
79
- - ".travis.yml"
80
- - Gemfile
81
- - LICENSE.txt
82
- - README.md
83
- - Rakefile
84
- - app/views/restful_error/show.html.erb
85
- - app/views/restful_error/show.html.haml
86
- - app/views/restful_error/show.json.jbuilder
87
- - app/views/restful_error/show.xml.erb
88
- - config/locales/en.restful_error.yml
89
- - config/locales/ja.restful_error.yml
90
21
  - lib/restful_error.rb
91
22
  - lib/restful_error/engine.rb
23
+ - lib/restful_error/inflector.rb
24
+ - lib/restful_error/railtie.rb
25
+ - lib/restful_error/status.rb
92
26
  - lib/restful_error/version.rb
93
27
  - lib/restful_error/wrapper.rb
94
- - restful_error.gemspec
95
28
  - spec/rack_spec.rb
29
+ - spec/railtie_spec.rb
96
30
  - spec/restful_error_spec.rb
97
31
  - spec/spec_helper.rb
98
32
  homepage: https://github.com/kuboon/restful_error
99
33
  licenses:
100
34
  - MIT
101
- metadata: {}
102
- post_install_message:
35
+ metadata:
36
+ rubygems_mfa_required: 'true'
37
+ post_install_message:
103
38
  rdoc_options: []
104
39
  require_paths:
105
40
  - lib
@@ -107,20 +42,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
42
  requirements:
108
43
  - - ">="
109
44
  - !ruby/object:Gem::Version
110
- version: '0'
45
+ version: '3.2'
111
46
  required_rubygems_version: !ruby/object:Gem::Requirement
112
47
  requirements:
113
48
  - - ">="
114
49
  - !ruby/object:Gem::Version
115
50
  version: '0'
116
51
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.6.11
119
- signing_key:
52
+ rubygems_version: 3.5.22
53
+ signing_key:
120
54
  specification_version: 4
121
55
  summary: Define your error with status code. Raise it and you will get formatted response
122
56
  with i18nized message.
123
- test_files:
124
- - spec/rack_spec.rb
125
- - spec/restful_error_spec.rb
126
- - spec/spec_helper.rb
57
+ test_files: []
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.2
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in restful_error.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Ohkubo KOHEI
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 DELETED
@@ -1,119 +0,0 @@
1
- # RestfulError
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
-
5
- Define your error with status code. Raise it and you will get formatted response with i18nized message.
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- gem 'restful_error'
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Load the module in your controller:
18
-
19
- ```ruby
20
- class ApplicationController < ActionController::Base
21
-
22
- include RestfulError::ActionController
23
- ```
24
-
25
- ## Usage
26
-
27
- ### Simple
28
- #### raise me
29
- ```ruby
30
- class PostsController < ApplicationController
31
- before_action do
32
- raise RestfulError[401] unless current_user
33
- # or
34
- raise RestfulError::Unauthorized unless current_user
35
- end
36
- end
37
- ```
38
- #### Multi format response
39
-
40
- ```ruby
41
- get '/posts/new'
42
- #=> render 'restful_error/show.html' with @status_code and @message
43
-
44
- post '/posts.json'
45
- #=> { status_code: 401, message: "Sign in required"} or write your json at 'restful_error/show.json'
46
-
47
- get '/session.xml'
48
- #=> "<error><status_code type="integer">401</status_code><message>Sign in required</message></error>" or write your xml at 'restful_error/show.xml'
49
- ```
50
-
51
- #### I18n
52
-
53
- ```yaml
54
- ja:
55
- restful_error:
56
- unauthorized: ログインしてください #401
57
- not_found: ページが存在しません #404
58
- ```
59
-
60
- ### Advanced
61
- #### your custom error
62
- ```ruby
63
- class ::NoSession < RestfulError[404]; end
64
- # or
65
- class ::NoSession < RestfulError::NotFound; end
66
- ```
67
- #### duck typing
68
- ```ruby
69
- class OAuthController < ApplicationController
70
-
71
- # all you need is status_code
72
- class RequireTwitterLogin < StandardError
73
- def status_code; 401; end
74
- end
75
- # or
76
- class RequireTwitterLogin < StandardError
77
- def status_code; :unauthorized; end
78
- end
79
- end
80
- ```
81
-
82
- #### library defined error
83
- ``` ruby
84
- config.action_dispatch.rescue_responses["CanCan::Unauthorized"] = 401
85
- # or
86
- config.action_dispatch.rescue_responses["CanCan::Unauthorized"] = :unauthorized
87
- ```
88
- #### I18n
89
- ```yaml
90
- ja:
91
- restful_error:
92
- no_session: セッションがありません
93
- oauth_controller/require_twitter_login: Twitterログインが必要です
94
- can_can/unauthorized: 権限がありません
95
- active_record/record_not_found: 要求されたリソースが存在しません
96
- ```
97
- #### custom message
98
-
99
- ```ruby
100
- class RequireLogin < StandardError
101
- def initialize(provider = 'Unknown')
102
- @provider = provider
103
- end
104
- def status_code
105
- :unauthorized
106
- end
107
- def status_message
108
- I18n.t('restful_error.require_login', provider: provider)
109
- end
110
- end
111
- ```
112
-
113
- ## Contributing
114
-
115
- 1. Fork it ( https://github.com/kuboon/restful_error/fork )
116
- 2. Create your feature branch (`git checkout -b my-new-feature`)
117
- 3. Commit your changes (`git commit -am 'Add some feature'`)
118
- 4. Push to the branch (`git push origin my-new-feature`)
119
- 5. Create a new Pull Request
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
7
-
@@ -1,4 +0,0 @@
1
- <div class="'page_header">
2
- <h1><%= @status_code %> <%= @reason_phrase %></h1>
3
- <p><%= @message %></p>
4
- </div>
@@ -1,5 +0,0 @@
1
- .page_header
2
- %h1
3
- = @status_code
4
- = @reason_phrase
5
- %p= @message
@@ -1,3 +0,0 @@
1
- json.status_code @status_code
2
- json.reason_phrase @reason_phrase
3
- json.message @message
@@ -1,5 +0,0 @@
1
- <error>
2
- <status_code><%= @status_code %></status_code>
3
- <reason_phrase><%= @reason_phrase %></reason_phrase>
4
- <message><%= @message %></message>
5
- </error>
@@ -1,12 +0,0 @@
1
- ja:
2
- restful_error:
3
- active_record/record_not_found: Requested resource is not found
4
- can_can/unauthorized: Unauthorized
5
- bad_request: Bad request #400
6
- unauthorized: Unauthorized #401
7
- forbidden: Forbidden #403
8
- not_found: Not found #404
9
- method_not_allowed: Method not allowd #405
10
- gone: Gone #410
11
- internal_server_error: Internal server error #500
12
- service_unavailable: Service unavailable #503
@@ -1,12 +0,0 @@
1
- ja:
2
- restful_error:
3
- active_record/record_not_found: 要求されたリソースが存在しません
4
- can_can/unauthorized: 権限がありません
5
- bad_request: 不正なリクエストです #400
6
- unauthorized: 権限がありません #401
7
- forbidden: そのURLへのアクセスは禁止されています #403
8
- not_found: そのURLは存在しません #404
9
- method_not_allowed: メソッドは使用できません #405
10
- gone: 要求されたリソースは消滅しました #410
11
- internal_server_error: サーバエラーです #500
12
- service_unavailable: サービスが一時的に利用不可能になっています。しばらく時間をおいて、再度ご確認願います。 #503
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'restful_error/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "restful_error"
8
- spec.version = RestfulError::VERSION
9
- spec.authors = ["kuboon"]
10
- spec.email = ["ohkubo@magician.jp"]
11
- spec.summary = %q{Define your error with status code. Raise it and you will get formatted response with i18nized message.}
12
- spec.description = %q{Define status_code method on your error. Views and messages are fully customizable on rails way.}
13
- spec.homepage = "https://github.com/kuboon/restful_error"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency 'rails', ">= 4.1"
22
-
23
- spec.add_development_dependency "bundler", "~> 1.6"
24
- spec.add_development_dependency "rake", '~> 0'
25
- spec.add_development_dependency "rspec", "~> 3"
26
- end