media_types-serialization 1.3.4 → 1.3.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 737a38bc10cd0c3aff8fa9bc33c3c192098709eb331f7c35706840410ff3d280
4
- data.tar.gz: d6311d9a1b27329e4164cb7bf3b8e839ce96419b05e9a9e42d033d7ba2942a50
3
+ metadata.gz: f668e10a02f800afc30da2c1438f99e4a50fb2b726cc829d490998f2f1997933
4
+ data.tar.gz: f0d711b09c45a03c7cfbac9238ac6f1e6f6f24b701d631f236b1986f19d80ca2
5
5
  SHA512:
6
- metadata.gz: c6fad7b09ecc516290fb5e0393ee5a790c128a75402cdb977c396b6dac01b30748b63f5631b001b7eaa9d9c1b8007e814200d9be7766afa757d1c93785bc34f8
7
- data.tar.gz: ea95bb41414b2125ac3af7efe42ff9c5e521f36a7bae2930760dd52fdee3e58e1175e5aaa8f03d3eb27bf5022d089f0542f4bc51b418cee05ae3724ba3756779
6
+ metadata.gz: 9f6e2dec7c6409279f226dc0c6b3dff609273bd72330f055397c0e2f7be54eab5b032d33192590486f898d9cca3f8cedd69c6c1a519e104a56942a40ae4b2565
7
+ data.tar.gz: bda722326eca550e19cc8ab656896423f092a8b8c14436a37b4e51c88f0c5191b85a3b682dc3ead1c9e38b277e5a233c4741eb6cddeff5af68b89c3ed0a22230
@@ -13,21 +13,20 @@ on:
13
13
 
14
14
  jobs:
15
15
  build:
16
-
17
16
  runs-on: ubuntu-latest
18
17
 
19
18
  strategy:
20
19
  matrix:
21
- ruby-version: [2.7.x, 2.6.x]
20
+ ruby-version: [2.7.x, 2.6.x, 2.5.x]
22
21
 
23
22
  steps:
24
- - uses: actions/checkout@v1
25
- - name: Set up Ruby ${{ matrix.ruby-version }}
26
- uses: actions/setup-ruby@v1
27
- with:
28
- ruby-version: ${{ matrix.ruby-version }}
29
- - name: Build and test with Rake
30
- run: |
31
- gem install bundler
32
- bundle install --jobs 4 --retry 3
33
- bundle exec rake
23
+ - uses: actions/checkout@v1
24
+ - name: Set up Ruby ${{ matrix.ruby-version }}
25
+ uses: actions/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby-version }}
28
+ - name: Build and test with Rake
29
+ run: |
30
+ gem install bundler
31
+ bundle install --jobs 4 --retry 3
32
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.5
4
+
5
+ - 🐛 Upgrade media-types library so Ruby 2.5 and 2.6 work again
6
+
3
7
  ## 1.3.4
4
8
 
5
9
  - Same as `1.3.3`
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types-serialization (1.3.4)
4
+ media_types-serialization (1.3.5)
5
5
  actionpack (>= 4.0.0)
6
6
  activesupport (>= 4.0.0)
7
- media_types (>= 2.1.0, < 3.0.0)
7
+ media_types (>= 2.1.1, < 3.0.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -66,7 +66,7 @@ GEM
66
66
  mail (2.7.1)
67
67
  mini_mime (>= 0.1.1)
68
68
  marcel (1.0.1)
69
- media_types (2.1.0)
69
+ media_types (2.1.1)
70
70
  method_source (1.0.0)
71
71
  mini_mime (1.1.0)
72
72
  minitest (5.14.4)
@@ -75,7 +75,7 @@ GEM
75
75
  racc (~> 1.4)
76
76
  nokogiri (1.12.3-x86_64-linux)
77
77
  racc (~> 1.4)
78
- oj (3.13.1)
78
+ oj (3.13.2)
79
79
  racc (1.5.2)
80
80
  rack (2.2.3)
81
81
  rack-test (1.1.0)
@@ -96,7 +96,7 @@ GEM
96
96
  rails-dom-testing (2.0.3)
97
97
  activesupport (>= 4.2.0)
98
98
  nokogiri (>= 1.6)
99
- rails-html-sanitizer (1.3.0)
99
+ rails-html-sanitizer (1.4.1)
100
100
  loofah (~> 2.3)
101
101
  railties (5.2.6)
102
102
  actionpack (= 5.2.6)
@@ -134,4 +134,4 @@ DEPENDENCIES
134
134
  rake (~> 13.0)
135
135
 
136
136
  BUNDLED WITH
137
- 2.2.7
137
+ 2.2.17
data/README.md CHANGED
@@ -224,7 +224,7 @@ There are convenience methods for serializing arrays of objects based on a templ
224
224
  #### Indexes
225
225
 
226
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.
227
+ The index method automatically generates it based on the `self` links defined in the default view (`view: nil`) of the given version.
228
228
 
229
229
  ```ruby
230
230
  class BookSerializer < MediaTypes::Serialization::Base
@@ -264,6 +264,88 @@ BookSerializer.serialize([book], BookValidator.view(:index).version(3), context:
264
264
  # }
265
265
  ```
266
266
 
267
+ ##### How to validate?
268
+
269
+ The `index` dsl does _not_ exist in the validation gem. This is how you validate indices:
270
+
271
+ ```ruby
272
+ class BookValidator
273
+ include MediaTypes::Dsl
274
+
275
+ def self.organisation
276
+ 'acme'
277
+ end
278
+
279
+ use_name 'book'
280
+
281
+ validations do
282
+ view :index do
283
+ version 3 do
284
+ attribute :books do
285
+ link :self
286
+
287
+ collection :_index, allow_empty: true do
288
+ attribute :href, String
289
+ end
290
+ end
291
+ end
292
+ end
293
+ end
294
+ end
295
+ ```
296
+
297
+ If the `:self` link contains _more attributes_, they will show up here too.
298
+
299
+ ```ruby
300
+ class BookSerializer < MediaTypes::Serialization::Base
301
+ validator BookValidator
302
+
303
+ output versions: [1, 2, 3] do |obj, version, context|
304
+ attribute :book do
305
+ link :self, href: context.book_url(obj), isbn: obj.isbn if version >= 3
306
+
307
+ attribute :title, obj.title
308
+ attribute :description, obj.description if version >= 2
309
+ end
310
+ end
311
+
312
+ output view: :index, version: 3 do |arr, version, context|
313
+ attribute :books do
314
+ link :self, href: context.book_index_url
315
+
316
+ index arr, version: version
317
+ end
318
+ end
319
+ end
320
+ ```
321
+
322
+ ```ruby
323
+ class BookValidator
324
+ include MediaTypes::Dsl
325
+
326
+ def self.organisation
327
+ 'acme'
328
+ end
329
+
330
+ use_name 'book'
331
+
332
+ validations do
333
+ view :index do
334
+ version 3 do
335
+ attribute :books do
336
+ link :self
337
+
338
+ collection :_index, allow_empty: true do
339
+ attribute :href, String
340
+ attribute :isbn, AllowNil(String)
341
+ end
342
+ end
343
+ end
344
+ end
345
+ end
346
+ end
347
+ ```
348
+
267
349
  #### Collections
268
350
 
269
351
  A collection inlines the member objects.
@@ -321,6 +403,37 @@ BookSerializer.serialize([book], BookValidator.view(:collection).version(3), con
321
403
  # }
322
404
  ```
323
405
 
406
+ The `collection` dsl is _not_ the same as the one in the validation gem. This is how you could validate collections:
407
+
408
+ ```ruby
409
+ class BookValidator
410
+ include MediaTypes::Dsl
411
+
412
+ def self.organisation
413
+ 'acme'
414
+ end
415
+
416
+ use_name 'book'
417
+
418
+ validations do
419
+ view :collection do
420
+ version 3 do
421
+ attribute :books do
422
+ link :self
423
+
424
+ collection :_embedded, allow_empty: true do
425
+ link :self
426
+
427
+ attribute :title, String
428
+ attribute :description, AllowNil(String)
429
+ end
430
+ end
431
+ end
432
+ end
433
+ end
434
+ end
435
+ ```
436
+
324
437
  ### Input deserialization
325
438
 
326
439
  You can mark a media type as something that's allowed to be sent along with a PUT request as follows:
@@ -460,6 +573,9 @@ While this is not a good practise as this makes it hard to add new fields or rem
460
573
  class BookSerializer < MediaTypes::Serialization::Base
461
574
  validator BookValidator
462
575
 
576
+ # applicaton/vnd.acme.book.v3+json
577
+ # applicaton/vnd.acme.book.v2+json
578
+ # applicaton/vnd.acme.book.v1+json
463
579
  output versions: [1, 2, 3] do |obj, version, context|
464
580
  attribute :book do
465
581
  link :self, href: context.book_url(obj) if version >= 3
@@ -468,8 +584,18 @@ class BookSerializer < MediaTypes::Serialization::Base
468
584
  attribute :description, obj.description if version >= 2
469
585
  end
470
586
  end
471
- output_alias 'application/json' # maps application/json to to applicaton/vnd.acme.book.v1+json
587
+
588
+ # applicaton/vnd.acme.book+json
589
+ output version: nil do |obj, version, context|
590
+ attribute :book do
591
+ attribute :title, obj.title
592
+ end
593
+ end
594
+ output_alias 'application/json' # maps application/json to to applicaton/vnd.acme.book+json
472
595
 
596
+ # applicaton/vnd.acme.book.v3.create+json
597
+ # applicaton/vnd.acme.book.v2.create+json
598
+ # applicaton/vnd.acme.book.v1.create+json
473
599
  input view: :create, versions: [1, 2, 3] do |json, version, context|
474
600
  book = Book.new
475
601
  book.title = json['book']['title']
@@ -479,10 +605,20 @@ class BookSerializer < MediaTypes::Serialization::Base
479
605
  # Make sure not to save here but only save in the controller
480
606
  book
481
607
  end
482
- input_alias 'application/json', view: :create # maps application/json to to applicaton/vnd.acme.book.v1+json
608
+
609
+ # applicaton/vnd.acme.book.create+json
610
+ input view: :create, version: nil do |json, version, context|
611
+ book = Book.new
612
+ book.title = json['book']['title']
613
+ book.description = 'Not available'
614
+
615
+ # Make sure not to save here but only save in the controller
616
+ book
617
+ end
618
+ input_alias 'application/json', view: :create # maps application/json to to applicaton/vnd.acme.book.create+json
483
619
  ```
484
620
 
485
- Validation will be done using the remapped validator. Aliasses map to version `nil` if that is available or `1` otherwise. It is not possible to configure this version.
621
+ Validation will be done using the remapped validator. Aliasses map to version `nil`. It is not possible to configure this version.
486
622
 
487
623
  ### HTML
488
624
 
@@ -1,5 +1,5 @@
1
1
  module MediaTypes
2
2
  module Serialization
3
- VERSION = '1.3.4'.freeze
3
+ VERSION = '1.3.5'.freeze
4
4
  end
5
5
  end
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
 
38
38
  spec.add_dependency 'actionpack', '>= 4.0.0'
39
39
  spec.add_dependency 'activesupport', '>= 4.0.0'
40
- spec.add_dependency 'media_types', '>= 2.1.0', '< 3.0.0'
40
+ spec.add_dependency 'media_types', '>= 2.1.1', '< 3.0.0'
41
41
 
42
42
  spec.add_development_dependency 'awesome_print'
43
43
  spec.add_development_dependency 'bundler'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: media_types-serialization
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
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-08-12 00:00:00.000000000 Z
12
+ date: 2021-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -45,7 +45,7 @@ dependencies:
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 2.1.0
48
+ version: 2.1.1
49
49
  - - "<"
50
50
  - !ruby/object:Gem::Version
51
51
  version: 3.0.0
@@ -55,7 +55,7 @@ dependencies:
55
55
  requirements:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
- version: 2.1.0
58
+ version: 2.1.1
59
59
  - - "<"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0