rexception 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +3 -0
- data/lib/rexception/controller.rb +43 -0
- data/lib/rexception/railtie.rb +9 -0
- data/lib/rexception/setting.rb +31 -0
- data/lib/rexception/version.rb +3 -0
- data/lib/rexception.rb +17 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 24a25113fbbb43426828f6de6097162baf65e3f9
|
4
|
+
data.tar.gz: d443721593818ec4de8f75af7ca4f9d1205e2dc0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44abab142291c6969576e3fb188975f8516ec407b343de6c036f864399f4b71c2f06d002fde6cfb67c6e698ada03fba59b7821f6713c834387e3453c10316398
|
7
|
+
data.tar.gz: 4eb25ffdd6c3e064c65297de1ac5b2a394d3afa1ab2ac30500ee86026afb772507face10a3be3914b3575942fe3eb85e77e07da605ee91e9db83c8b74ce97bb2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 kami
|
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/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rexception
|
2
|
+
class ExceptionsController < ActionController::Base
|
3
|
+
STATUSES = Rack::Utils::SYMBOL_TO_STATUS_CODE.select { |_, code| code >= 400 }
|
4
|
+
|
5
|
+
STATUSES.each do |status, code|
|
6
|
+
eval <<-RUBY
|
7
|
+
def #{status}
|
8
|
+
render template_exists?(view) ? view : view(:application), status: #{code}
|
9
|
+
end
|
10
|
+
RUBY
|
11
|
+
end
|
12
|
+
|
13
|
+
layout -> { setting.layout }
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def view(status = status())
|
18
|
+
"#{setting.errors_dir}/#{status}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def status
|
22
|
+
self.class.status(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def setting
|
26
|
+
Rexception.setting
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def call(env)
|
31
|
+
action(status(env)).call(env)
|
32
|
+
end
|
33
|
+
|
34
|
+
def status(env)
|
35
|
+
ActionDispatch::ExceptionWrapper.rescue_responses[exception(env).class.name]
|
36
|
+
end
|
37
|
+
|
38
|
+
def exception(env)
|
39
|
+
env['action_dispatch.exception']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Rexception
|
4
|
+
class Setting
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_accessor :layout
|
8
|
+
attr_accessor :errors_dir
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
defaults.each { |k, v| instance_variable_set("@#{k}", v) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
yield self
|
16
|
+
end
|
17
|
+
|
18
|
+
def rescue_responses=(rescue_responses)
|
19
|
+
ActionDispatch::ExceptionWrapper.rescue_responses.merge!(rescue_responses)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def defaults
|
25
|
+
@defaults ||= {
|
26
|
+
layout: 'application',
|
27
|
+
errors_dir: 'errors'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rexception.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rexception/version'
|
2
|
+
require 'rexception/controller'
|
3
|
+
require 'rexception/railtie' if defined?(Rails)
|
4
|
+
|
5
|
+
module Rexception
|
6
|
+
autoload :Setting, 'rexception/setting'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def setup(&block)
|
10
|
+
Setting.instance.setup(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def setting
|
14
|
+
Setting.instance
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rexception
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kami
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-16 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.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
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: capybara
|
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
|
+
description: Rendering error pages for Rails application.
|
56
|
+
email:
|
57
|
+
- kami30k@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- Rakefile
|
64
|
+
- lib/rexception.rb
|
65
|
+
- lib/rexception/controller.rb
|
66
|
+
- lib/rexception/railtie.rb
|
67
|
+
- lib/rexception/setting.rb
|
68
|
+
- lib/rexception/version.rb
|
69
|
+
homepage: https://github.com/kami30k/rexception
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.2.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Rendering error pages for Rails application.
|
93
|
+
test_files: []
|