media_types-deserialization 0.1.2 → 0.1.3

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: 1bbd23e88f2aede4504ab00dc8bbbdf38dcd23bf0ac7eeaa27703a08e467918a
4
- data.tar.gz: 37cce138d77c59e7c42b7928eab60a6837ef3e93cb31cea00374e4e47e992fcd
3
+ metadata.gz: 1f2274208d8846656d2f16154499f830786861ef11dd21d95975b80c9c618bb0
4
+ data.tar.gz: 96b8453e48c461806a34ba49c9506ce3d795ba18930fa9f293d5a63210a37535
5
5
  SHA512:
6
- metadata.gz: 5d732f74c55fe45c860686f857218e240181e5055765d4abf0da4347213ecc00296b8a7d3a51667f21c97c15f191a9272ba7303d709f97fed7b3e218f4bfe1f4
7
- data.tar.gz: ffae9954054d4c84cdb8303e7d392f7ea12ad6659cc5c28eabba73b2681b1c4c337d604327ff7703d593cc51ba2ee9b3eb8cf56124b8596513486c33adfe4c54
6
+ metadata.gz: 5f70378c22073f069d8c5ac9962be084839a00b25fdcf9744a285906d351932070952f67ae6743e8d143fe78585b966be9ad7ff19e646f58fd48882bb9e7f72f
7
+ data.tar.gz: '058b525043b542068ef473a76dbcd376e61d8d6880f98781cfff4f1c69f5c316c4fa7a59da35eee368462625ec0d2d4720cc5e8c0255efbf072928284d17a4cb'
@@ -26,9 +26,9 @@
26
26
  <content url="file://$MODULE_DIR$" />
27
27
  <orderEntry type="jdk" jdkName="ruby-2.5.3-p105" jdkType="RUBY_SDK" />
28
28
  <orderEntry type="sourceFolder" forTests="false" />
29
- <orderEntry type="library" scope="PROVIDED" name="actionpack (v5.2.2.1, ruby-2.5.3-p105) [gem]" level="application" />
30
- <orderEntry type="library" scope="PROVIDED" name="actionview (v5.2.2.1, ruby-2.5.3-p105) [gem]" level="application" />
31
- <orderEntry type="library" scope="PROVIDED" name="activesupport (v5.2.2.1, ruby-2.5.3-p105) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="actionpack (v5.2.3, ruby-2.5.3-p105) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="actionview (v5.2.3, ruby-2.5.3-p105) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v5.2.3, ruby-2.5.3-p105) [gem]" level="application" />
32
32
  <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.3, ruby-2.5.3-p105) [gem]" level="application" />
33
33
  <orderEntry type="library" scope="PROVIDED" name="bundler (v2.0.1, ruby-2.5.3-p105) [gem]" level="application" />
34
34
  <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.5, ruby-2.5.3-p105) [gem]" level="application" />
@@ -41,8 +41,8 @@
41
41
  <orderEntry type="library" scope="PROVIDED" name="media_types (v0.6.1, ruby-2.5.3-p105) [gem]" level="application" />
42
42
  <orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.4.0, ruby-2.5.3-p105) [gem]" level="application" />
43
43
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.11.3, ruby-2.5.3-p105) [gem]" level="application" />
44
- <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.10.1, ruby-2.5.3-p105) [gem]" level="application" />
45
- <orderEntry type="library" scope="PROVIDED" name="oj (v3.7.10, ruby-2.5.3-p105) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.10.3, ruby-2.5.3-p105) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="oj (v3.7.12, ruby-2.5.3-p105) [gem]" level="application" />
46
46
  <orderEntry type="library" scope="PROVIDED" name="rack (v2.0.6, ruby-2.5.3-p105) [gem]" level="application" />
47
47
  <orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, ruby-2.5.3-p105) [gem]" level="application" />
48
48
  <orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, ruby-2.5.3-p105) [gem]" level="application" />
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3
4
+
5
+ - 🚨 Update nokogiri: 1.10.2 → 1.10.3 (patch)
6
+ - Update oj: 3.7.10 → 3.7.12 (patch)
7
+ - Update all of rails: 5.2.2.1 → 5.2.3 (minor)
8
+ - Fix [`README.md`](./README.md) `require` statement
9
+
3
10
  ## 0.1.2
4
11
 
5
12
  - Fix `ContentTypeNotRecognised` backtrace
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types-deserialization (0.1.2)
4
+ media_types-deserialization (0.1.3)
5
5
  activesupport (>= 4.0.0)
6
6
  http_headers-content_type (>= 0.1.1, < 1.0.0)
7
7
  media_types (>= 0.6.0)
@@ -9,20 +9,20 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (5.2.2.1)
13
- actionview (= 5.2.2.1)
14
- activesupport (= 5.2.2.1)
12
+ actionpack (5.2.3)
13
+ actionview (= 5.2.3)
14
+ activesupport (= 5.2.3)
15
15
  rack (~> 2.0)
16
16
  rack-test (>= 0.6.3)
17
17
  rails-dom-testing (~> 2.0)
18
18
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
- actionview (5.2.2.1)
20
- activesupport (= 5.2.2.1)
19
+ actionview (5.2.3)
20
+ activesupport (= 5.2.3)
21
21
  builder (~> 3.1)
22
22
  erubi (~> 1.4)
23
23
  rails-dom-testing (~> 2.0)
24
24
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
- activesupport (5.2.2.1)
25
+ activesupport (5.2.3)
26
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
27
27
  i18n (>= 0.7, < 2)
28
28
  minitest (~> 5.1)
@@ -42,11 +42,11 @@ GEM
42
42
  media_types (0.6.1)
43
43
  mini_portile2 (2.4.0)
44
44
  minitest (5.11.3)
45
- nokogiri (1.10.1)
45
+ nokogiri (1.10.3)
46
46
  mini_portile2 (~> 2.4.0)
47
- nokogiri (1.10.1-x64-mingw32)
47
+ nokogiri (1.10.3-x64-mingw32)
48
48
  mini_portile2 (~> 2.4.0)
49
- oj (3.7.10)
49
+ oj (3.7.12)
50
50
  rack (2.0.6)
51
51
  rack-test (1.1.0)
52
52
  rack (>= 1.0, < 3)
data/README.md CHANGED
@@ -1,156 +1,156 @@
1
- # MediaTypes::Deserialization
2
-
3
- [![Build Status: master](https://travis-ci.com/XPBytes/media_types-deserialization.svg)](https://travis-ci.com/XPBytes/media_types-deserialization)
4
- [![Gem Version](https://badge.fury.io/rb/media_types-deserialization.svg)](https://badge.fury.io/rb/media_types-deserialization)
5
- [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
6
-
7
- Add media types supported deserialization using your favourite deserializer, and (when supported and provided) media
8
- type validation.
9
-
10
- ## Installation
11
-
12
- Add this line to your application's Gemfile:
13
-
14
- ```ruby
15
- gem 'media_types-deserialization'
16
- ```
17
-
18
- And then execute:
19
-
20
- $ bundle
21
-
22
- Or install it yourself as:
23
-
24
- $ gem install media_types-deserialization
25
-
26
- ## Usage
27
-
28
- All logic lives in the `MediaTypes::Deserialization` and the main method you'll use is `media_type_params`. This works
29
- very similarly as `params` in `Rack` (and therefore `Rails`) applications, but only gives back what the implicit or
30
- explicit deserializer gives back.
31
-
32
- ```ruby
33
- require 'media_type/deserialization'
34
-
35
- class BaseController
36
- include MediaTypes::Deserialization
37
-
38
- rescue_from ContentFormatError, with: :bad_request # 400
39
- rescue_from ContentTypeNotRecognised, with: :unsupported_media_type # 415
40
- rescue_from ContentDoesNotMatchContentType, with: :unprocessable_entity # 422
41
- end
42
- ```
43
-
44
- ### Content Type lookup (symbol)
45
-
46
- If you _don't_ provide the `lookup_content_type_symbol` configuration, it requires `'action_dispatch/http/mime_type'` to
47
- be present in order to look-up the content type symbol. This is true for `Rails` applications by default.
48
-
49
- ```ruby
50
- MediaTypes::Deserialization.configure do
51
- self.lookup_content_type_symbol = lambda do |content_type|
52
- # For example use a lookup map
53
- KNOWN_CONTENT_TYPES_TO_SYMBOL[content_type]
54
-
55
- # Or alternatively use matching
56
- content_type.include?('json') ? :json : nil
57
- end
58
- end
59
- ```
60
-
61
- See below if you're using the `media_types` gem.
62
-
63
- ### Deserializer lookup
64
-
65
- If you _don't_ provide the `lookup_deserializer_by_symbol` configuration, it currently can only deserialize `json` and
66
- will only do so if the symbol is `:json`, requiring `oj`. If you don't want this behaviour, define it.
67
-
68
- ```ruby
69
- MediaTypes::Deserialization.configure do
70
- self.lookup_deserializer_by_symbol = lambda do |symbol|
71
- case symbol
72
- when :json
73
- return CustomJsonDeserializer
74
- when :xml
75
- when :html
76
- when :xhtml
77
- return CustomXmlDeserializer
78
- else
79
- nil
80
- end
81
- end
82
- end
83
- ```
84
-
85
- ### Media Type lookup and validation
86
-
87
- If you *want* media type validation, for example via the `media_types` gem, provide the `lookup_media_type_by_symbol`
88
- option and return the media types. The easiest way to accomplish this is tracking your registerables when you register
89
- the media types, and creating a Lookup Map like so:
90
-
91
- ```ruby
92
- # In some initializer that defines the media types,
93
- # given a module MyDomain::MediaTypes which holds many media types
94
-
95
- require 'my_domain/media_types'
96
- require 'media_types/integrations/actionpack'
97
-
98
- registerables = []
99
- MyDomain::MediaTypes.module_exec do
100
- registerables.concat self::Author.register
101
- registerables.concat self::Book.register
102
- registerables.concat self::Configuration.register
103
- registerables.concat self::Errors.register
104
- registerables.concat self::Signature.register
105
-
106
- # Create lookup table by string (content-type) => media type
107
- lookup = registerables.flatten.each_with_object({}) do |registerable, hash|
108
- [registerable.media_type, *registerable.aliases].each do |type|
109
- hash[String(type)] = registerable
110
- end
111
- end.freeze
112
-
113
- # Create lookup table by symbol => media_type
114
- lookup_by_symbol = registerables.flatten.each_with_object({}) do |registerable, hash|
115
- hash[String(registerable.symbol).to_sym] = registerable
116
- end.freeze
117
-
118
- const_set(:LOOKUP, lookup)
119
- const_set(:LOOKUP_BY_SYMBOL, lookup_by_symbol)
120
- end
121
- ```
122
-
123
- At this point you can re-use those lookup tables for both the media type lookup and the symbol lookup:
124
-
125
- ```ruby
126
- MediaTypes::Deserialization.configure do
127
- self.lookup_content_type_symbol = lambda do |content_type|
128
- registerable = MyDomain::MediaTypes.const_get(:Lookup).fetch(content_type) { nil }
129
- registerable&.symbol
130
- end
131
-
132
- self.lookup_media_type_by_symbol = lambda do |symbol|
133
- registerable = MyDomain::MediaTypes.const_get(:LOOKUP_BY_SYMBOL).fetch(symbol) { nil }
134
- registerable&.media_type
135
- end
136
- end
137
- ```
138
-
139
- ### Related
140
-
141
- - [`MediaTypes`](https://github.com/SleeplessByte/media-types-ruby): :gem: Library to create media type definitions, schemes and validations
142
- - [`MediaTypes::Serialization`](https://github.com/XPBytes/media_types-serialization): :cyclone: Add media types supported serialization using your favourite serializer
143
- - [`MediaTypes::Validation`](https://github.com/XPBytes/media_types-validation): :heavy_exclamation_mark: Response validations according to a media-type
144
-
145
- ## Development
146
-
147
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
148
- also run `bin/console` for an interactive prompt that will allow you to experiment.
149
-
150
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
151
- version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
152
- push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
153
-
154
- ## Contributing
155
-
156
- Bug reports and pull requests are welcome on GitHub at [XPBytes/media_types-deserialization](https://github.com/XPBytes/media_types-deserialization).
1
+ # MediaTypes::Deserialization
2
+
3
+ [![Build Status: master](https://travis-ci.com/XPBytes/media_types-deserialization.svg)](https://travis-ci.com/XPBytes/media_types-deserialization)
4
+ [![Gem Version](https://badge.fury.io/rb/media_types-deserialization.svg)](https://badge.fury.io/rb/media_types-deserialization)
5
+ [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
6
+
7
+ Add media types supported deserialization using your favourite deserializer, and (when supported and provided) media
8
+ type validation.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'media_types-deserialization'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install media_types-deserialization
25
+
26
+ ## Usage
27
+
28
+ All logic lives in the `MediaTypes::Deserialization` and the main method you'll use is `media_type_params`. This works
29
+ very similarly as `params` in `Rack` (and therefore `Rails`) applications, but only gives back what the implicit or
30
+ explicit deserializer gives back.
31
+
32
+ ```ruby
33
+ require 'media_types/deserialization'
34
+
35
+ class BaseController
36
+ include MediaTypes::Deserialization
37
+
38
+ rescue_from ContentFormatError, with: :bad_request # 400
39
+ rescue_from ContentTypeNotRecognised, with: :unsupported_media_type # 415
40
+ rescue_from ContentDoesNotMatchContentType, with: :unprocessable_entity # 422
41
+ end
42
+ ```
43
+
44
+ ### Content Type lookup (symbol)
45
+
46
+ If you _don't_ provide the `lookup_content_type_symbol` configuration, it requires `'action_dispatch/http/mime_type'` to
47
+ be present in order to look-up the content type symbol. This is true for `Rails` applications by default.
48
+
49
+ ```ruby
50
+ MediaTypes::Deserialization.configure do
51
+ self.lookup_content_type_symbol = lambda do |content_type|
52
+ # For example use a lookup map
53
+ KNOWN_CONTENT_TYPES_TO_SYMBOL[content_type]
54
+
55
+ # Or alternatively use matching
56
+ content_type.include?('json') ? :json : nil
57
+ end
58
+ end
59
+ ```
60
+
61
+ See below if you're using the `media_types` gem.
62
+
63
+ ### Deserializer lookup
64
+
65
+ If you _don't_ provide the `lookup_deserializer_by_symbol` configuration, it currently can only deserialize `json` and
66
+ will only do so if the symbol is `:json`, requiring `oj`. If you don't want this behaviour, define it.
67
+
68
+ ```ruby
69
+ MediaTypes::Deserialization.configure do
70
+ self.lookup_deserializer_by_symbol = lambda do |symbol|
71
+ case symbol
72
+ when :json
73
+ return CustomJsonDeserializer
74
+ when :xml
75
+ when :html
76
+ when :xhtml
77
+ return CustomXmlDeserializer
78
+ else
79
+ nil
80
+ end
81
+ end
82
+ end
83
+ ```
84
+
85
+ ### Media Type lookup and validation
86
+
87
+ If you *want* media type validation, for example via the `media_types` gem, provide the `lookup_media_type_by_symbol`
88
+ option and return the media types. The easiest way to accomplish this is tracking your registerables when you register
89
+ the media types, and creating a Lookup Map like so:
90
+
91
+ ```ruby
92
+ # In some initializer that defines the media types,
93
+ # given a module MyDomain::MediaTypes which holds many media types
94
+
95
+ require 'my_domain/media_types'
96
+ require 'media_types/integrations/actionpack'
97
+
98
+ registerables = []
99
+ MyDomain::MediaTypes.module_exec do
100
+ registerables.concat self::Author.register
101
+ registerables.concat self::Book.register
102
+ registerables.concat self::Configuration.register
103
+ registerables.concat self::Errors.register
104
+ registerables.concat self::Signature.register
105
+
106
+ # Create lookup table by string (content-type) => media type
107
+ lookup = registerables.flatten.each_with_object({}) do |registerable, hash|
108
+ [registerable.media_type, *registerable.aliases].each do |type|
109
+ hash[String(type)] = registerable
110
+ end
111
+ end.freeze
112
+
113
+ # Create lookup table by symbol => media_type
114
+ lookup_by_symbol = registerables.flatten.each_with_object({}) do |registerable, hash|
115
+ hash[String(registerable.symbol).to_sym] = registerable
116
+ end.freeze
117
+
118
+ const_set(:LOOKUP, lookup)
119
+ const_set(:LOOKUP_BY_SYMBOL, lookup_by_symbol)
120
+ end
121
+ ```
122
+
123
+ At this point you can re-use those lookup tables for both the media type lookup and the symbol lookup:
124
+
125
+ ```ruby
126
+ MediaTypes::Deserialization.configure do
127
+ self.lookup_content_type_symbol = lambda do |content_type|
128
+ registerable = MyDomain::MediaTypes.const_get(:Lookup).fetch(content_type) { nil }
129
+ registerable&.symbol
130
+ end
131
+
132
+ self.lookup_media_type_by_symbol = lambda do |symbol|
133
+ registerable = MyDomain::MediaTypes.const_get(:LOOKUP_BY_SYMBOL).fetch(symbol) { nil }
134
+ registerable&.media_type
135
+ end
136
+ end
137
+ ```
138
+
139
+ ### Related
140
+
141
+ - [`MediaTypes`](https://github.com/SleeplessByte/media-types-ruby): :gem: Library to create media type definitions, schemes and validations
142
+ - [`MediaTypes::Serialization`](https://github.com/XPBytes/media_types-serialization): :cyclone: Add media types supported serialization using your favourite serializer
143
+ - [`MediaTypes::Validation`](https://github.com/XPBytes/media_types-validation): :heavy_exclamation_mark: Response validations according to a media-type
144
+
145
+ ## Development
146
+
147
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
148
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
149
+
150
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
151
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
152
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
153
+
154
+ ## Contributing
155
+
156
+ Bug reports and pull requests are welcome on GitHub at [XPBytes/media_types-deserialization](https://github.com/XPBytes/media_types-deserialization).
@@ -1,5 +1,5 @@
1
1
  module MediaTypes
2
2
  module Deserialization
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: media_types-deserialization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-25 00:00:00.000000000 Z
11
+ date: 2019-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -182,8 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  requirements: []
185
- rubyforge_project:
186
- rubygems_version: 2.7.6
185
+ rubygems_version: 3.0.3
187
186
  signing_key:
188
187
  specification_version: 4
189
188
  summary: Add media types supported deserialization using your favourite parser