rails-hush 1.1.0 → 1.1.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
2
  SHA256:
3
- metadata.gz: 28eb5448f9a28b437d7cb46cbba086fc16c891df1a8083a694ed12fba56bcd32
4
- data.tar.gz: c4b6f533e00e33e1b85c08abffe2fa863bdadbbe55e6709fefd522160e40fc0c
3
+ metadata.gz: 2a9c38ec9eb1c74c7be0f5be8400851ff7b4e18d09cf13f45d78dc0a661e91a5
4
+ data.tar.gz: fdefce31691aab5c96c685ee6a4688545d11d9fd66a926ac15845d593df23033
5
5
  SHA512:
6
- metadata.gz: c2cca48d9b7558a79a5421f709c25277a670abcf19f46ab2b5c0a6ecc4bd7ce49e08276eeb381b5bc7ed34fe56c41b0354652edb1fa11a2569f0bf46697c249c
7
- data.tar.gz: b900f8c397cf312c16347746333311dcd0f8ad2e22daf935c6d953cd4c0e400cb34e0eebbbdedd3172fbf3d06016113d5bbd43965f6c009c45e22bf7fe68b80c
6
+ metadata.gz: 8beddfa617f90cb92c7860bc1b23498738d5f722f2467c2c80f81c43e57464184abe6df3a00f0889edcd1a210df3b55a70bfe58c6ed968eefe7f8439923d8612
7
+ data.tar.gz: 527686f8e8edc9accdeff52175fc737752bea3ef7b44ef8932f8a530c1a0bc6e71da8f2cb3bf543552a342f0a457968149ece42b714cf7588d3ccb44b807f881
data/README.md CHANGED
@@ -42,9 +42,9 @@ RailsHush does support a couple of configuration options:
42
42
  To disable automatic loading of middleware:
43
43
 
44
44
  # Phase one (early) middleware
45
- config.rails_hush.use_one = true
45
+ config.rails_hush.use_one = false
46
46
  # Phase two (late) middleware
47
- config.rails_hush.use_two = true
47
+ config.rails_hush.use_two = false
48
48
 
49
49
  Then add the middleware on your own:
50
50
 
@@ -78,7 +78,7 @@ Rails' default "test" environment settings are quite different than "production"
78
78
 
79
79
  ## Contributing
80
80
 
81
- Contributions welcome. Please use standard Github Pull Requests.
81
+ Contributions welcome. Please use standard GitHub Pull Requests.
82
82
 
83
83
 
84
84
  ## License
@@ -1,5 +1,6 @@
1
1
  module RailsHush
2
2
  class HushOne
3
+ include ShowExceptions
3
4
  include SimpleRenderer
4
5
 
5
6
  def initialize(app, renderer=nil)
@@ -9,7 +10,7 @@ module RailsHush
9
10
 
10
11
  def call(env)
11
12
  request = ActionDispatch::Request.new env
12
- if request.show_exceptions? && !request.get_header("action_dispatch.show_detailed_exceptions")
13
+ if show_exceptions?(request) && !request.get_header("action_dispatch.show_detailed_exceptions")
13
14
  begin
14
15
  @app.call(env)
15
16
  rescue ActionController::UnknownHttpMethod
@@ -1,5 +1,6 @@
1
1
  module RailsHush
2
2
  class HushTwo
3
+ include ShowExceptions
3
4
  include SimpleRenderer
4
5
 
5
6
  def initialize(app, renderer=nil)
@@ -9,7 +10,7 @@ module RailsHush
9
10
 
10
11
  def call(env)
11
12
  request = ActionDispatch::Request.new env
12
- if request.show_exceptions? && !request.get_header("action_dispatch.show_detailed_exceptions")
13
+ if show_exceptions?(request) && !request.get_header("action_dispatch.show_detailed_exceptions")
13
14
  begin
14
15
  _, headers, body = response = @app.call(env)
15
16
  if headers['X-Cascade'] == 'pass'
@@ -0,0 +1,24 @@
1
+ module RailsHush
2
+ module ShowExceptions
3
+
4
+ # actionpack treats missing/invalid values as :all/true. since railties (eg: a full rails
5
+ # app) defaults to :all, skipping the invalid value case here to improve code clarity.
6
+ # since rails-hush intentionally overrides certain exceptions, treat :rescuable the same
7
+ # as :all. there's no need to be dynamic here.
8
+ SHOWABLE = [
9
+ :all, # rails 7.1+
10
+ true, # rails 7.0-
11
+ nil, # equiv to :all,true
12
+ :rescuable # rails 7.1+
13
+ ]
14
+
15
+ def show_exceptions?(request, exception=nil)
16
+ if Rails.version >= '7.1'
17
+ SHOWABLE.include? request.get_header("action_dispatch.show_exceptions")
18
+ else
19
+ request.show_exceptions?
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -1,38 +1,40 @@
1
- module SimpleRenderer
1
+ module RailsHush
2
+ module SimpleRenderer
2
3
 
3
- def log_request(status, request)
4
- payload = {
5
- params: (request.filtered_parameters rescue {}),
6
- headers: request.headers,
7
- format: (request.format.ref rescue :text),
8
- method: (request.request_method rescue 'INVALID'),
9
- path: request.fullpath,
10
- status: status
11
- }
12
- ActiveSupport::Notifications.instrument "process_action.action_controller", payload
13
- end
4
+ def log_request(status, request)
5
+ payload = {
6
+ params: (request.filtered_parameters rescue {}),
7
+ headers: request.headers,
8
+ format: (request.format.ref rescue :text),
9
+ method: (request.request_method rescue 'INVALID'),
10
+ path: request.fullpath,
11
+ status: status
12
+ }
13
+ ActiveSupport::Notifications.instrument "process_action.action_controller", payload
14
+ end
14
15
 
15
- def render(status, request, error=nil)
16
- begin
17
- content_type = request.formats.first
18
- rescue Mime::Type::InvalidMimeType
19
- content_type = Mime[:text]
16
+ def render(status, request, error=nil)
17
+ begin
18
+ content_type = request.formats.first
19
+ rescue Mime::Type::InvalidMimeType
20
+ content_type = Mime[:text]
21
+ end
22
+ error ||= Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500])
23
+ @renderer.call(status, content_type, error)
20
24
  end
21
- error ||= Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500])
22
- @renderer.call(status, content_type, error)
23
- end
24
25
 
25
- def default_renderer(status, content_type, error)
26
- body = { status: status, error: error }
27
- format = "to_#{content_type.to_sym}" if content_type
28
- if format && body.respond_to?(format)
29
- body = body.public_send(format)
30
- else
31
- content_type = 'application/json'
32
- body = body.to_json
26
+ def default_renderer(status, content_type, error)
27
+ body = { status: status, error: error }
28
+ format = "to_#{content_type.to_sym}" if content_type
29
+ if format && body.respond_to?(format)
30
+ body = body.public_send(format)
31
+ else
32
+ content_type = 'application/json'
33
+ body = body.to_json
34
+ end
35
+ [status, { "Content-Type" => "#{content_type}; charset=#{ActionDispatch::Response.default_charset}",
36
+ "Content-Length" => body.bytesize.to_s }, [body]]
33
37
  end
34
- [status, { "Content-Type" => "#{content_type}; charset=#{ActionDispatch::Response.default_charset}",
35
- "Content-Length" => body.bytesize.to_s }, [body]]
36
- end
37
38
 
39
+ end
38
40
  end
@@ -1,3 +1,3 @@
1
1
  module RailsHush
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
data/lib/rails_hush.rb CHANGED
@@ -1,4 +1,4 @@
1
- %w(simple_renderer hush_one hush_two).each do |f|
1
+ %w(show_exceptions simple_renderer hush_one hush_two).each do |f|
2
2
  require "rails_hush/middleware/#{f}"
3
3
  end
4
4
  require 'rails_hush/railtie'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-hush
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-10 00:00:00.000000000 Z
11
+ date: 2023-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '6'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '6'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sqlite3
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +73,7 @@ files:
73
73
  - lib/rails_hush.rb
74
74
  - lib/rails_hush/middleware/hush_one.rb
75
75
  - lib/rails_hush/middleware/hush_two.rb
76
+ - lib/rails_hush/middleware/show_exceptions.rb
76
77
  - lib/rails_hush/middleware/simple_renderer.rb
77
78
  - lib/rails_hush/railtie.rb
78
79
  - lib/rails_hush/version.rb