mime_typed_public_exceptions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c1c025b3cc1c61c96d10d8e2fd198bf81f1205d660e3af1224271cf4349c1725
4
+ data.tar.gz: 3df032a0ae5417285c68f0b40441c2d34cd5f322d91d83642fdb90e06c2fbe1b
5
+ SHA512:
6
+ metadata.gz: f367307cb256d10d0104aa29be30d0361c1a6e971c05279b0b86a6f7029883218b36fbf7584bf6c7e484f4587ccccdd5eeede7821eac7614db7dcb6c611e3b88
7
+ data.tar.gz: e1e6e8e910aee10ffd21eb710fcef49328e88e3ab9eaf092da02386e90f2c699ffc359e18babd185335736c6ce9be3ae742fb6655c1cb8e0755e414878fe9e10
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 naari3
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,47 @@
1
+ # MimeTypedPublicExceptions
2
+ PublicExceptions for multiple mime types
3
+
4
+ ## Usage
5
+ ```js
6
+ // public/500.json
7
+ {
8
+ "status": 500,
9
+ "message": "internal server error"
10
+ }
11
+ ```
12
+
13
+ ```ruby
14
+ Rails.application.configure do
15
+ config.exceptions_app = MimeTypedPublicExceptions.new(Rails.public_path)
16
+ end
17
+ ```
18
+
19
+ ```ruby
20
+ app.get '/some_exception', headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
21
+ # => 500
22
+ app.response_body
23
+ # => "{\n \"status\": 500,\n \"message\": \"internal server error\"\n}"
24
+ ```
25
+
26
+ ## Installation
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem 'mime_typed_public_exceptions'
31
+ ```
32
+
33
+ And then execute:
34
+ ```bash
35
+ $ bundle
36
+ ```
37
+
38
+ Or install it yourself as:
39
+ ```bash
40
+ $ gem install mime_typed_public_exceptions
41
+ ```
42
+
43
+ ## Contributing
44
+ Contribution directions go here.
45
+
46
+ ## License
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'MimeTypedPublicExceptions'
14
+ rdoc.options << '--line-numbers'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ require 'rspec/core/rake_task'
20
+ RSpec::Core::RakeTask.new(:spec)
21
+ task default: :spec
22
+
23
+ require 'bundler/gem_tasks'
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_dispatch'
4
+ require 'mime_typed_public_exceptions/version'
5
+
6
+ # This class behaves roughly as ActionDispatch::PublicExceptions.
7
+ # PublicExceptions is a Rack::Middleware for render an error page
8
+ # which static from /public directory but html only.
9
+ # This class when called, render an error page which static
10
+ # from /public directory with not only html but also others.
11
+ class MimeTypedPublicExceptions < ActionDispatch::PublicExceptions
12
+ private
13
+
14
+ def render(status, content_type, _body)
15
+ ext = content_type.symbol || 'html' # symbol does not represent an extension
16
+ path = [
17
+ "#{public_path}/#{status}.#{I18n.locale}.#{ext}",
18
+ "#{public_path}/#{status}.#{ext}"
19
+ ].find { |fp| File.exist?(fp) }
20
+ if path
21
+ render_format(status, content_type, File.read(path))
22
+ else
23
+ [404, { 'X-Cascade' => 'pass' }, []]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_dispatch'
4
+ class MimeTypedPublicExceptions < ActionDispatch::PublicExceptions
5
+ VERSION = '0.1.0'
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # desc "Explaining what the task does"
4
+ # task :mime_typed_public_exceptions do
5
+ # # Task goes here
6
+ # end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mime_typed_public_exceptions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - naari3
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-02 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: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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: rspec-rails
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: rubocop
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
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: PublicExceptions for multiple mime types
84
+ email:
85
+ - naari.named@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - MIT-LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - lib/mime_typed_public_exceptions.rb
94
+ - lib/mime_typed_public_exceptions/version.rb
95
+ - lib/tasks/mime_typed_public_exceptions_tasks.rake
96
+ homepage: https://github.com/naari3/mime_typed_public_exceptions
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: PublicExceptions for multiple mime types
120
+ test_files: []