inertia_rails 1.11.0 → 1.11.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: 7912624c7ea6f1c71a896b969b704d8ff329ee41a3d1bc7277c28900b35a6516
4
- data.tar.gz: 30098f0f5dd3cf41987cd40f139a12259d5501375b85685ab0d427c0e69d230e
3
+ metadata.gz: 60a2f2a20da36323f792051d3a0c1327b3f085f78e8fed5906064e8892c516d9
4
+ data.tar.gz: c9a40fd17509def36b88862a671f98a4ed839f158ffd0959a66aba3023ee6084
5
5
  SHA512:
6
- metadata.gz: a97f62fa00d4489ff8364e6b4f9914161a1394905e5830526ba0baa9ae6888ee933a4e7739e18aeb6969f470989fb4aba9031cb62f57b68ed89065ff433d4e54
7
- data.tar.gz: e9d7b942b9e1b7f4cdb98e9941143b0e08501586266aac08390a510126233ffeca8328e75e9b0f63aea49d1d19820d02b97e65af0fb178bb822c8bf63ad9925c
6
+ metadata.gz: c136e534632a852b4d92ec7303cb5eba67fed88706cf28cc16e8bc541fda5320f9f09aa3e92f481951fe93390e30714813f0950bd67b75389b933634721d8dd5
7
+ data.tar.gz: b6f8568840f971249c90142afd6b20adf39b4d99a4864d952ddbedcbfdfb49884a6e35f9c419fd180d7abf50590bee70863f3766b94e6883a171b8995cef5f9e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.11.1] - 2021-06-27
8
+
9
+ * Fixed thread safety in the middleware. Thanks @caifara!
10
+
7
11
  ## [1.11.0] - 2021-03-23
8
12
 
9
13
  * Fixed the install generator. `installable?` was always returning false, preventing it from actually running.
data/README.md CHANGED
@@ -1,14 +1,10 @@
1
- # Inertia.js Rails Adapter
2
-
3
- Visit [inertiajs.com](https://inertiajs.com/) to learn more.
1
+ ![image](https://user-images.githubusercontent.com/6599653/114456558-032e2200-9bab-11eb-88bc-a19897f417ba.png)
4
2
 
5
- # Note to pre Rubygems release users
6
3
 
7
- The initial version of the gem was named `inertia`; however, that name was not available on Rubygems.
4
+ # Inertia.js Rails Adapter
8
5
 
9
- The 1.0.0 version release on Rubygems is `inertia_rails`.
6
+ Visit [inertiajs.com](https://inertiajs.com/) for installation instructions, documentation, and to learn more.
10
7
 
11
- The changes required are:
8
+ *Maintained and sponsored by the team at [bellaWatt](https://bellawatt.com/)*
12
9
 
13
- 1. Use `gem 'inertia_rails'` in your Gemfile (or `gem install inertia_rails`)
14
- 2. Change any `Inertia.configure` calls to `InertiaRails.configure`
10
+ [![bellaWatt Logo](https://user-images.githubusercontent.com/6599653/114456832-5607d980-9bab-11eb-99c8-ab39867c384e.png)](https://bellawatt.com/)
@@ -5,79 +5,91 @@ module InertiaRails
5
5
  end
6
6
 
7
7
  def call(env)
8
- @env = env
8
+ InertiaRailsRequest.new(@app, env)
9
+ .response
10
+ end
9
11
 
10
- status, headers, body = @app.call(env)
11
- request = ActionDispatch::Request.new(env)
12
+ class InertiaRailsRequest
13
+ def initialize(app, env)
14
+ @app = app
15
+ @env = env
16
+ end
12
17
 
13
- ::InertiaRails.reset!
18
+ def response
19
+ status, headers, body = @app.call(@env)
20
+ request = ActionDispatch::Request.new(@env)
14
21
 
15
- # Inertia errors are added to the session via redirect_to
16
- request.session.delete(:inertia_errors) unless keep_inertia_errors?(status)
22
+ ::InertiaRails.reset!
17
23
 
18
- status = 303 if inertia_non_post_redirect?(status)
24
+ # Inertia errors are added to the session via redirect_to
25
+ request.session.delete(:inertia_errors) unless keep_inertia_errors?(status)
19
26
 
20
- return stale_inertia_get? ? force_refresh(request) : [status, headers, body]
21
- end
27
+ status = 303 if inertia_non_post_redirect?(status)
22
28
 
23
- private
29
+ stale_inertia_get? ? force_refresh(request) : [status, headers, body]
30
+ end
24
31
 
25
- def keep_inertia_errors?(status)
26
- redirect_status?(status) || stale_inertia_request?
27
- end
32
+ private
28
33
 
29
- def stale_inertia_request?
30
- inertia_request? && version_stale?
31
- end
34
+ def keep_inertia_errors?(status)
35
+ redirect_status?(status) || stale_inertia_request?
36
+ end
32
37
 
33
- def redirect_status?(status)
34
- [301, 302].include? status
35
- end
38
+ def stale_inertia_request?
39
+ inertia_request? && version_stale?
40
+ end
36
41
 
37
- def non_get_redirectable_method?
38
- ['PUT', 'PATCH', 'DELETE'].include? request_method
39
- end
42
+ def redirect_status?(status)
43
+ [301, 302].include? status
44
+ end
40
45
 
41
- def inertia_non_post_redirect?(status)
42
- inertia_request? && redirect_status?(status) && non_get_redirectable_method?
43
- end
46
+ def non_get_redirectable_method?
47
+ ['PUT', 'PATCH', 'DELETE'].include? request_method
48
+ end
44
49
 
45
- def stale_inertia_get?
46
- get? && stale_inertia_request?
47
- end
50
+ def inertia_non_post_redirect?(status)
51
+ inertia_request? && redirect_status?(status) && non_get_redirectable_method?
52
+ end
48
53
 
49
- def get?
50
- request_method == 'GET'
51
- end
54
+ def stale_inertia_get?
55
+ get? && stale_inertia_request?
56
+ end
52
57
 
53
- def request_method
54
- @env['REQUEST_METHOD']
55
- end
58
+ def get?
59
+ request_method == 'GET'
60
+ end
56
61
 
57
- def inertia_version
58
- @env['HTTP_X_INERTIA_VERSION']
59
- end
62
+ def request_method
63
+ @env['REQUEST_METHOD']
64
+ end
60
65
 
61
- def inertia_request?
62
- @env['HTTP_X_INERTIA'].present?
63
- end
66
+ def inertia_version
67
+ @env['HTTP_X_INERTIA_VERSION']
68
+ end
64
69
 
65
- def version_stale?
66
- sent_version != saved_version
67
- end
70
+ def inertia_request?
71
+ @env['HTTP_X_INERTIA'].present?
72
+ end
68
73
 
69
- def sent_version
70
- return nil if inertia_version.nil?
71
- InertiaRails.version.is_a?(Numeric) ? inertia_version.to_f : inertia_version
72
- end
74
+ def version_stale?
75
+ sent_version != saved_version
76
+ end
73
77
 
74
- def saved_version
75
- InertiaRails.version.is_a?(Numeric) ? InertiaRails.version.to_f : InertiaRails.version
76
- end
78
+ def sent_version
79
+ return nil if inertia_version.nil?
80
+
81
+ InertiaRails.version.is_a?(Numeric) ? inertia_version.to_f : inertia_version
82
+ end
77
83
 
78
- def force_refresh(request)
79
- request.flash.keep
80
- Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url}).finish
84
+ def saved_version
85
+ InertiaRails.version.is_a?(Numeric) ? InertiaRails.version.to_f : InertiaRails.version
86
+ end
87
+
88
+ def force_refresh(request)
89
+ request.flash.keep
90
+ Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url}).finish
91
+ end
81
92
  end
82
93
  end
83
94
  end
95
+
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.11.0"
2
+ VERSION = "1.11.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-03-23 00:00:00.000000000 Z
13
+ date: 2021-06-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails