mime_typed_public_exceptions 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1176d97d426dc51f5c00366048f07306265f1d16a9b591e63ed9d4039081837f
4
- data.tar.gz: 5bb8799122951aabe16b0339bde5e6d5d498539ca2baaa94a6846fdbcb54df04
3
+ metadata.gz: c95a003ba404e93b487038b0152d810098435e14c3238901b28b6fe0c0f45ec0
4
+ data.tar.gz: 8944dc499b98d3b8afc6ae6f6fe34316b7e2a18d4483314327c9c84405414b0f
5
5
  SHA512:
6
- metadata.gz: 53653403e1ec1c42e1c14afb6aabc2bdaf2ff1eac5fda6b56aa27c75bd659b25aabb2d30042a33dcf54f7ad6533d1879e0b1db3771a7f8707cfe11b02fdeaf5d
7
- data.tar.gz: dc8251b4e7ae9f1d7788cf5ddbb5294e2815da1322b67a4ed98e8891c6eb2b8c75fc435726890caaba84a51257bdcbab14f522f7d19b09afb7ea27aa31d5aa0c
6
+ metadata.gz: c7395fd5cd186dfb593a3ba5de604394ea9d3573c2a64a5e17cfc915d81705c2f391f68f4890c8a99f32e86a15eafc19363cb0626af6f13c3eb9c3a967ac301f
7
+ data.tar.gz: a80879be277e080640b8ebe60b83aa3cd24664d9b142b9ce6cc9929f7a28ce6a469fe7ab4e3cd4835fc9d370f5c407971fdb597fe5bd44a93774d0f52ad7ff03
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'action_dispatch'
4
4
  class MimeTypedPublicExceptions < ActionDispatch::PublicExceptions
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'action_dispatch'
4
+ require 'mimemagic'
5
+
4
6
  require 'mime_typed_public_exceptions/version'
5
7
 
6
8
  # This class behaves roughly as ActionDispatch::PublicExceptions.
@@ -12,15 +14,20 @@ class MimeTypedPublicExceptions < ActionDispatch::PublicExceptions
12
14
  private
13
15
 
14
16
  def render(status, content_type, _body)
15
- ext = content_type.symbol # 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) }
17
+ path = maybe_file_paths(status, content_type).find { |fp| File.exist?(fp) }
20
18
  if path
21
19
  render_format(status, content_type, File.read(path))
22
20
  else
23
21
  render_html(status)
24
22
  end
25
23
  end
24
+
25
+ def maybe_file_paths(status, content_type)
26
+ MimeMagic.new(content_type.to_s).extensions.map do |ext|
27
+ [
28
+ "#{public_path}/#{status}.#{I18n.locale}.#{ext}",
29
+ "#{public_path}/#{status}.#{ext}"
30
+ ]
31
+ end.flatten
32
+ end
26
33
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mime_typed_public_exceptions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - naari3
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-03 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mimemagic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rspec_junit_formatter
56
+ name: rspec-rails
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rspec-rails
70
+ name: rspec_junit_formatter
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="