oj_serializers 2.0.3 → 3.0.0

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: f9532d127e357231931f57cda2531743fe4064d0f9e0371cb2aac81a39dedb35
4
- data.tar.gz: 8465a8f1f8e39fb48cd07a6c6156ff744f7e094a2985e01a1a13445957f2b3f0
3
+ metadata.gz: 7a055b7489622b5fcc884399410af78d536d8e03750cecdebe5535e2fd46d3d6
4
+ data.tar.gz: 61a1c9852a57dd3d367f22015018a9397759bb3c3a313f1f8d32ce7093e7eb34
5
5
  SHA512:
6
- metadata.gz: 176c981929972198d8cbaf9548cc9238b60f51010fbd33415a70c25ed8f167885e8cfa494820cc668a03eb9cf96664bb40ba4b2cc69efc4e229763e621aa7190
7
- data.tar.gz: d0d7ea0e5fc50b993b7439e50be0c59f6da26c23ac542c69838b5c145197d598186ae162ce9bc82711942b8e94631acb99acfe4739e04b1e25e28e1f6b70f260
6
+ metadata.gz: '02887512f4deac20d0a3a6d8d14718539db2baa44fffe3ee273a2b2fdf39312c717f1b62ca75006b1fa32dc16ef38a20e59e05725ba33ddb75c0b0cab498b2f8'
7
+ data.tar.gz: c4451e1a5e1f7f4b9d1b1d17696cc2559114946e220103b6e1c0546ab3198483f9e22e85ba3ed78845265ead0fed97a4fb78e2ed663d2ca6b0485efecabf9667
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## Oj Serializers 3.0.0 (2026-01-02)
2
+
3
+ ### Features ✨
4
+
5
+ - [Pass user options to children associations](https://github.com/ElMassimo/oj_serializers/commit/d495f06)
6
+
7
+ ## Oj Serializers 2.1.0 (2026-01-02)
8
+
9
+ ### Fixes 🐞
10
+
11
+ - [Improve sorting by :definition with more than 10 attributes in the list](https://github.com/ElMassimo/oj_serializers/commit/d58cb81) (#25)
12
+
1
13
  ## Oj Serializers 2.0.3 (2023-04-19)
2
14
 
3
15
  ### Features ✨
@@ -18,28 +18,28 @@ class ActiveModel::Serializer
18
18
  # OjSerializer: Used internally to write a single object association in :hash mode.
19
19
  #
20
20
  # Returns nothing.
21
- def self.one_as_hash(object)
21
+ def self.one_as_hash(object, options = nil)
22
22
  new(object)
23
23
  end
24
24
 
25
25
  # OjSerializer: Used internally to write an association in :hash mode.
26
26
  #
27
27
  # Returns nothing.
28
- def self.many_as_hash(array)
28
+ def self.many_as_hash(array, options = nil)
29
29
  array.map { |object| new(object) }
30
30
  end
31
31
 
32
32
  # OjSerializer: Used internally to write a single object association in :json mode.
33
33
  #
34
34
  # Returns nothing.
35
- def self.write_one(writer, object)
35
+ def self.write_one(writer, object, options = nil)
36
36
  writer.push_value(new(object))
37
37
  end
38
38
 
39
39
  # OjSerializer: Used internally to write an association in :json mode.
40
40
  #
41
41
  # Returns nothing.
42
- def self.write_many(writer, array)
42
+ def self.write_many(writer, array, options = nil)
43
43
  writer.push_array
44
44
  array.each do |object|
45
45
  write_one(writer, object)
@@ -25,7 +25,7 @@ module OjSerializers::ControllerSerialization
25
25
  if serializer_class && serializer_class < OjSerializers::Serializer
26
26
  super(OjSerializers::JsonStringEncoder.encode_to_json(resource, **options), options.except(:root, :serializer, :each_serializer))
27
27
  else
28
- super(resource, **options)
28
+ super(resource, options)
29
29
  end
30
30
  end
31
31
  end
@@ -607,17 +607,17 @@ protected
607
607
  <<~WRITE_ONE
608
608
  if __value = #{value}
609
609
  writer.push_key('#{key}')
610
- #{serializer_class}.write_one(writer, __value)
610
+ #{serializer_class}.write_one(writer, __value, options)
611
611
  end
612
612
  WRITE_ONE
613
613
  when :many
614
614
  <<~WRITE_MANY
615
615
  writer.push_key('#{key}')
616
- #{serializer_class}.write_many(writer, #{value})
616
+ #{serializer_class}.write_many(writer, #{value}, options)
617
617
  WRITE_MANY
618
618
  when :flat
619
619
  <<~WRITE_FLAT
620
- #{serializer_class}.write_to_json(writer, #{value})
620
+ #{serializer_class}.write_to_json(writer, #{value}, options)
621
621
  WRITE_FLAT
622
622
  else
623
623
  raise ArgumentError, "Unknown association type: #{type.inspect}"
@@ -666,11 +666,11 @@ protected
666
666
 
667
667
  case type = options.fetch(:association)
668
668
  when :one
669
- "#{key}: (__value = #{value}) ? #{serializer_class}.one_as_hash(__value) : nil"
669
+ "#{key}: (__value = #{value}) ? #{serializer_class}.one_as_hash(__value, options) : nil"
670
670
  when :many
671
- "#{key}: #{serializer_class}.many_as_hash(#{value})"
671
+ "#{key}: #{serializer_class}.many_as_hash(#{value}, options)"
672
672
  when :flat
673
- "**#{serializer_class}.one_as_hash(#{value})"
673
+ "**#{serializer_class}.one_as_hash(#{value}, options)"
674
674
  else
675
675
  raise ArgumentError, "Unknown association type: #{type.inspect}"
676
676
  end
@@ -713,7 +713,13 @@ protected
713
713
  if sort_by == :name
714
714
  sort_by = ->(name, options, _) { options[:identifier] ? "__#{name}" : name }
715
715
  elsif !sort_by || sort_by == :definition
716
- sort_by = ->(name, options, index) { options[:identifier] ? "__#{name}" : "zzz#{index}" }
716
+ sort_by = ->(name, options, index) {
717
+ if options[:identifier]
718
+ 0 - (_attributes.count - index)
719
+ else
720
+ index
721
+ end
722
+ }
717
723
  end
718
724
 
719
725
  attributes.sort_by.with_index { |(name, options), index| sort_by.call(name, options, index) }.to_h
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OjSerializers
4
- VERSION = '2.0.3'
4
+ VERSION = '3.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximo Mussini
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-04-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: oj
@@ -53,7 +52,6 @@ metadata:
53
52
  source_code_uri: https://github.com/ElMassimo/oj_serializers
54
53
  changelog_uri: https://github.com/ElMassimo/oj_serializers/blob/master/CHANGELOG.md
55
54
  rubygems_mfa_required: 'true'
56
- post_install_message:
57
55
  rdoc_options: []
58
56
  require_paths:
59
57
  - lib
@@ -68,8 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
66
  - !ruby/object:Gem::Version
69
67
  version: '0'
70
68
  requirements: []
71
- rubygems_version: 3.2.32
72
- signing_key:
69
+ rubygems_version: 3.6.9
73
70
  specification_version: 4
74
71
  summary: A lighter JSON serializer for Ruby Objects in Rails. Easily migrate away
75
72
  from Active Model Serializers.