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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64e776b0385e75bc7accfd536320105d6f54724f5b85f10ce8396c412e3d42f4
4
- data.tar.gz: fcac17f274d2f295d4ca57f20375caa7c54baf5cad1c8300a65416e5172bf2ae
3
+ metadata.gz: '096826bd7e4a4be4fcd147fec07f26d05aec0101b8651ae63ed376a7a2388077'
4
+ data.tar.gz: 2f783986be7ca3eff779e10a2ace5338d9ab7dbb755334ae79d01d7b422a77c9
5
5
  SHA512:
6
- metadata.gz: 60a7cfd98fd87f4b5ca3facb3338518015abb4567b5ff35741a16e7b36bd4bb58a2262dd74c34c884d119d5844c2cf1034e2f4ac566dfee6205e2797ad730c4a
7
- data.tar.gz: 1911cb60916f41d1ce594d7b98ed072cce91092bf6c00f60ae985fe50cc5380ef7367b0bff5a9d0f72f0f83a5b7a9072708ebccd81096c539a04c88603f0fc37
6
+ metadata.gz: f0b58cdb8eb8e4f8c0c8ad73cc607673768cba38399cf9c804db16a54198b3fe0799a18c641e7c05d10e03c2936fc96a416b80ff51ff4bd5e6d570b10a47e712
7
+ data.tar.gz: e82051321d55df89abe34c6d43e62a0158245c4fb9ae60060fc3e939df854626b3014285f2ac277f7632f6c3cd099ef349265bdfffbf7b7b226f76287bb53147
@@ -17,12 +17,12 @@ jobs:
17
17
 
18
18
  strategy:
19
19
  matrix:
20
- ruby-version: [2.7.x, 2.6.x, 2.5.x]
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: actions/setup-ruby@v1
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
@@ -10,3 +10,5 @@
10
10
  .idea/workspace.xml
11
11
  .idea/usage.statistics.xml
12
12
  .idea/tasks.xml
13
+
14
+ /media_types-serialization*.gem
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0
4
+
5
+ - ✨ Add support for redirecting in serializers
6
+
3
7
  ## 1.3.9
4
8
 
5
9
  - ✨ Make serializer look slightly better on mobile by zooming in initially
data/Gemfile.lock CHANGED
@@ -1,128 +1,158 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types-serialization (1.3.9)
5
- actionpack (>= 4.0.0)
6
- activesupport (>= 4.0.0)
7
- media_types (>= 2.1.1, < 3.0.0)
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 (5.2.6)
13
- actionpack (= 5.2.6)
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
- actionmailer (5.2.6)
17
- actionpack (= 5.2.6)
18
- actionview (= 5.2.6)
19
- activejob (= 5.2.6)
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 (5.2.6)
23
- actionview (= 5.2.6)
24
- activesupport (= 5.2.6)
25
- rack (~> 2.0, >= 2.0.8)
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.2)
29
- actionview (5.2.6)
30
- activesupport (= 5.2.6)
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.0, >= 1.0.3)
35
- activejob (5.2.6)
36
- activesupport (= 5.2.6)
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 (5.2.6)
39
- activesupport (= 5.2.6)
40
- activerecord (5.2.6)
41
- activemodel (= 5.2.6)
42
- activesupport (= 5.2.6)
43
- arel (>= 9.0)
44
- activestorage (5.2.6)
45
- actionpack (= 5.2.6)
46
- activerecord (= 5.2.6)
47
- marcel (~> 1.0.0)
48
- activesupport (5.2.6)
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 (>= 0.7, < 2)
51
- minitest (~> 5.1)
52
- tzinfo (~> 1.1)
53
- arel (9.0.0)
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.1.9)
73
+ concurrent-ruby (1.2.2)
57
74
  crass (1.0.6)
58
- erubi (1.10.0)
59
- globalid (0.5.2)
75
+ date (3.3.3)
76
+ erubi (1.12.0)
77
+ globalid (1.1.0)
60
78
  activesupport (>= 5.0)
61
- i18n (1.8.10)
79
+ i18n (1.12.0)
62
80
  concurrent-ruby (~> 1.0)
63
- loofah (2.12.0)
81
+ loofah (2.19.1)
64
82
  crass (~> 1.0.2)
65
83
  nokogiri (>= 1.5.9)
66
- mail (2.7.1)
84
+ mail (2.8.1)
67
85
  mini_mime (>= 0.1.1)
68
- marcel (1.0.1)
69
- media_types (2.1.1)
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.0)
72
- minitest (5.14.4)
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.12.3-x64-mingw32)
104
+ nokogiri (1.14.2-x64-mingw32)
75
105
  racc (~> 1.4)
76
- nokogiri (1.12.3-x86_64-linux)
77
- racc (~> 1.4)
78
- oj (3.13.4)
79
- racc (1.5.2)
80
- rack (2.2.3)
81
- rack-test (1.1.0)
82
- rack (>= 1.0, < 3)
83
- rails (5.2.6)
84
- actioncable (= 5.2.6)
85
- actionmailer (= 5.2.6)
86
- actionpack (= 5.2.6)
87
- actionview (= 5.2.6)
88
- activejob (= 5.2.6)
89
- activemodel (= 5.2.6)
90
- activerecord (= 5.2.6)
91
- activestorage (= 5.2.6)
92
- activesupport (= 5.2.6)
93
- bundler (>= 1.3.0)
94
- railties (= 5.2.6)
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.4.1)
100
- loofah (~> 2.3)
101
- railties (5.2.6)
102
- actionpack (= 5.2.6)
103
- activesupport (= 5.2.6)
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 (>= 0.8.7)
106
- thor (>= 0.19.0, < 2.0)
135
+ rake (>= 12.2)
136
+ thor (~> 1.0)
107
137
  rake (13.0.6)
108
- sprockets (4.0.2)
138
+ sprockets (4.2.0)
109
139
  concurrent-ruby (~> 1.0)
110
- rack (> 1, < 3)
111
- sprockets-rails (3.2.2)
112
- actionpack (>= 4.0)
113
- activesupport (>= 4.0)
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.0)
116
- thread_safe (0.3.6)
117
- tzinfo (1.2.9)
118
- thread_safe (~> 0.1)
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 (~> 5.2)
163
+ rails (~> 6.0)
134
164
  rake (~> 13.0)
135
165
 
136
166
  BUNDLED WITH
137
- 2.2.17
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 `context.class.render(params)`
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MediaTypes
4
4
  module Serialization
5
- VERSION = '1.3.9'
5
+ VERSION = '1.4.0'
6
6
  end
7
7
  end
@@ -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
- render body: result, **options
666
+ if context.serialization_custom_render.nil?
667
+ render body: result, **options
667
668
 
668
- response.content_type = registrations.identifier_for(identifier)
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', '>= 4.0.0'
39
- spec.add_dependency 'activesupport', '>= 4.0.0'
40
- spec.add_dependency 'media_types', '>= 2.1.1', '< 3.0.0'
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', '~> 5.2'
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.3.9
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: 2021-11-04 00:00:00.000000000 Z
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: 4.0.0
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: 4.0.0
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: 4.0.0
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: 4.0.0
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.1.1
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.1.1
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: '5.2'
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: '5.2'
103
+ version: '6.0'
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rake
106
106
  requirement: !ruby/object:Gem::Requirement