media_types 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/debian.yml +43 -43
  3. data/.github/workflows/publish-bookworm.yml +34 -33
  4. data/.github/workflows/publish-sid.yml +34 -33
  5. data/.github/workflows/ruby.yml +22 -22
  6. data/.gitignore +20 -20
  7. data/.rubocop.yml +29 -29
  8. data/CHANGELOG.md +183 -175
  9. data/Gemfile +6 -6
  10. data/Gemfile.lock +43 -43
  11. data/LICENSE +21 -21
  12. data/README.md +666 -666
  13. data/Rakefile +12 -12
  14. data/bin/console +15 -15
  15. data/bin/setup +8 -8
  16. data/lib/media_types/constructable.rb +161 -161
  17. data/lib/media_types/dsl/errors.rb +18 -18
  18. data/lib/media_types/dsl.rb +172 -172
  19. data/lib/media_types/errors.rb +25 -25
  20. data/lib/media_types/formatter.rb +56 -56
  21. data/lib/media_types/hash.rb +21 -21
  22. data/lib/media_types/object.rb +35 -35
  23. data/lib/media_types/scheme/allow_nil.rb +30 -30
  24. data/lib/media_types/scheme/any_of.rb +41 -41
  25. data/lib/media_types/scheme/attribute.rb +46 -46
  26. data/lib/media_types/scheme/enumeration_context.rb +18 -18
  27. data/lib/media_types/scheme/enumeration_of_type.rb +80 -80
  28. data/lib/media_types/scheme/errors.rb +87 -87
  29. data/lib/media_types/scheme/links.rb +54 -54
  30. data/lib/media_types/scheme/missing_validation.rb +41 -41
  31. data/lib/media_types/scheme/not_strict.rb +15 -15
  32. data/lib/media_types/scheme/output_empty_guard.rb +45 -45
  33. data/lib/media_types/scheme/output_iterator_with_predicate.rb +66 -66
  34. data/lib/media_types/scheme/output_type_guard.rb +39 -39
  35. data/lib/media_types/scheme/rules.rb +186 -186
  36. data/lib/media_types/scheme/rules_exhausted_guard.rb +75 -73
  37. data/lib/media_types/scheme/validation_options.rb +44 -44
  38. data/lib/media_types/scheme.rb +535 -535
  39. data/lib/media_types/testing/assertions.rb +20 -20
  40. data/lib/media_types/validations.rb +118 -118
  41. data/lib/media_types/version.rb +5 -5
  42. data/lib/media_types/views.rb +12 -12
  43. data/lib/media_types.rb +73 -73
  44. data/media_types.gemspec +33 -33
  45. metadata +6 -6
data/CHANGELOG.md CHANGED
@@ -1,175 +1,183 @@
1
- # Changelog
2
-
3
- ## 2.3.0
4
-
5
- - Add ability to define multiple versions using one block.
6
- - Add `index` attribute type that automatically generates a link list compatible with media_types-serialization.
7
- - Add support for `collection` to automatically look up a previously defined schema when passing a view.
8
- - Add ability to mark certain attributes as optional when validating with `loose: true` and required otherwise.
9
-
10
- ## 2.2.0
11
-
12
- - Change dependencies and build output to be debian compatible
13
-
14
- ## 2.1.1
15
-
16
- - Fix Ruby 2.6 to 2.7 incompatible change
17
-
18
- ## 2.1.0
19
-
20
- - Add `override_suffix` to force a specific suffix
21
- - Fix all deprecation warnings
22
-
23
- ## 2.0.1
24
-
25
- - Views can now be accessed indifferently.
26
- - Attribute keys no longer match indifferently.
27
- - Fixed infinite loop when validating non-hash, non-array items.
28
-
29
- ## 2.0.0
30
-
31
- - Remove ability to set default suffix. All suffixes now default to `+json`.
32
- - Suffixes are now set for a given view and version instead of as a block.
33
- - Add `suffix :yoursuffix` command to override the default `:json` suffix.
34
- - Remove defaults block.
35
- - Remove registrations block.
36
-
37
- ## 1.0.0
38
-
39
- - Add the ability to do inline tests when defining validations using `assert_pass '<json>'` and `assert_fail '<json>'`.
40
- - `media_type` has been replaced with `use_name`.
41
- - It is no longer possible to set a default version. Please use `version <x> do` instead.
42
- - You no longer need to specify a custom format string. If you set an organisation with `def self.organisation` or set a module wide organisation with `MediaTypes::set_organisation <module>, '<organisation>'` the library will generate identifiers for you.
43
- - `self.base_format` has been replaced by `identifier_format do |type:, view:, version:, suffix:|`.
44
- - Add the `empty` validation to mark an empty object as valid.
45
- - Add the `identifier` function to get the [Media Type Identifier](https://en.wikipedia.org/wiki/Media_type) for the validator.
46
- - Add `version(x)` and `view(x)` functions.
47
- - Add an `available_validations` functions that returns all defined validations.
48
- - Fix an issue where validations could accidentally merge if defined with a bad `base_format`.
49
- - Fix an issue where undefined validations would accept an empty object.
50
-
51
- ## 0.6.2
52
-
53
- - Fix handling empty collections
54
-
55
- ## 0.6.1
56
-
57
- - Fix no `validations` error on `validatable?` (now returns `false`)
58
- - Update `bundler` to `2.x`
59
-
60
- ## 0.6.0
61
-
62
- - Change default expected type for `attribute` to Object
63
- - Remove default `actionpack` calls for `.register`
64
- - Add integration for registering with `actionpack` (rails)
65
- - Add integration for registering with `http` (http.rb)
66
- - Fix stack overflow for cyclic schema
67
-
68
- ## 0.5.5
69
-
70
- - Fix an issue with `attribute(optional:, &block)` not passing `optional:` to the created `collection`.
71
-
72
- ## 0.5.4
73
-
74
- - Fix formatter reworked template when fields are not present
75
-
76
- ## 0.5.3
77
-
78
- - Remove `require 'awesome_print'` in library code as it's marked as a development dependency onlvy
79
-
80
- ## 0.5.2
81
-
82
- - Add requires in files with missing requires
83
-
84
- ## 0.5.1
85
-
86
- - Fix merging optional attributes
87
- - Change `#inspect` to look like a tree
88
-
89
- ## 0.5.0
90
-
91
- - Change internal representation of key to symbol
92
- - Change default type from `nil` to `Object`, removing special behaviour for nil
93
- - Add `Rules` class to handle normalization of keys and handling `rules` (`Scheme`, `Attribute`, etc)
94
- - Add guard classes to handle guard behaviour (`OutputEmptyGuard`, `OutputTypeGuard` and `RulesExhaustedGuard`)
95
- - Add `optional:` keywords to most dsl (`attribute`, `collection`, `any`, `link`)
96
- - Add `Formatter` class to handle formatting of the `Constructable#to_s`
97
- - Add behaviour to strip leading dot (`.`) or plus (`+`) from `+%<var>` if `var` is nil, fixing weird media types
98
- - Add behaviour to remove format variable values if format variable is not present, fixing warnings
99
- - Add `inspect` for most public classes
100
- - Add second argument for type or scheme to `any` dsl, mimicking `collection`
101
- - Add tests for most dsl, common permutations
102
- - Rename `force` to `expected_type`
103
- - Remove `format_view` behaviour where it adds a dot (`.`) if a view is present
104
- - Remove special iteration behaviour for `Links` (`link` dsl), allowing them to be optional, or non-exhaustive
105
- - Raise error if `self.base_format` is not available at time of `Dsl.media_type` call
106
- - Fix `expected_type` guard for arrays, nil, or arrays with nil.
107
-
108
- ## 0.4.1
109
-
110
- - Use strings for `:_links`, matching the other validation keys
111
-
112
- ## 0.4.0
113
-
114
- - Simplify `assert_media_type_format` by dumping views completely
115
- - Add test for `merge`
116
- - Add test for nested blocks in `validations` using `view` and `version` nesting
117
- - Add test for `validatable?`
118
- - Add block passing to `Scheme.new`
119
-
120
- ## 0.3.0
121
-
122
- - Add `merge` dsl to merge two `Scheme`
123
-
124
- ## 0.2.6
125
-
126
- - Change validation to accept both symbolised and stringified input ánd validations
127
-
128
- ## 0.2.5
129
-
130
- - Add automatic require for `media_types/scheme/any_of`
131
-
132
- ## 0.2.4
133
-
134
- - Change messages for `assert_media_types_registered` to be more informative and consistent
135
-
136
- ## 0.2.3
137
-
138
- - Fix an issue with `Hash#compact` which was introduce in 2.4+. Now works with Ruby 2.3
139
-
140
- ## 0.2.2
141
-
142
- - Fix an issue with `Registrar#versions`
143
- - Fix link in the gemspec to Github
144
-
145
- ## 0.2.1
146
-
147
- - Fix an issue with `Constructable#valid?` and `Constructable#validate!`
148
-
149
- ## 0.2.0
150
-
151
- Breaking changes to update public API and usage
152
-
153
- - Remove `Base` class (use `MediaTypes::Dsl` instead)
154
- - Remove a lot of configuration options as they are deemed unneeded
155
- - Remove `active_support` dependency
156
- - Rename `ConstructableMimeType` to `Constructable`
157
- - Moved global scheme types to `Scheme` as subtype
158
- - Add `MediaTypes::Dsl`
159
- - Add `validations` block to capture schemes
160
- - Add `registrations` block to capture register intent
161
- - Add `defaults` block to capture mime type defaults
162
- - Add `MediaTypes.register` class method to call `Mime::Type.register`
163
- - Add `Registerable` capture class
164
- - Add type / base setting for `Constructable`
165
- - Add versioned validations
166
- - Add forced types of `collection`s
167
- - Add `attribute` with block
168
- - Add `EnumerationOfType` for schema typed arrays
169
- - Add `AnyOf` for scheme enum types
170
- - Add non-block calls for `Scheme` dsl
171
- - Add yard documentation to `/docs`
172
-
173
- ## 0.1.0
174
-
175
- :baby: initial release
1
+ # Changelog
2
+
3
+ ## 2.3.2
4
+
5
+ - Fix that causes bailout in nested rule to stop validation altogether
6
+
7
+ ## 2.3.1
8
+
9
+ - Fix build issue that caused debian package to be empty
10
+
11
+ ## 2.3.0
12
+
13
+ - Add ability to define multiple versions using one block.
14
+ - Add `index` attribute type that automatically generates a link list compatible with media_types-serialization.
15
+ - Add support for `collection` to automatically look up a previously defined schema when passing a view.
16
+ - Add ability to mark certain attributes as optional when validating with `loose: true` and required otherwise.
17
+
18
+ ## 2.2.0
19
+
20
+ - Change dependencies and build output to be debian compatible
21
+
22
+ ## 2.1.1
23
+
24
+ - Fix Ruby 2.6 to 2.7 incompatible change
25
+
26
+ ## 2.1.0
27
+
28
+ - Add `override_suffix` to force a specific suffix
29
+ - Fix all deprecation warnings
30
+
31
+ ## 2.0.1
32
+
33
+ - Views can now be accessed indifferently.
34
+ - Attribute keys no longer match indifferently.
35
+ - Fixed infinite loop when validating non-hash, non-array items.
36
+
37
+ ## 2.0.0
38
+
39
+ - Remove ability to set default suffix. All suffixes now default to `+json`.
40
+ - Suffixes are now set for a given view and version instead of as a block.
41
+ - Add `suffix :yoursuffix` command to override the default `:json` suffix.
42
+ - Remove defaults block.
43
+ - Remove registrations block.
44
+
45
+ ## 1.0.0
46
+
47
+ - Add the ability to do inline tests when defining validations using `assert_pass '<json>'` and `assert_fail '<json>'`.
48
+ - `media_type` has been replaced with `use_name`.
49
+ - It is no longer possible to set a default version. Please use `version <x> do` instead.
50
+ - You no longer need to specify a custom format string. If you set an organisation with `def self.organisation` or set a module wide organisation with `MediaTypes::set_organisation <module>, '<organisation>'` the library will generate identifiers for you.
51
+ - `self.base_format` has been replaced by `identifier_format do |type:, view:, version:, suffix:|`.
52
+ - Add the `empty` validation to mark an empty object as valid.
53
+ - Add the `identifier` function to get the [Media Type Identifier](https://en.wikipedia.org/wiki/Media_type) for the validator.
54
+ - Add `version(x)` and `view(x)` functions.
55
+ - Add an `available_validations` functions that returns all defined validations.
56
+ - Fix an issue where validations could accidentally merge if defined with a bad `base_format`.
57
+ - Fix an issue where undefined validations would accept an empty object.
58
+
59
+ ## 0.6.2
60
+
61
+ - Fix handling empty collections
62
+
63
+ ## 0.6.1
64
+
65
+ - Fix no `validations` error on `validatable?` (now returns `false`)
66
+ - Update `bundler` to `2.x`
67
+
68
+ ## 0.6.0
69
+
70
+ - Change default expected type for `attribute` to Object
71
+ - Remove default `actionpack` calls for `.register`
72
+ - Add integration for registering with `actionpack` (rails)
73
+ - Add integration for registering with `http` (http.rb)
74
+ - Fix stack overflow for cyclic schema
75
+
76
+ ## 0.5.5
77
+
78
+ - Fix an issue with `attribute(optional:, &block)` not passing `optional:` to the created `collection`.
79
+
80
+ ## 0.5.4
81
+
82
+ - Fix formatter reworked template when fields are not present
83
+
84
+ ## 0.5.3
85
+
86
+ - Remove `require 'awesome_print'` in library code as it's marked as a development dependency onlvy
87
+
88
+ ## 0.5.2
89
+
90
+ - Add requires in files with missing requires
91
+
92
+ ## 0.5.1
93
+
94
+ - Fix merging optional attributes
95
+ - Change `#inspect` to look like a tree
96
+
97
+ ## 0.5.0
98
+
99
+ - Change internal representation of key to symbol
100
+ - Change default type from `nil` to `Object`, removing special behaviour for nil
101
+ - Add `Rules` class to handle normalization of keys and handling `rules` (`Scheme`, `Attribute`, etc)
102
+ - Add guard classes to handle guard behaviour (`OutputEmptyGuard`, `OutputTypeGuard` and `RulesExhaustedGuard`)
103
+ - Add `optional:` keywords to most dsl (`attribute`, `collection`, `any`, `link`)
104
+ - Add `Formatter` class to handle formatting of the `Constructable#to_s`
105
+ - Add behaviour to strip leading dot (`.`) or plus (`+`) from `+%<var>` if `var` is nil, fixing weird media types
106
+ - Add behaviour to remove format variable values if format variable is not present, fixing warnings
107
+ - Add `inspect` for most public classes
108
+ - Add second argument for type or scheme to `any` dsl, mimicking `collection`
109
+ - Add tests for most dsl, common permutations
110
+ - Rename `force` to `expected_type`
111
+ - Remove `format_view` behaviour where it adds a dot (`.`) if a view is present
112
+ - Remove special iteration behaviour for `Links` (`link` dsl), allowing them to be optional, or non-exhaustive
113
+ - Raise error if `self.base_format` is not available at time of `Dsl.media_type` call
114
+ - Fix `expected_type` guard for arrays, nil, or arrays with nil.
115
+
116
+ ## 0.4.1
117
+
118
+ - Use strings for `:_links`, matching the other validation keys
119
+
120
+ ## 0.4.0
121
+
122
+ - Simplify `assert_media_type_format` by dumping views completely
123
+ - Add test for `merge`
124
+ - Add test for nested blocks in `validations` using `view` and `version` nesting
125
+ - Add test for `validatable?`
126
+ - Add block passing to `Scheme.new`
127
+
128
+ ## 0.3.0
129
+
130
+ - Add `merge` dsl to merge two `Scheme`
131
+
132
+ ## 0.2.6
133
+
134
+ - Change validation to accept both symbolised and stringified input ánd validations
135
+
136
+ ## 0.2.5
137
+
138
+ - Add automatic require for `media_types/scheme/any_of`
139
+
140
+ ## 0.2.4
141
+
142
+ - Change messages for `assert_media_types_registered` to be more informative and consistent
143
+
144
+ ## 0.2.3
145
+
146
+ - Fix an issue with `Hash#compact` which was introduce in 2.4+. Now works with Ruby 2.3
147
+
148
+ ## 0.2.2
149
+
150
+ - Fix an issue with `Registrar#versions`
151
+ - Fix link in the gemspec to Github
152
+
153
+ ## 0.2.1
154
+
155
+ - Fix an issue with `Constructable#valid?` and `Constructable#validate!`
156
+
157
+ ## 0.2.0
158
+
159
+ Breaking changes to update public API and usage
160
+
161
+ - Remove `Base` class (use `MediaTypes::Dsl` instead)
162
+ - Remove a lot of configuration options as they are deemed unneeded
163
+ - Remove `active_support` dependency
164
+ - Rename `ConstructableMimeType` to `Constructable`
165
+ - Moved global scheme types to `Scheme` as subtype
166
+ - Add `MediaTypes::Dsl`
167
+ - Add `validations` block to capture schemes
168
+ - Add `registrations` block to capture register intent
169
+ - Add `defaults` block to capture mime type defaults
170
+ - Add `MediaTypes.register` class method to call `Mime::Type.register`
171
+ - Add `Registerable` capture class
172
+ - Add type / base setting for `Constructable`
173
+ - Add versioned validations
174
+ - Add forced types of `collection`s
175
+ - Add `attribute` with block
176
+ - Add `EnumerationOfType` for schema typed arrays
177
+ - Add `AnyOf` for scheme enum types
178
+ - Add non-block calls for `Scheme` dsl
179
+ - Add yard documentation to `/docs`
180
+
181
+ ## 0.1.0
182
+
183
+ :baby: initial release
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in media_types.gemspec
6
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in media_types.gemspec
6
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,43 +1,43 @@
1
- PATH
2
- remote: .
3
- specs:
4
- media_types (2.1.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ansi (1.5.0)
10
- awesome_print (1.9.2)
11
- builder (3.2.4)
12
- docile (1.4.0)
13
- minitest (5.18.0)
14
- minitest-reporters (1.6.0)
15
- ansi
16
- builder
17
- minitest (>= 5.0)
18
- ruby-progressbar
19
- oj (3.14.2)
20
- rake (13.0.6)
21
- ruby-progressbar (1.13.0)
22
- simplecov (0.22.0)
23
- docile (~> 1.1)
24
- simplecov-html (~> 0.11)
25
- simplecov_json_formatter (~> 0.1)
26
- simplecov-html (0.12.3)
27
- simplecov_json_formatter (0.1.4)
28
-
29
- PLATFORMS
30
- x64-mingw32
31
-
32
- DEPENDENCIES
33
- awesome_print
34
- bundler (>= 2)
35
- media_types!
36
- minitest
37
- minitest-reporters
38
- oj
39
- rake
40
- simplecov
41
-
42
- BUNDLED WITH
43
- 2.1.4
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ media_types (2.3.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ awesome_print (1.9.2)
11
+ builder (3.2.4)
12
+ docile (1.4.0)
13
+ minitest (5.18.0)
14
+ minitest-reporters (1.6.0)
15
+ ansi
16
+ builder
17
+ minitest (>= 5.0)
18
+ ruby-progressbar
19
+ oj (3.14.2)
20
+ rake (13.0.6)
21
+ ruby-progressbar (1.13.0)
22
+ simplecov (0.22.0)
23
+ docile (~> 1.1)
24
+ simplecov-html (~> 0.11)
25
+ simplecov_json_formatter (~> 0.1)
26
+ simplecov-html (0.12.3)
27
+ simplecov_json_formatter (0.1.4)
28
+
29
+ PLATFORMS
30
+ x64-mingw32
31
+
32
+ DEPENDENCIES
33
+ awesome_print
34
+ bundler (>= 2)
35
+ media_types!
36
+ minitest
37
+ minitest-reporters
38
+ oj
39
+ rake
40
+ simplecov
41
+
42
+ BUNDLED WITH
43
+ 2.1.4
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 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 all
13
- 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 THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020 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 all
13
+ 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 THE
21
+ SOFTWARE.