media_types-serialization 1.3.9 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +114 -84
- data/README.md +14 -1
- data/lib/media_types/serialization/serialization_dsl.rb +19 -1
- data/lib/media_types/serialization/serializers/problem_serializer.rb +7 -0
- data/lib/media_types/serialization/version.rb +1 -1
- data/lib/media_types/serialization.rb +8 -4
- data/media_types-serialization.gemspec +4 -4
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '096826bd7e4a4be4fcd147fec07f26d05aec0101b8651ae63ed376a7a2388077'
|
4
|
+
data.tar.gz: 2f783986be7ca3eff779e10a2ace5338d9ab7dbb755334ae79d01d7b422a77c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0b58cdb8eb8e4f8c0c8ad73cc607673768cba38399cf9c804db16a54198b3fe0799a18c641e7c05d10e03c2936fc96a416b80ff51ff4bd5e6d570b10a47e712
|
7
|
+
data.tar.gz: e82051321d55df89abe34c6d43e62a0158245c4fb9ae60060fc3e939df854626b3014285f2ac277f7632f6c3cd099ef349265bdfffbf7b7b226f76287bb53147
|
data/.github/workflows/ci.yml
CHANGED
@@ -17,12 +17,12 @@ jobs:
|
|
17
17
|
|
18
18
|
strategy:
|
19
19
|
matrix:
|
20
|
-
ruby-version: [
|
20
|
+
ruby-version: ["3.1", "3.0", "2.7"]
|
21
21
|
|
22
22
|
steps:
|
23
23
|
- uses: actions/checkout@v1
|
24
24
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
25
|
-
uses:
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
26
|
with:
|
27
27
|
ruby-version: ${{ matrix.ruby-version }}
|
28
28
|
- name: Build and test with Rake
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,128 +1,158 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
media_types-serialization (1.
|
5
|
-
actionpack (>=
|
6
|
-
activesupport (>=
|
7
|
-
media_types (>= 2.
|
4
|
+
media_types-serialization (1.4.0)
|
5
|
+
actionpack (>= 6.0.0)
|
6
|
+
activesupport (>= 6.0.0)
|
7
|
+
media_types (>= 2.2.0, < 3.0.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actioncable (
|
13
|
-
actionpack (=
|
12
|
+
actioncable (6.1.7.3)
|
13
|
+
actionpack (= 6.1.7.3)
|
14
|
+
activesupport (= 6.1.7.3)
|
14
15
|
nio4r (~> 2.0)
|
15
16
|
websocket-driver (>= 0.6.1)
|
16
|
-
|
17
|
-
actionpack (=
|
18
|
-
|
19
|
-
|
17
|
+
actionmailbox (6.1.7.3)
|
18
|
+
actionpack (= 6.1.7.3)
|
19
|
+
activejob (= 6.1.7.3)
|
20
|
+
activerecord (= 6.1.7.3)
|
21
|
+
activestorage (= 6.1.7.3)
|
22
|
+
activesupport (= 6.1.7.3)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
actionmailer (6.1.7.3)
|
25
|
+
actionpack (= 6.1.7.3)
|
26
|
+
actionview (= 6.1.7.3)
|
27
|
+
activejob (= 6.1.7.3)
|
28
|
+
activesupport (= 6.1.7.3)
|
20
29
|
mail (~> 2.5, >= 2.5.4)
|
21
30
|
rails-dom-testing (~> 2.0)
|
22
|
-
actionpack (
|
23
|
-
actionview (=
|
24
|
-
activesupport (=
|
25
|
-
rack (~> 2.0, >= 2.0.
|
31
|
+
actionpack (6.1.7.3)
|
32
|
+
actionview (= 6.1.7.3)
|
33
|
+
activesupport (= 6.1.7.3)
|
34
|
+
rack (~> 2.0, >= 2.0.9)
|
26
35
|
rack-test (>= 0.6.3)
|
27
36
|
rails-dom-testing (~> 2.0)
|
28
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
29
|
-
|
30
|
-
|
37
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
38
|
+
actiontext (6.1.7.3)
|
39
|
+
actionpack (= 6.1.7.3)
|
40
|
+
activerecord (= 6.1.7.3)
|
41
|
+
activestorage (= 6.1.7.3)
|
42
|
+
activesupport (= 6.1.7.3)
|
43
|
+
nokogiri (>= 1.8.5)
|
44
|
+
actionview (6.1.7.3)
|
45
|
+
activesupport (= 6.1.7.3)
|
31
46
|
builder (~> 3.1)
|
32
47
|
erubi (~> 1.4)
|
33
48
|
rails-dom-testing (~> 2.0)
|
34
|
-
rails-html-sanitizer (~> 1.
|
35
|
-
activejob (
|
36
|
-
activesupport (=
|
49
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
50
|
+
activejob (6.1.7.3)
|
51
|
+
activesupport (= 6.1.7.3)
|
37
52
|
globalid (>= 0.3.6)
|
38
|
-
activemodel (
|
39
|
-
activesupport (=
|
40
|
-
activerecord (
|
41
|
-
activemodel (=
|
42
|
-
activesupport (=
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
activerecord (=
|
47
|
-
|
48
|
-
|
53
|
+
activemodel (6.1.7.3)
|
54
|
+
activesupport (= 6.1.7.3)
|
55
|
+
activerecord (6.1.7.3)
|
56
|
+
activemodel (= 6.1.7.3)
|
57
|
+
activesupport (= 6.1.7.3)
|
58
|
+
activestorage (6.1.7.3)
|
59
|
+
actionpack (= 6.1.7.3)
|
60
|
+
activejob (= 6.1.7.3)
|
61
|
+
activerecord (= 6.1.7.3)
|
62
|
+
activesupport (= 6.1.7.3)
|
63
|
+
marcel (~> 1.0)
|
64
|
+
mini_mime (>= 1.1.0)
|
65
|
+
activesupport (6.1.7.3)
|
49
66
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
50
|
-
i18n (>=
|
51
|
-
minitest (
|
52
|
-
tzinfo (~>
|
53
|
-
|
67
|
+
i18n (>= 1.6, < 2)
|
68
|
+
minitest (>= 5.1)
|
69
|
+
tzinfo (~> 2.0)
|
70
|
+
zeitwerk (~> 2.3)
|
54
71
|
awesome_print (1.9.2)
|
55
72
|
builder (3.2.4)
|
56
|
-
concurrent-ruby (1.
|
73
|
+
concurrent-ruby (1.2.2)
|
57
74
|
crass (1.0.6)
|
58
|
-
|
59
|
-
|
75
|
+
date (3.3.3)
|
76
|
+
erubi (1.12.0)
|
77
|
+
globalid (1.1.0)
|
60
78
|
activesupport (>= 5.0)
|
61
|
-
i18n (1.
|
79
|
+
i18n (1.12.0)
|
62
80
|
concurrent-ruby (~> 1.0)
|
63
|
-
loofah (2.
|
81
|
+
loofah (2.19.1)
|
64
82
|
crass (~> 1.0.2)
|
65
83
|
nokogiri (>= 1.5.9)
|
66
|
-
mail (2.
|
84
|
+
mail (2.8.1)
|
67
85
|
mini_mime (>= 0.1.1)
|
68
|
-
|
69
|
-
|
86
|
+
net-imap
|
87
|
+
net-pop
|
88
|
+
net-smtp
|
89
|
+
marcel (1.0.2)
|
90
|
+
media_types (2.2.0)
|
70
91
|
method_source (1.0.0)
|
71
|
-
mini_mime (1.1.
|
72
|
-
minitest (5.
|
92
|
+
mini_mime (1.1.2)
|
93
|
+
minitest (5.18.0)
|
94
|
+
net-imap (0.3.4)
|
95
|
+
date
|
96
|
+
net-protocol
|
97
|
+
net-pop (0.1.2)
|
98
|
+
net-protocol
|
99
|
+
net-protocol (0.2.1)
|
100
|
+
timeout
|
101
|
+
net-smtp (0.3.3)
|
102
|
+
net-protocol
|
73
103
|
nio4r (2.5.8)
|
74
|
-
nokogiri (1.
|
104
|
+
nokogiri (1.14.2-x64-mingw32)
|
75
105
|
racc (~> 1.4)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
actionview (=
|
88
|
-
activejob (=
|
89
|
-
activemodel (=
|
90
|
-
activerecord (=
|
91
|
-
activestorage (=
|
92
|
-
activesupport (=
|
93
|
-
bundler (>= 1.
|
94
|
-
railties (=
|
106
|
+
oj (3.14.2)
|
107
|
+
racc (1.6.2)
|
108
|
+
rack (2.2.6.4)
|
109
|
+
rack-test (2.1.0)
|
110
|
+
rack (>= 1.3)
|
111
|
+
rails (6.1.7.3)
|
112
|
+
actioncable (= 6.1.7.3)
|
113
|
+
actionmailbox (= 6.1.7.3)
|
114
|
+
actionmailer (= 6.1.7.3)
|
115
|
+
actionpack (= 6.1.7.3)
|
116
|
+
actiontext (= 6.1.7.3)
|
117
|
+
actionview (= 6.1.7.3)
|
118
|
+
activejob (= 6.1.7.3)
|
119
|
+
activemodel (= 6.1.7.3)
|
120
|
+
activerecord (= 6.1.7.3)
|
121
|
+
activestorage (= 6.1.7.3)
|
122
|
+
activesupport (= 6.1.7.3)
|
123
|
+
bundler (>= 1.15.0)
|
124
|
+
railties (= 6.1.7.3)
|
95
125
|
sprockets-rails (>= 2.0.0)
|
96
126
|
rails-dom-testing (2.0.3)
|
97
127
|
activesupport (>= 4.2.0)
|
98
128
|
nokogiri (>= 1.6)
|
99
|
-
rails-html-sanitizer (1.
|
100
|
-
loofah (~> 2.
|
101
|
-
railties (
|
102
|
-
actionpack (=
|
103
|
-
activesupport (=
|
129
|
+
rails-html-sanitizer (1.5.0)
|
130
|
+
loofah (~> 2.19, >= 2.19.1)
|
131
|
+
railties (6.1.7.3)
|
132
|
+
actionpack (= 6.1.7.3)
|
133
|
+
activesupport (= 6.1.7.3)
|
104
134
|
method_source
|
105
|
-
rake (>=
|
106
|
-
thor (
|
135
|
+
rake (>= 12.2)
|
136
|
+
thor (~> 1.0)
|
107
137
|
rake (13.0.6)
|
108
|
-
sprockets (4.0
|
138
|
+
sprockets (4.2.0)
|
109
139
|
concurrent-ruby (~> 1.0)
|
110
|
-
rack (
|
111
|
-
sprockets-rails (3.
|
112
|
-
actionpack (>=
|
113
|
-
activesupport (>=
|
140
|
+
rack (>= 2.2.4, < 4)
|
141
|
+
sprockets-rails (3.4.2)
|
142
|
+
actionpack (>= 5.2)
|
143
|
+
activesupport (>= 5.2)
|
114
144
|
sprockets (>= 3.0.0)
|
115
|
-
thor (1.1
|
116
|
-
|
117
|
-
tzinfo (
|
118
|
-
|
145
|
+
thor (1.2.1)
|
146
|
+
timeout (0.3.2)
|
147
|
+
tzinfo (2.0.6)
|
148
|
+
concurrent-ruby (~> 1.0)
|
119
149
|
websocket-driver (0.7.5)
|
120
150
|
websocket-extensions (>= 0.1.0)
|
121
151
|
websocket-extensions (0.1.5)
|
152
|
+
zeitwerk (2.6.7)
|
122
153
|
|
123
154
|
PLATFORMS
|
124
155
|
x64-mingw32
|
125
|
-
x86_64-linux
|
126
156
|
|
127
157
|
DEPENDENCIES
|
128
158
|
awesome_print
|
@@ -130,8 +160,8 @@ DEPENDENCIES
|
|
130
160
|
media_types-serialization!
|
131
161
|
minitest (~> 5.0)
|
132
162
|
oj
|
133
|
-
rails (~>
|
163
|
+
rails (~> 6.0)
|
134
164
|
rake (~> 13.0)
|
135
165
|
|
136
166
|
BUNDLED WITH
|
137
|
-
2.
|
167
|
+
2.1.4
|
data/README.md
CHANGED
@@ -887,7 +887,15 @@ Can be used to render a view.
|
|
887
887
|
You can set local variables in the view by assigning a hash to the `assigns:` parameter.
|
888
888
|
Returns a `string`
|
889
889
|
|
890
|
-
> When possible, prefer `output_raw` with
|
890
|
+
> When possible, prefer `output_raw` with context.render_to_string(params)`
|
891
|
+
|
892
|
+
#### `redirect_to(url, context, **options)`
|
893
|
+
|
894
|
+
This redirects the user to the specified url when this serializer is rendered. The output of the serializer is still shown in the API viewer.
|
895
|
+
|
896
|
+
#### `suppress_render do |result|`
|
897
|
+
|
898
|
+
Replaces the render at the end of `render_media` and substitutes it with the contents of the block.
|
891
899
|
|
892
900
|
### Controller definition
|
893
901
|
|
@@ -916,6 +924,11 @@ Outputs the specified description as help information.
|
|
916
924
|
|
917
925
|
Accepts the same filters as `before_action`.
|
918
926
|
|
927
|
+
#### `output_error(klazz, serializers = []) do`
|
928
|
+
|
929
|
+
Wraps the controller method in a `rescue_from` and presents the users with a `text/html` or `application/problem+json` representation of the error.
|
930
|
+
The `text/html` response can be overridden by supplying an additional serializer in the `serializers` array. It will use the nil view for the given serializers.
|
931
|
+
|
919
932
|
#### `allow_input_serializer( serializer, views: nil, **filters )`
|
920
933
|
|
921
934
|
Configure the controller to allow the client to send bodies with a `Content-Type` that can be deserialized using the specified serializer.
|
@@ -11,10 +11,11 @@ module MediaTypes
|
|
11
11
|
@serialization_links = links
|
12
12
|
@serialization_context = context
|
13
13
|
@serialization_vary = vary
|
14
|
+
@serialization_custom_render = nil
|
14
15
|
super(serializer)
|
15
16
|
end
|
16
17
|
|
17
|
-
attr_accessor :serialization_dsl_result
|
18
|
+
attr_accessor :serialization_dsl_result, :serialization_custom_render
|
18
19
|
|
19
20
|
def attribute(key, value = {}, &block)
|
20
21
|
unless block.nil?
|
@@ -112,6 +113,23 @@ module MediaTypes
|
|
112
113
|
|
113
114
|
context.serialization_dsl_result
|
114
115
|
end
|
116
|
+
|
117
|
+
def redirect_to(url, context, **options)
|
118
|
+
suppress_render do |result|
|
119
|
+
context.redirect_to(
|
120
|
+
url,
|
121
|
+
**options
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
"Redirecting to: #{url}"
|
126
|
+
end
|
127
|
+
|
128
|
+
def suppress_render(&block)
|
129
|
+
@serialization_custom_render = block || lambda { |result| }
|
130
|
+
|
131
|
+
serialization_dsl_result
|
132
|
+
end
|
115
133
|
end
|
116
134
|
end
|
117
135
|
end
|
@@ -32,6 +32,9 @@ module MediaTypes
|
|
32
32
|
attribute key, value
|
33
33
|
end
|
34
34
|
|
35
|
+
hidden do
|
36
|
+
link :type, href: problem.type
|
37
|
+
end
|
35
38
|
attribute :type, problem.type
|
36
39
|
attribute :title, title unless title.nil?
|
37
40
|
attribute :detail, detail unless detail.nil?
|
@@ -51,6 +54,10 @@ module MediaTypes
|
|
51
54
|
end
|
52
55
|
end.compact.first || problem.translations.keys.first
|
53
56
|
translation = problem.translations[translation_entry]
|
57
|
+
|
58
|
+
hidden do
|
59
|
+
link :type, href: problem.type
|
60
|
+
end
|
54
61
|
|
55
62
|
title = translation[:title]
|
56
63
|
detail = translation[:detail] || problem.error.message
|
@@ -321,7 +321,7 @@ module MediaTypes
|
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
324
|
-
def output_error(klazz)
|
324
|
+
def output_error(klazz, serializers: [])
|
325
325
|
rescue_from klazz do |error|
|
326
326
|
problem = Problem.new(error)
|
327
327
|
instance_exec { yield problem, error, self } if block_given?
|
@@ -331,7 +331,7 @@ module MediaTypes
|
|
331
331
|
|
332
332
|
render_media(
|
333
333
|
problem,
|
334
|
-
serializers: [registrations],
|
334
|
+
serializers: [registrations] + serializers.map { |s| s.outputs_for(views: [nil])},
|
335
335
|
status: problem.response_status_code
|
336
336
|
)
|
337
337
|
end
|
@@ -663,9 +663,13 @@ module MediaTypes
|
|
663
663
|
return
|
664
664
|
end
|
665
665
|
|
666
|
-
|
666
|
+
if context.serialization_custom_render.nil?
|
667
|
+
render body: result, **options
|
667
668
|
|
668
|
-
|
669
|
+
response.content_type = registrations.identifier_for(identifier)
|
670
|
+
else
|
671
|
+
context.serialization_custom_render.call(result)
|
672
|
+
end
|
669
673
|
end
|
670
674
|
end
|
671
675
|
end
|
@@ -35,13 +35,13 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ['lib']
|
37
37
|
|
38
|
-
spec.add_dependency 'actionpack', '>=
|
39
|
-
spec.add_dependency 'activesupport', '>=
|
40
|
-
spec.add_dependency 'media_types', '>= 2.
|
38
|
+
spec.add_dependency 'actionpack', '>= 6.0.0'
|
39
|
+
spec.add_dependency 'activesupport', '>= 6.0.0'
|
40
|
+
spec.add_dependency 'media_types', '>= 2.2.0', '< 3.0.0'
|
41
41
|
|
42
42
|
spec.add_development_dependency 'awesome_print'
|
43
43
|
spec.add_development_dependency 'bundler'
|
44
|
-
spec.add_development_dependency 'rails', '~>
|
44
|
+
spec.add_development_dependency 'rails', '~> 6.0'
|
45
45
|
spec.add_development_dependency 'rake', '~> 13.0'
|
46
46
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
47
47
|
spec.add_development_dependency 'oj'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: media_types-serialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -17,35 +17,35 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 6.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 6.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activesupport
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 6.0.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 6.0.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: media_types
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 2.
|
48
|
+
version: 2.2.0
|
49
49
|
- - "<"
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: 3.0.0
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version: 2.
|
58
|
+
version: 2.2.0
|
59
59
|
- - "<"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 3.0.0
|
@@ -93,14 +93,14 @@ dependencies:
|
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '6.0'
|
97
97
|
type: :development
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '6.0'
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: rake
|
106
106
|
requirement: !ruby/object:Gem::Requirement
|