oj_serializers 2.0.2 → 2.0.3

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: f1a6edc7a526ccc3e6edd655070c28a9c54f2fd38646aaf36bf4db0b58363f36
4
- data.tar.gz: 5a2541b9005c35d1f4c68a0dc142691b35199c78e0e134f6cc44ad0cd6a3a8bc
3
+ metadata.gz: f9532d127e357231931f57cda2531743fe4064d0f9e0371cb2aac81a39dedb35
4
+ data.tar.gz: 8465a8f1f8e39fb48cd07a6c6156ff744f7e094a2985e01a1a13445957f2b3f0
5
5
  SHA512:
6
- metadata.gz: 4ee1d2c5e850cd14548dbf1219056f61b25be85a55a83107bc6cf695b991cb52bb54605c45c88aed18e3573e53c72f22bbedbfa7a2bd066e10a17d71a1e25bd1
7
- data.tar.gz: f8454069164b46838efecc9652e5a56fa816a07e47e7ad1983be49147c469f2c58bcdb67ab54ebb59bbcdd381abe0ee7ff7240ca282f310e581fc8dc0a275a0f
6
+ metadata.gz: 176c981929972198d8cbaf9548cc9238b60f51010fbd33415a70c25ed8f167885e8cfa494820cc668a03eb9cf96664bb40ba4b2cc69efc4e229763e621aa7190
7
+ data.tar.gz: d0d7ea0e5fc50b993b7439e50be0c59f6da26c23ac542c69838b5c145197d598186ae162ce9bc82711942b8e94631acb99acfe4739e04b1e25e28e1f6b70f260
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## Oj Serializers 2.0.3 (2023-04-19)
2
+
3
+ ### Features ✨
4
+
5
+ - [Allow `key` and `unless` in AMS-compat mode](https://github.com/ElMassimo/oj_serializers/commit/5050710e199651cc2c0e9d9d6395f2c2ac9b1875)
6
+
7
+ ### Fixes 🐞
8
+
9
+ - [Allow using `active_model_serializers` in associations](https://github.com/ElMassimo/oj_serializers/commit/501ed4014b564e6f103d2f52d15832fe6706d6a8)
10
+
1
11
  ## Oj Serializers 2.0.2 (2023-04-02)
2
12
 
3
13
  ### Features ✨
data/README.md CHANGED
@@ -31,6 +31,7 @@ Faster JSON serializers for Ruby, built on top of the powerful [`oj`][oj] librar
31
31
  [Discussion]: https://github.com/ElMassimo/oj_serializers/discussions
32
32
  [TypeScript]: https://www.typescriptlang.org/
33
33
  [types_from_serializers]: https://github.com/ElMassimo/types_from_serializers
34
+ [inheritance]: https://github.com/ElMassimo/types_from_serializers/blob/main/playground/vanilla/app/serializers/song_with_videos_serializer.rb#L1
34
35
 
35
36
  ## Why? 🤔
36
37
 
@@ -400,7 +401,7 @@ As a result, it's posible to easily detect mismatches between the backend and th
400
401
 
401
402
  ### Composing serializers 🧱
402
403
 
403
- There are three options to compose serializers: inheritance, mixins, and `flat_one`.
404
+ There are three options to [compose serializers](https://github.com/ElMassimo/oj_serializers/discussions/10#discussioncomment-5523921): [inheritance], mixins, and `flat_one`.
404
405
 
405
406
  Use `flat_one` to include all attributes from a different serializer:
406
407
 
@@ -416,6 +417,8 @@ class AttachmentSerializer < BaseSerializer
416
417
  end
417
418
  ```
418
419
 
420
+ Think of it as `has_one` without a "root", all the attributes are added directly.
421
+
419
422
  <details>
420
423
  <summary>Example Output</summary>
421
424
 
@@ -14,7 +14,53 @@ class ActiveModel::Serializer
14
14
  def self.many(array, options = nil)
15
15
  array.map { |object| new(object, options) }
16
16
  end
17
+
18
+ # OjSerializer: Used internally to write a single object association in :hash mode.
19
+ #
20
+ # Returns nothing.
21
+ def self.one_as_hash(object)
22
+ new(object)
23
+ end
24
+
25
+ # OjSerializer: Used internally to write an association in :hash mode.
26
+ #
27
+ # Returns nothing.
28
+ def self.many_as_hash(array)
29
+ array.map { |object| new(object) }
30
+ end
31
+
32
+ # OjSerializer: Used internally to write a single object association in :json mode.
33
+ #
34
+ # Returns nothing.
35
+ def self.write_one(writer, object)
36
+ writer.push_value(new(object))
37
+ end
38
+
39
+ # OjSerializer: Used internally to write an association in :json mode.
40
+ #
41
+ # Returns nothing.
42
+ def self.write_many(writer, array)
43
+ writer.push_array
44
+ array.each do |object|
45
+ write_one(writer, object)
46
+ end
47
+ writer.pop
48
+ end
49
+
50
+ module OjOptionsCompat
51
+ def add_attribute(value_from, key: nil, **options)
52
+ options[:as] ||= key if key
53
+
54
+ if (unless_proc = options.delete(:unless))
55
+ options[:if] = -> { !instance_exec(&unless_proc) }
56
+ end
57
+
58
+ super(value_from, **options)
59
+ end
60
+ end
17
61
  end
18
62
 
19
63
  require 'oj_serializers'
20
64
  require 'oj_serializers/sugar'
65
+
66
+ Oj::Serializer.singleton_class.prepend(ActiveModel::Serializer::OjOptionsCompat)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OjSerializers
4
- VERSION = '2.0.2'
4
+ VERSION = '2.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximo Mussini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-02 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.3.7
71
+ rubygems_version: 3.2.32
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: A lighter JSON serializer for Ruby Objects in Rails. Easily migrate away