media_types-serialization 1.1.0 → 1.3.2

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: f7eabad722268eb76ce511245770ef7fb6a4c07c9d0ce8be05ac0995a4ebe309
4
- data.tar.gz: f749dfcbc363662ddb7e7a2d81162168fa1dea8bb086aa57074d1a51d3bfc5c5
3
+ metadata.gz: b21177c2ffb12e53fc1c077dc76e3228d79db6a26c9dbf8f84a0f8703e79d31f
4
+ data.tar.gz: 61355285dbc6025e54c7fb24ccb53e453a036135515baa5abac76e88344d2b99
5
5
  SHA512:
6
- metadata.gz: e64bafc043adbb81c87475e2898687f1495b7e15f8bb71dbb73fe2a0ea9f39556d4644f60f3f6658d196efe533f8cf8a504b7b8936e7812dc607bce628f400e4
7
- data.tar.gz: e4aa0a59bc0e3a8f785feda5d99b15a5f193984b3fd6deb5b06577e90b0c8628f615c7214258c0d08383bd5fc171a7249d8985a14d0fadc4f32734899981572a
6
+ metadata.gz: c00d90c86d30ff29980942d443d93ba4368ec69c161e1d0da28cd9b7dff9b1616662e035ee42c702c8d49d2b31ec9dd2b98e2bfc9a419044d244e66430c6b71a
7
+ data.tar.gz: 6792550a393bb078940e3db00407881ca698e439f9b3387ea2e04a007c3f17efd00a57f344b2ec2f3dd698e57001185262a858dad53fed0cd10055717beabcb3
data/.gitignore CHANGED
@@ -1,12 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- .idea/workspace.xml
11
- .idea/usage.statistics.xml
12
- .idea/tasks.xml
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .idea/workspace.xml
11
+ .idea/usage.statistics.xml
12
+ .idea/tasks.xml
data/.idea/.rakeTasks CHANGED
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <Settings><!--This file was automatically generated by Ruby plugin.
3
- You are allowed to:
4
- 1. Remove rake task
5
- 2. Add existing rake tasks
6
- To add existing rake tasks automatically delete this file and reload the project.
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
7
  --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build media_types-serialization-0.5.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install media_types-serialization-0.5.1.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install media_types-serialization-0.5.1.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.5.1 and build and push media_types-serialization-0.5.1.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
@@ -1,6 +1,6 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
- </profile>
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
6
  </component>
@@ -1,20 +1,20 @@
1
- <component name="ProjectRunConfigurationManager">
2
- <configuration default="false" name="test" type="RakeRunConfigurationType" factoryName="Rake">
3
- <module name="media_types-serialization" />
4
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="" />
5
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
6
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
7
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
8
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
9
- <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
10
- <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
11
- <EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov" />
12
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_NAME" VALUE="test" />
13
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ARGS" VALUE="" />
14
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ATTACHED_TEST_FRAMEWORKS" VALUE=":test_unit " />
15
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_TRACE" VALUE="false" />
16
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_DRYRUN" VALUE="false" />
17
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_PREREQS" VALUE="false" />
18
- <method v="2" />
19
- </configuration>
1
+ <component name="ProjectRunConfigurationManager">
2
+ <configuration default="false" name="test" type="RakeRunConfigurationType" factoryName="Rake">
3
+ <module name="media_types-serialization" />
4
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="" />
5
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
6
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
7
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
8
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
9
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
10
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
11
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov" />
12
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_NAME" VALUE="test" />
13
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ARGS" VALUE="" />
14
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ATTACHED_TEST_FRAMEWORKS" VALUE=":test_unit " />
15
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_TRACE" VALUE="false" />
16
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_DRYRUN" VALUE="false" />
17
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_PREREQS" VALUE="false" />
18
+ <method v="2" />
19
+ </configuration>
20
20
  </component>
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.2
4
+
5
+ - 🐛 Fix override suffix not returning self or new
6
+
7
+ ## 1.3.1
8
+
9
+ - 🐛 Fix api viewer
10
+ - 🐛 Fix `output_raw` suffix (`+json` needs to be `''`)
11
+
12
+ ## 1.3.0
13
+
14
+ - ✨ Add `formats:` to `output_html` and default it to `[:html]`, so rails behaves
15
+ - 🐛 Fix stale references to `render media:`
16
+ - 🐛 Fix inconsistent `context:` passing for `Serializer.serialize`
17
+
18
+ ## 1.2.0
19
+
20
+ - ✨ Add `view:` to `output_html` which renders a specific rails view.
21
+
3
22
  ## 1.1.0
4
23
 
5
24
  - ✨ Add _allow_output_html_: Fallback to rails rendering.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in media_types-serialization.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in media_types-serialization.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,137 +1,137 @@
1
- PATH
2
- remote: .
3
- specs:
4
- media_types-serialization (1.0.3)
5
- actionpack (>= 4.0.0)
6
- activesupport (>= 4.0.0)
7
- media_types (>= 2.0.0, < 3.0.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- actioncable (5.2.6)
13
- actionpack (= 5.2.6)
14
- nio4r (~> 2.0)
15
- 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)
20
- mail (~> 2.5, >= 2.5.4)
21
- 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)
26
- rack-test (>= 0.6.3)
27
- rails-dom-testing (~> 2.0)
28
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- actionview (5.2.6)
30
- activesupport (= 5.2.6)
31
- builder (~> 3.1)
32
- erubi (~> 1.4)
33
- rails-dom-testing (~> 2.0)
34
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
- activejob (5.2.6)
36
- activesupport (= 5.2.6)
37
- 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)
49
- 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)
54
- awesome_print (1.9.2)
55
- builder (3.2.4)
56
- concurrent-ruby (1.1.9)
57
- crass (1.0.6)
58
- erubi (1.10.0)
59
- globalid (0.4.2)
60
- activesupport (>= 4.2.0)
61
- i18n (1.8.10)
62
- concurrent-ruby (~> 1.0)
63
- loofah (2.10.0)
64
- crass (~> 1.0.2)
65
- nokogiri (>= 1.5.9)
66
- mail (2.7.1)
67
- mini_mime (>= 0.1.1)
68
- marcel (1.0.1)
69
- media_types (2.0.1)
70
- method_source (1.0.0)
71
- mini_mime (1.1.0)
72
- minitest (5.14.4)
73
- nio4r (2.5.7)
74
- nokogiri (1.11.7-x64-mingw32)
75
- racc (~> 1.4)
76
- nokogiri (1.11.7-x86_64-linux)
77
- racc (~> 1.4)
78
- oj (3.11.7)
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)
95
- sprockets-rails (>= 2.0.0)
96
- rails-dom-testing (2.0.3)
97
- activesupport (>= 4.2.0)
98
- nokogiri (>= 1.6)
99
- rails-html-sanitizer (1.3.0)
100
- loofah (~> 2.3)
101
- railties (5.2.6)
102
- actionpack (= 5.2.6)
103
- activesupport (= 5.2.6)
104
- method_source
105
- rake (>= 0.8.7)
106
- thor (>= 0.19.0, < 2.0)
107
- rake (13.0.3)
108
- sprockets (4.0.2)
109
- concurrent-ruby (~> 1.0)
110
- rack (> 1, < 3)
111
- sprockets-rails (3.2.2)
112
- actionpack (>= 4.0)
113
- activesupport (>= 4.0)
114
- 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)
119
- websocket-driver (0.7.5)
120
- websocket-extensions (>= 0.1.0)
121
- websocket-extensions (0.1.5)
122
-
123
- PLATFORMS
124
- x64-mingw32
125
- x86_64-linux
126
-
127
- DEPENDENCIES
128
- awesome_print
129
- bundler
130
- media_types-serialization!
131
- minitest (~> 5.0)
132
- oj
133
- rails (~> 5.2)
134
- rake (~> 13.0)
135
-
136
- BUNDLED WITH
137
- 2.2.7
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ media_types-serialization (1.3.2)
5
+ actionpack (>= 4.0.0)
6
+ activesupport (>= 4.0.0)
7
+ media_types (>= 2.0.0, < 3.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (5.2.6)
13
+ actionpack (= 5.2.6)
14
+ nio4r (~> 2.0)
15
+ 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)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ 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)
26
+ rack-test (>= 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (5.2.6)
30
+ activesupport (= 5.2.6)
31
+ builder (~> 3.1)
32
+ erubi (~> 1.4)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
+ activejob (5.2.6)
36
+ activesupport (= 5.2.6)
37
+ 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)
49
+ 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)
54
+ awesome_print (1.9.2)
55
+ builder (3.2.4)
56
+ concurrent-ruby (1.1.9)
57
+ crass (1.0.6)
58
+ erubi (1.10.0)
59
+ globalid (0.4.2)
60
+ activesupport (>= 4.2.0)
61
+ i18n (1.8.10)
62
+ concurrent-ruby (~> 1.0)
63
+ loofah (2.10.0)
64
+ crass (~> 1.0.2)
65
+ nokogiri (>= 1.5.9)
66
+ mail (2.7.1)
67
+ mini_mime (>= 0.1.1)
68
+ marcel (1.0.1)
69
+ media_types (2.0.1)
70
+ method_source (1.0.0)
71
+ mini_mime (1.1.0)
72
+ minitest (5.14.4)
73
+ nio4r (2.5.7)
74
+ nokogiri (1.11.7-x64-mingw32)
75
+ racc (~> 1.4)
76
+ nokogiri (1.11.7-x86_64-linux)
77
+ racc (~> 1.4)
78
+ oj (3.12.3)
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)
95
+ sprockets-rails (>= 2.0.0)
96
+ rails-dom-testing (2.0.3)
97
+ activesupport (>= 4.2.0)
98
+ nokogiri (>= 1.6)
99
+ rails-html-sanitizer (1.3.0)
100
+ loofah (~> 2.3)
101
+ railties (5.2.6)
102
+ actionpack (= 5.2.6)
103
+ activesupport (= 5.2.6)
104
+ method_source
105
+ rake (>= 0.8.7)
106
+ thor (>= 0.19.0, < 2.0)
107
+ rake (13.0.6)
108
+ sprockets (4.0.2)
109
+ concurrent-ruby (~> 1.0)
110
+ rack (> 1, < 3)
111
+ sprockets-rails (3.2.2)
112
+ actionpack (>= 4.0)
113
+ activesupport (>= 4.0)
114
+ 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)
119
+ websocket-driver (0.7.5)
120
+ websocket-extensions (>= 0.1.0)
121
+ websocket-extensions (0.1.5)
122
+
123
+ PLATFORMS
124
+ x64-mingw32
125
+ x86_64-linux
126
+
127
+ DEPENDENCIES
128
+ awesome_print
129
+ bundler
130
+ media_types-serialization!
131
+ minitest (~> 5.0)
132
+ oj
133
+ rails (~> 5.2)
134
+ rake (~> 13.0)
135
+
136
+ BUNDLED WITH
137
+ 2.2.7
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Derk-Jan Karrenbeld
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Derk-Jan Karrenbeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -79,11 +79,13 @@ class BookController < ActionController::API
79
79
  end
80
80
  ```
81
81
 
82
- While using the controller integration the context will always be set to the current controller. This allows you to construct urls.
82
+ While using the controller integration the context will always be set to the current controller.
83
+ This allows you to construct urls.
83
84
 
84
85
  ### Adding HATEOAS responses to existing routes
85
86
 
86
- When creating a mobile application it's often useful to allow the app to request a non-html representation of a specific url. If you have an existing route:
87
+ When creating a mobile application it's often useful to allow the app to request a non-html representation of a specific url.
88
+ If you have an existing route:
87
89
 
88
90
  ```ruby
89
91
  class BookController < ApplicationController
@@ -113,7 +115,9 @@ end
113
115
 
114
116
  ### Validations
115
117
 
116
- Right now the serializer does not validate incoming or outgoing information. This can cause issues when you accidentally emit non-conforming data that people start to depend on. To make sure you don't do that you can specify a [Media Type validator](https://github.com/SleeplessByte/media-types-ruby):
118
+ Right now the serializer does not validate incoming or outgoing information.
119
+ This can cause issues when you accidentally emit non-conforming data that people start to depend on.
120
+ To make sure you don't do that you can specify a [Media Type validator](https://github.com/SleeplessByte/media-types-ruby):
117
121
 
118
122
  ```ruby
119
123
  require 'media_types'
@@ -179,7 +183,8 @@ BookSerializer.serialize(book, BookValidator.version(2), context: nil)
179
183
 
180
184
  ### Links
181
185
 
182
- When making [HATEOAS](https://docs.delftsolutions.nl/wiki/HATEOAS_API) compliant applications it's very useful to include `Link` headers in your response so clients can use a `HEAD` request instead of having to fetch the entire resource. Serializers have convenience methods to help with this:
186
+ When making [HATEOAS](https://docs.delftsolutions.nl/wiki/HATEOAS_API) compliant applications it's very useful to include `Link` headers in your response so clients can use a `HEAD` request instead of having to fetch the entire resource.
187
+ Serializers have convenience methods to help with this:
183
188
 
184
189
  ```ruby
185
190
  class BookSerializer < MediaTypes::Serialization::Base
@@ -218,7 +223,8 @@ There are convenience methods for serializing arrays of objects based on a templ
218
223
 
219
224
  #### Indexes
220
225
 
221
- An index is a collection of urls that point to members of the array. The index method automatically generates it based on the self links defined in the default view of the same version.
226
+ An index is a collection of urls that point to members of the array.
227
+ The index method automatically generates it based on the self links defined in the default view of the same version.
222
228
 
223
229
  ```ruby
224
230
  class BookSerializer < MediaTypes::Serialization::Base
@@ -260,7 +266,8 @@ BookSerializer.serialize([book], BookValidator.view(:index).version(3), context:
260
266
 
261
267
  #### Collections
262
268
 
263
- A collection inlines the member objects. The collection method automatically generates it based on the default view of the same version.
269
+ A collection inlines the member objects.
270
+ The collection method automatically generates it based on the default view of the same version.
264
271
 
265
272
  ```ruby
266
273
  class BookSerializer < MediaTypes::Serialization::Base
@@ -329,6 +336,7 @@ class BookSerializer < MediaTypes::Serialization::Base
329
336
  attribute :title, obj.title
330
337
  attribute :description, obj.description if version >= 2
331
338
  end
339
+ end
332
340
 
333
341
  input version: 3
334
342
  end
@@ -344,11 +352,11 @@ class BookController < ActionController::API
344
352
  book = Book.new
345
353
  book.title = 'Everything, abridged'
346
354
 
347
- render media: serialize_media(book), content_type: request.format.to_s
355
+ render_media serialize_media(book)
348
356
  end
349
357
 
350
358
  def create
351
- json = deserialize(request, context: self) # does validation for us
359
+ json = deserialize(request) # does validation for us
352
360
  puts json
353
361
  end
354
362
  end
@@ -390,14 +398,14 @@ class BookController < ActionController::API
390
398
  book = Book.new
391
399
  book.title = 'Everything, abridged'
392
400
 
393
- render media: serialize_media(book), content_type: request.format.to_s
401
+ render_media serialize_media(book)
394
402
  end
395
403
 
396
404
  def create
397
- book = deserialize(request, context: self)
405
+ book = deserialize(request)
398
406
  book.save!
399
407
 
400
- render media: serialize_media(book), content_type request.format.to_s
408
+ render_media serialize_media(book)
401
409
  end
402
410
  end
403
411
  ```
@@ -406,7 +414,9 @@ If you don't want to apply any input validation or deserialization you can use t
406
414
 
407
415
  ### Raw output
408
416
 
409
- Sometimes you need to output raw data. This cannot be validated. You do this as follows:
417
+ Sometimes you need to output raw data.
418
+ This cannot be validated.
419
+ You do this as follows:
410
420
 
411
421
  ```ruby
412
422
  class BookSerializer < MediaTypes::Serialization::Base
@@ -443,7 +453,8 @@ end
443
453
 
444
454
  ### Remapping media type identifiers
445
455
 
446
- Sometimes you already have old clients using an `application/json` media type identifier when they do requests. While this is not a good practise as this makes it hard to add new fields or remove old ones, this library has support for migrating away:
456
+ Sometimes you already have old clients using an `application/json` media type identifier when they do requests.
457
+ While this is not a good practise as this makes it hard to add new fields or remove old ones, this library has support for migrating away:
447
458
 
448
459
  ```ruby
449
460
  class BookSerializer < MediaTypes::Serialization::Base
@@ -475,7 +486,8 @@ Validation will be done using the remapped validator. Aliasses map to version `n
475
486
 
476
487
  ### HTML
477
488
 
478
- This library has a built in API viewer. The viewer can be accessed by by appending a `?api_viewer=last` query parameter to the URL.
489
+ This library has a built in API viewer.
490
+ The viewer can be accessed by by appending a `?api_viewer=last` query parameter to the URL.
479
491
 
480
492
  To enable the API viewer, use: `allow_api_viewer` in the controller.
481
493
 
@@ -493,11 +505,11 @@ class BookController < ActionController::API
493
505
  book = Book.new
494
506
  book.title = 'Everything, abridged'
495
507
 
496
- render media: serialize_media(book), content_type: request.format.to_s
508
+ render_media serialize_media(book)
497
509
  end
498
510
 
499
511
  def create
500
- json = deserialize(request, context: self) # does validation for us
512
+ json = deserialize(request) # does validation for us
501
513
  puts json
502
514
  end
503
515
  end
@@ -531,17 +543,18 @@ end
531
543
 
532
544
  #### Errors
533
545
 
534
- This library adds support for returning errors to clients using the [`application/problem+json`](https://tools.ietf.org/html/rfc7231) media type. You can catch and transform application errors by adding an `output_error` call before `freeze_io!`:
546
+ This library adds support for returning errors to clients using the [`application/problem+json`](https://tools.ietf.org/html/rfc7231) media type.
547
+ You can catch and transform application errors by adding an `output_error` call before `freeze_io!`:
535
548
 
536
549
  ```ruby
537
550
  class BookController < ActionController::API
538
551
  include MediaTypes::Serialization
539
552
 
540
- output_error CanCan::AccessDenied do |p, error|
541
- p.title 'You do not have enough permissions to perform this action.', lang: 'en'
542
- p.title 'Je hebt geen toestemming om deze actie uit te voeren.', lang: 'nl-NL'
553
+ output_error CanCan::AccessDenied do |problem_output, error|
554
+ problem_output.title 'You do not have enough permissions to perform this action.', lang: 'en'
555
+ problem_output.title 'Je hebt geen toestemming om deze actie uit te voeren.', lang: 'nl-NL'
543
556
 
544
- p.status_code :forbidden
557
+ problem_output.status_code :forbidden
545
558
  end
546
559
 
547
560
  freeze_io!
@@ -550,12 +563,14 @@ class BookController < ActionController::API
550
563
  end
551
564
  ```
552
565
 
553
- The exception you specified will be rescued by the controller and will be displayed to the user along with a link to the shared wiki page for that error type. Feel free to add instructions there on how clients should solve this problem. You can find more information at: [https://docs.delftsolutions.nl/wiki/Error](https://docs.delftsolutions.nl/wiki/Error)
554
- If you want to override this url you can use the `p.url(href)` function.
566
+ The exception you specified will be rescued by the controller and will be displayed to the user along with a link to the shared wiki page for that error type. Feel free to add instructions there on how clients should solve this problem.
567
+ You can find more information at: [https://docs.delftsolutions.nl/wiki/Error](https://docs.delftsolutions.nl/wiki/Error)
568
+ If you want to override this url you can use the `problem_output.url(href)` function.
555
569
 
556
- By default the `message` property of the error is used to fill the `details` field. You can override this by using the `p.override_details(description, lang:)` function.
570
+ By default the `message` property of the error is used to fill the `details` field.
571
+ You can override this by using the `problem_output.override_details(description, lang:)` function.
557
572
 
558
- Custom attributes can be added using the `p.attribute(name, value)` function.
573
+ Custom attributes can be added using the `problem_output.attribute(name, value)` function.
559
574
 
560
575
  ### Related
561
576
 
@@ -581,35 +596,47 @@ Either validator or unvalidated must be used while defining a serializer.
581
596
 
582
597
  #### `output( view:, version:, versions: ) do |obj, version, context|`
583
598
 
584
- Defines a serialization block. Either version or versions can be set. View should be a symbol or unset.
599
+ Defines a serialization block. Either version or versions can be set.
600
+ View should be a symbol or unset.
585
601
 
586
- Obj is the object to be serialized, version is the negotiated version and context is the context passed in from the serialize function. When using the controller integration, context is the current controller.
602
+ Obj is the object to be serialized, version is the negotiated version and context is the context passed in from the serialize function.
603
+ When using the controller integration, context is the current controller.
587
604
 
588
605
  The block should return an object to convert into JSON.
589
606
 
590
607
  #### `output_raw( view:, version:, versions: ) do |obj, version, context|`
591
608
 
592
- This has the same behavior as `output` but should return a string instead of an object. Output is not validated.
609
+ This has the same behavior as `output` but should return a string instead of an object.
610
+ Output is not validated.
593
611
 
594
612
  #### `output_alias( media_type_identifier, view:, hide_variant: false )`
595
613
 
596
- Defines a legacy mapping. This will make the deserializer parse the media type `media_type_identifier` as if it was version `nil` of the specified view. If view is undefined it will use the output serializer without a view defined.
614
+ Defines a legacy mapping. This will make the deserializer parse the media type `media_type_identifier` as if it was version `nil` of the specified view.
615
+ If `view` is undefined it will use the output serializer without a view defined.
597
616
 
598
- Response will have a content type equal to `[media_type_identifier]; variant=[mapped_media_type_identifier]`. If `hide_variant:` is true, the content type emitted will only be `[media_type_identifier]`.
617
+ Response will have a content type equal to `[media_type_identifier]; variant=[mapped_media_type_identifier]`.
618
+ If `hide_variant:` is true, the content type emitted will only be `[media_type_identifier]`.
619
+
620
+ > You cannot alias a _versioned_ media type, otherwise it would be easy to later break the definition by changing the version it aliases.
599
621
 
600
622
  #### `output_alias_optional( media_type_identifier, view:, hide_variant: false )`
601
623
 
602
- Has the same behavior as `output_alias` but can be used by multiple serializers. The serializer that is loaded last in the controller 'wins' control over this media type identifier. If any of the serializers have an `output_alias` defined with the same media type identifier that one will win instead.
624
+ Has the same behavior as `output_alias` but can be used by multiple serializers.
625
+ The serializer that is loaded last in the controller 'wins' control over this media type identifier.
626
+ If any of the serializers have an `output_alias` defined with the same media type identifier that one will win instead.
603
627
 
604
628
  Response will have a content type equal to `[media_type_identifier]; variant=[mapped_media_type_identifier]`. If `hide_variant:` is true, the content type emitted will only be `[media_type_identifier]`.
605
629
 
606
630
  #### `input( view:, version:, versions: ) do |obj, version, context|`
607
631
 
608
- Defines a deserialization block. Either version or versions can be set. View should be a symbol or unset.
632
+ Defines a deserialization block. Either version or versions can be set.
633
+ View should be a symbol or unset.
609
634
 
610
- Obj is the object to be serialized, version is the negotiated version and context is the context passed in from the serialize function. When using the controller integration, context is the current controller.
635
+ Obj is the object to be serialized, version is the negotiated version and context is the context passed in from the serialize function.
636
+ When using the controller integration, context is the current controller.
611
637
 
612
- The block should return the internal representation of the object. Best practise is to make sure not to change state in this function but to leave that up to the controller.
638
+ The block should return the internal representation of the object.
639
+ Best practise is to make sure not to change state in this function but to leave that up to the controller.
613
640
 
614
641
  #### `input_raw( view:, version:, versions: ) do |bytes, version, context|`
615
642
 
@@ -617,11 +644,17 @@ This has the same behavior as `input` but takes in raw data. Input is not valida
617
644
 
618
645
  #### `input_alias( media_type_identifier, view: )`
619
646
 
620
- Defines a legacy mapping. This will make the serializer parse the media type `media_type_identifier` as if it was version 1 of the specified view. If view is undefined it will use the input serializer without a view defined.
647
+ Defines a legacy mapping.
648
+ This will make the serializer parse the media type `media_type_identifier` as if it was version `nil` of the specified view.
649
+ If view is undefined it will use the input serializer without a view defined.
650
+
651
+ > You cannot alias a _versioned_ media type, otherwise it would be easy to later break the definition by changing the version it aliases.
621
652
 
622
653
  #### `input_alias_optional( media_type_identifier, view: )`
623
654
 
624
- Has the same behavior as `input_alias` but can be used by multiple serializers. The serializer that is loaded last in the controller 'wins' control over this media type identifier. If any of the serializers have an `input_alias` defined with the same media type identifier that one will win instead.
655
+ Has the same behavior as `input_alias` but can be used by multiple serializers.
656
+ The serializer that is loaded last in the controller 'wins' control over this media type identifier.
657
+ If any of the serializers have an `input_alias` defined with the same media type identifier that one will win instead.
625
658
 
626
659
  #### `disable_wildcards`
627
660
 
@@ -633,13 +666,15 @@ The following methods are available within an `output ... do` block.
633
666
 
634
667
  #### `attribute( key, value = {} ) do`
635
668
 
636
- Sets a value for the given key. If a block is given, any `attribute`, `link`, `collection` and `index` statements are run in context of `value`.
669
+ Sets a value for the given key.
670
+ If a block is given, any `attribute`, `link`, `collection` and `index` statements are run in context of `value`.
637
671
 
638
672
  Returns the built up context so far.
639
673
 
640
674
  #### `link( rel, href:, emit_header: true, **attributes )`
641
675
 
642
- Adds a `_link` block to the current context. Also adds the specified link to the HTTP Link header. `attributes` allows passing in custom attributes.
676
+ Adds a `_link` block to the current context. Also adds the specified link to the HTTP Link header.
677
+ `attributes` allows passing in custom attributes.
643
678
 
644
679
  If `emit_header` is `true` the link will also be emitted as a http header.
645
680
 
@@ -660,7 +695,9 @@ Returns the built up context so far.
660
695
 
661
696
  #### `hidden do`
662
697
 
663
- Sometimes you want to add links without actually modifying the object. Calls to `attribute`, `link`, `index`, `collection` made inside this block won't modify the context. Any calls to link will only set the HTTP Link header.
698
+ Sometimes you want to add links without actually modifying the object.
699
+ Calls to `attribute`, `link`, `index`, `collection` made inside this block won't modify the context.
700
+ Any calls to link will only set the HTTP Link header.
664
701
 
665
702
  Returns the unmodified context.
666
703
 
@@ -684,17 +721,20 @@ These functions are available during the controller definition if you add `inclu
684
721
 
685
722
  #### `allow_output_serializer( serializer, views: nil, **filters )`
686
723
 
687
- Configure the controller to allow the client to request responses emitted by the specified serializer. Optionally allows you to specify which views to allow by passing an array in the views parameter.
724
+ Configure the controller to allow the client to request responses emitted by the specified serializer.
725
+ Optionally allows you to specify which views to allow by passing an array in the views parameter.
688
726
 
689
727
  Accepts the same filters as `before_action`.
690
728
 
691
- #### `allow_output_html( as: nil, layout: nil, **filters )`
729
+ #### `allow_output_html( as: nil, view: nil, layout: nil, **filters )`
692
730
 
693
731
  Allows falling back to the default Rails view rendering when the client asks for the media type in the `as:` parameter or `text/html` if `as:` is unset.
694
732
 
695
- The `Content-Type` of the response will be `text/html` if the `as:` parameter is unset. If the `as:` parameter is set, it will include it in the variant parameter: `text/html; variant=application/vnd.xpbytes.borderless`.
733
+ The `Content-Type` of the response will be `text/html` if the `as:` parameter is unset.
734
+ If the `as:` parameter is set, it will include it in the variant parameter: `text/html; variant=application/vnd.xpbytes.borderless`.
696
735
 
697
736
  Accepts the same filters as `before_action`.
737
+ You can set the template to use using the `view:` parameter.
698
738
 
699
739
  #### `allow_output_docs( description, **filters )`
700
740
 
@@ -704,7 +744,8 @@ Accepts the same filters as `before_action`.
704
744
 
705
745
  #### `allow_input_serializer( serializer, views: nil, **filters )`
706
746
 
707
- Configure the controller to allow the client to send bodies with a `Content-Type` that can be deserialized using the specified serializer. Optionally allows you to specify which views to allow by passing an array in the views parameter.
747
+ Configure the controller to allow the client to send bodies with a `Content-Type` that can be deserialized using the specified serializer.
748
+ Optionally allows you to specify which views to allow by passing an array in the views parameter.
708
749
 
709
750
  Accepts the same filters as `before_action`.
710
751
 
@@ -738,7 +779,8 @@ Enables rendering the api viewer when adding the `api_viewer=last` query paramet
738
779
 
739
780
  #### `freeze_io!(**filter_opts)`
740
781
 
741
- Registers serialization and deserialization in the controller. This function must be called before using the controller.
782
+ Registers serialization and deserialization in the controller.
783
+ This function must be called before using the controller.
742
784
 
743
785
  ### Controller usage
744
786
 
@@ -746,7 +788,8 @@ These functions are available during method execution in the controller.
746
788
 
747
789
  #### `render_media( obj, serializers: nil, not_acceptable_serializer: nil, **options ) do`
748
790
 
749
- Serializes an object and renders it using the appropriate content type. Options are passed through to the controller `render` function. Allows you to specify different objects to different serializers using a block:
791
+ Serializes an object and renders it using the appropriate content type.
792
+ Options are passed through to the controller `render` function. Allows you to specify different objects to different serializers using a block:
750
793
 
751
794
  ```ruby
752
795
  render_media do
@@ -757,13 +800,15 @@ render_media do
757
800
  end
758
801
  ```
759
802
 
760
- Warning: this block can be called multiple times when used together with recursive serializers like the API viewer. Try to avoid changing state in this block.
803
+ **Warning**: this block can be called multiple times when used together with recursive serializers like the API viewer.
804
+ Try to _avoid changing state_ in this block.
761
805
 
762
806
  If you want to render with different serializers than defined in the controller you can pass an array of serializers in the `serializers` property.
763
807
 
764
808
  If you want to override the serializer that is used to render the response when no acceptable Content-Type could be negotiated you can pass the desired serializer in the `not_acceptable_serializer` property.
765
809
 
766
- This method throws a `MediaTypes::Serialization::OutputValidationFailedError` error if the output does not conform to the format defined by the configured validator. Best practise is to return a 500 error to the client.
810
+ This method throws a `MediaTypes::Serialization::OutputValidationFailedError` error if the output does not conform to the format defined by the configured validator.
811
+ Best practise is to return a 500 error to the client.
767
812
 
768
813
  If no acceptable Content-Type could be negotiated the response will be rendered using the serialized defined by the class `not_acceptable_serializer` function or by the `not_acceptable_serializer` property.
769
814
 
@@ -805,12 +850,11 @@ HERE
805
850
 
806
851
  ## Development
807
852
 
808
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
809
- also run `bin/console` for an interactive prompt that will allow you to experiment.
853
+ After checking out the repo, run `bin/setup` to install dependencies.
854
+ Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
810
855
 
811
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
812
- version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
813
- push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
856
+ To install this gem onto your local machine, run `bundle exec rake install`.
857
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
814
858
 
815
859
  ## Contributing
816
860
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task :default => :test
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "media_types/serialization"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "media_types/serialization"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -184,7 +184,7 @@ module MediaTypes
184
184
  end
185
185
  end
186
186
 
187
- def allow_output_html(as: nil, layout: nil, **filter_opts)
187
+ def allow_output_html(as: nil, view: nil, layout: nil, formats: [:html], variants: nil, **filter_opts)
188
188
  before_action(**filter_opts) do
189
189
  raise SerializersAlreadyFrozenError if defined? @serialization_frozen
190
190
 
@@ -197,11 +197,13 @@ module MediaTypes
197
197
  validator = FakeValidator.new(as.nil? ? 'text/html' : as)
198
198
 
199
199
  block = lambda { |_, _, controller|
200
- if layout.nil?
201
- controller.render_to_string
202
- else
203
- controller.render_to_string(layout: layout)
204
- end
200
+ options = {}
201
+ options[:layout] = layout unless layout.nil?
202
+ options[:template] = view unless view.nil?
203
+ options[:formats] = formats unless formats.nil?
204
+ options[:variants] = variants unless variants.nil?
205
+
206
+ controller.render_to_string(**options)
205
207
  }
206
208
 
207
209
  html_registration.register_block(nil, validator, nil, block, true, wildcards: true)
@@ -334,11 +336,6 @@ module MediaTypes
334
336
  end
335
337
  # rubocop:enable Metrics/BlockLength
336
338
 
337
- included do
338
- protected
339
-
340
- end
341
-
342
339
  protected
343
340
 
344
341
  def serialize(victim, media_type, serializer: Object.new, links: [], vary: ['Accept'])
@@ -358,6 +355,7 @@ module MediaTypes
358
355
  if obj == MEDIA_TYPES_SERIALIZATION_OBJ_IS_UNDEFINED && block.nil?
359
356
  raise 'render_media was called without an object. Please provide one or supply a block to match the serializer.'
360
357
  end
358
+
361
359
  obj = nil if obj == MEDIA_TYPES_SERIALIZATION_OBJ_IS_UNDEFINED
362
360
 
363
361
  raise SerializersNotFrozenError unless defined? @serialization_frozen
@@ -387,10 +385,17 @@ module MediaTypes
387
385
  selector.instance_exec(&block)
388
386
 
389
387
  raise UnmatchedSerializerError, serializer unless selector.matched
388
+
390
389
  obj = selector.value
391
390
  end
392
391
 
393
- serialization_render_resolved(obj: obj, serializer: serializer, identifier: identifier, registrations: registration, options: options)
392
+ serialization_render_resolved(
393
+ obj: obj,
394
+ serializer: serializer,
395
+ identifier: identifier,
396
+ registrations: registration,
397
+ options: options
398
+ )
394
399
  end
395
400
 
396
401
  def deserialize(request)
@@ -409,6 +414,7 @@ module MediaTypes
409
414
  raise SerializersNotFrozenError unless defined?(@serialization_frozen)
410
415
  raise NoInputReceivedError if request.content_type.blank?
411
416
  raise InputNotAcceptableError unless @serialization_input_registrations.has? request.content_type
417
+
412
418
  @serialization_input_registrations.call(@serialization_decoded_input, request.content_type, self)
413
419
  end
414
420
 
@@ -419,6 +425,7 @@ module MediaTypes
419
425
  registration = registration.registrations[identifier]
420
426
 
421
427
  raise 'Assertion failed, inconsistent answer from resolve_media_type' if registration.nil?
428
+
422
429
  registration.serializer
423
430
  end
424
431
 
@@ -426,8 +433,12 @@ module MediaTypes
426
433
 
427
434
  def resolve_media_type(request, registration, allow_last: true)
428
435
  if defined? @serialization_override_accept
429
- @serialization_override_accept = registration.registrations.keys.last if allow_last && @serialization_override_accept == 'last'
436
+ if allow_last && @serialization_override_accept == 'last'
437
+ @serialization_override_accept = registration.registrations.keys.last
438
+ end
439
+
430
440
  return nil unless registration.has? @serialization_override_accept
441
+
431
442
  return @serialization_override_accept
432
443
  end
433
444
 
@@ -475,7 +486,10 @@ module MediaTypes
475
486
  input_is_allowed = @serialization_input_registrations.has? request.content_type unless request.content_type.blank?
476
487
 
477
488
  unless input_is_allowed || all_allowed
478
- serializers = @serialization_unsupported_media_type_serializer || [MediaTypes::Serialization::Serializers::ProblemSerializer, MediaTypes::Serialization::Serializers::FallbackUnsupportedMediaTypeSerializer]
489
+ serializers = @serialization_unsupported_media_type_serializer || [
490
+ MediaTypes::Serialization::Serializers::ProblemSerializer,
491
+ MediaTypes::Serialization::Serializers::FallbackUnsupportedMediaTypeSerializer
492
+ ]
479
493
  registrations = SerializationRegistration.new(:output)
480
494
  serializers.each do |s|
481
495
  registrations = registrations.merge(s.outputs_for(views: [nil, :html]))
@@ -503,7 +517,10 @@ module MediaTypes
503
517
  input_data = request.body.read
504
518
  @serialization_decoded_input = @serialization_input_registrations.decode(input_data, request.content_type, self)
505
519
  rescue InputValidationFailedError => e
506
- serializers = @serialization_input_validation_failed_serializer || [MediaTypes::Serialization::Serializers::ProblemSerializer, MediaTypes::Serialization::Serializers::InputValidationErrorSerializer]
520
+ serializers = @serialization_input_validation_failed_serializer || [
521
+ MediaTypes::Serialization::Serializers::ProblemSerializer,
522
+ MediaTypes::Serialization::Serializers::InputValidationErrorSerializer
523
+ ]
507
524
  registrations = SerializationRegistration.new(:output)
508
525
  serializers.each do |s|
509
526
  registrations = registrations.merge(s.outputs_for(views: [nil, :html]))
@@ -549,7 +566,13 @@ module MediaTypes
549
566
  actions: @serialization_available_serializers,
550
567
  }
551
568
 
552
- serialization_render_resolved obj: input, serializer: description_serializer, identifier: endpoint_matched_identifier, registrations: @serialization_output_registrations, options: {}
569
+ serialization_render_resolved(
570
+ obj: input,
571
+ serializer: description_serializer,
572
+ identifier: endpoint_matched_identifier,
573
+ registrations: @serialization_output_registrations,
574
+ options: {}
575
+ )
553
576
  return
554
577
  end
555
578
 
@@ -595,7 +618,7 @@ module MediaTypes
595
618
  output: result,
596
619
  links: links,
597
620
  }
598
- wrapped = @serialization_wrapping_renderer.serialize input, '*/*', self
621
+ wrapped = @serialization_wrapping_renderer.serialize input, '*/*', context: self
599
622
  render body: wrapped
600
623
 
601
624
  response.content_type = 'text/html'
@@ -55,7 +55,7 @@ module MediaTypes
55
55
  raise ValidatorNotSpecifiedError, :output if serializer_validator.nil?
56
56
 
57
57
  versions.each do |v|
58
- validator = serializer_validator.view(view).version(v)
58
+ validator = serializer_validator.view(view).version(v).override_suffix('')
59
59
 
60
60
  serializer_output_registration.register_block(self, validator, v, block, true, wildcards: !self.serializer_disable_wildcards)
61
61
  end
@@ -106,22 +106,22 @@ module MediaTypes
106
106
  validator = serializer_validator.view(view)
107
107
  victim_identifier = validator.identifier
108
108
 
109
- serializer_input_registration.register_alias(self, media_type_identifier, victim_identifier, false)
109
+ serializer_input_registration.register_alias(self, media_type_identifier, victim_identifier, false, true, wildcards: false)
110
110
  end
111
111
 
112
112
  def input_alias_optional(media_type_identifier, view: nil)
113
113
  validator = serializer_validator.view(view)
114
114
  victim_identifier = validator.identifier
115
115
 
116
- serializer_input_registration.register_alias(self, media_type_identifier, victim_identifier, true)
116
+ serializer_input_registration.register_alias(self, media_type_identifier, victim_identifier, true, true, wildcards: false)
117
117
  end
118
118
 
119
- def serialize(victim, media_type_identifier, context, dsl: nil, raw: nil)
119
+ def serialize(victim, media_type_identifier, context:, dsl: nil, raw: nil)
120
120
  dsl ||= SerializationDSL.new(self, context: context)
121
121
  serializer_output_registration.call(victim, media_type_identifier.to_s, context, dsl: dsl, raw: raw)
122
122
  end
123
123
 
124
- def deserialize(victim, media_type_identifier, context)
124
+ def deserialize(victim, media_type_identifier, context:)
125
125
  serializer_input_registration.call(victim, media_type_identifier, context)
126
126
  end
127
127
 
@@ -22,6 +22,7 @@ class FakeValidator
22
22
 
23
23
  def override_suffix(suffix)
24
24
  suffixes[[internal_view, internal_version]] = suffix
25
+ FakeValidator.new(prefix, internal_view, version, suffixes)
25
26
  end
26
27
 
27
28
  def identifier
@@ -56,7 +56,7 @@ module MediaTypes
56
56
  array.each do |e|
57
57
  child_links = []
58
58
  context = SerializationDSL.new(__getobj__, child_links, context: @serialization_context)
59
- serializer.serialize(e, identifier, @serialization_context, dsl: context)
59
+ serializer.serialize(e, identifier, context: @serialization_context, dsl: context)
60
60
 
61
61
  self_links = child_links.select { |l| l[:rel] == :self }
62
62
  raise NoSelfLinkProvidedError, identifier unless self_links.any?
@@ -79,7 +79,7 @@ module MediaTypes
79
79
 
80
80
  array.each do |e|
81
81
  context = SerializationDSL.new(__getobj__, [], @serialization_vary, context: @serialization_context)
82
- result = serializer.serialize(e, identifier, @serialization_context, dsl: context, raw: true)
82
+ result = serializer.serialize(e, identifier, context: @serialization_context, dsl: context, raw: true)
83
83
 
84
84
  result = block.call(result) unless block.nil?
85
85
 
@@ -105,7 +105,7 @@ module MediaTypes
105
105
  def emit
106
106
  serialization_dsl_result
107
107
  end
108
-
108
+
109
109
  def object(&block)
110
110
  context = SerializationDSL.new(__getobj__, @serialization_links, @serialization_vary, context: @serialization_context)
111
111
  context.instance_exec(&block)
@@ -1,5 +1,5 @@
1
1
  module MediaTypes
2
2
  module Serialization
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.3.2'.freeze
4
4
  end
5
5
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.metadata['homepage_uri'] = spec.homepage
22
22
  spec.metadata['source_code_uri'] = spec.homepage
23
- spec.metadata['changelog_uri'] = spec.homepage + '/CHANGELOG.md'
23
+ spec.metadata['changelog_uri'] = spec.homepage + '/blob/master/CHANGELOG.md'
24
24
  else
25
25
  raise 'RubyGems 2.0 or newer is required to protect against ' \
26
26
  'public gem pushes.'
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.1.0
4
+ version: 1.3.2
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-06-29 00:00:00.000000000 Z
12
+ date: 2021-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -197,7 +197,7 @@ licenses:
197
197
  metadata:
198
198
  homepage_uri: https://github.com/XPBytes/media_types-serialization
199
199
  source_code_uri: https://github.com/XPBytes/media_types-serialization
200
- changelog_uri: https://github.com/XPBytes/media_types-serialization/CHANGELOG.md
200
+ changelog_uri: https://github.com/XPBytes/media_types-serialization/blob/master/CHANGELOG.md
201
201
  post_install_message:
202
202
  rdoc_options: []
203
203
  require_paths: