inertia_rails 1.11.0 → 1.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -9
- data/lib/inertia_rails/middleware.rb +65 -53
- data/lib/inertia_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a2f2a20da36323f792051d3a0c1327b3f085f78e8fed5906064e8892c516d9
|
4
|
+
data.tar.gz: c9a40fd17509def36b88862a671f98a4ed839f158ffd0959a66aba3023ee6084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
4
|
+
# Inertia.js Rails Adapter
|
8
5
|
|
9
|
-
|
6
|
+
Visit [inertiajs.com](https://inertiajs.com/) for installation instructions, documentation, and to learn more.
|
10
7
|
|
11
|
-
|
8
|
+
*Maintained and sponsored by the team at [bellaWatt](https://bellawatt.com/)*
|
12
9
|
|
13
|
-
|
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
|
-
@
|
8
|
+
InertiaRailsRequest.new(@app, env)
|
9
|
+
.response
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
class InertiaRailsRequest
|
13
|
+
def initialize(app, env)
|
14
|
+
@app = app
|
15
|
+
@env = env
|
16
|
+
end
|
12
17
|
|
13
|
-
|
18
|
+
def response
|
19
|
+
status, headers, body = @app.call(@env)
|
20
|
+
request = ActionDispatch::Request.new(@env)
|
14
21
|
|
15
|
-
|
16
|
-
request.session.delete(:inertia_errors) unless keep_inertia_errors?(status)
|
22
|
+
::InertiaRails.reset!
|
17
23
|
|
18
|
-
|
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
|
-
|
21
|
-
end
|
27
|
+
status = 303 if inertia_non_post_redirect?(status)
|
22
28
|
|
23
|
-
|
29
|
+
stale_inertia_get? ? force_refresh(request) : [status, headers, body]
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
redirect_status?(status) || stale_inertia_request?
|
27
|
-
end
|
32
|
+
private
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
def keep_inertia_errors?(status)
|
35
|
+
redirect_status?(status) || stale_inertia_request?
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
def stale_inertia_request?
|
39
|
+
inertia_request? && version_stale?
|
40
|
+
end
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
def redirect_status?(status)
|
43
|
+
[301, 302].include? status
|
44
|
+
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
46
|
+
def non_get_redirectable_method?
|
47
|
+
['PUT', 'PATCH', 'DELETE'].include? request_method
|
48
|
+
end
|
44
49
|
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
def inertia_non_post_redirect?(status)
|
51
|
+
inertia_request? && redirect_status?(status) && non_get_redirectable_method?
|
52
|
+
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
def stale_inertia_get?
|
55
|
+
get? && stale_inertia_request?
|
56
|
+
end
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
def get?
|
59
|
+
request_method == 'GET'
|
60
|
+
end
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
def request_method
|
63
|
+
@env['REQUEST_METHOD']
|
64
|
+
end
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
def inertia_version
|
67
|
+
@env['HTTP_X_INERTIA_VERSION']
|
68
|
+
end
|
64
69
|
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
def inertia_request?
|
71
|
+
@env['HTTP_X_INERTIA'].present?
|
72
|
+
end
|
68
73
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
74
|
+
def version_stale?
|
75
|
+
sent_version != saved_version
|
76
|
+
end
|
73
77
|
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
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
|
+
|
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.
|
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-
|
13
|
+
date: 2021-06-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|