userializer 0.3.2 → 0.3.4

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: 39db10c77bd519fffda4b6e6c7e613bc1105a951ab39e677dd8d1aaa0aa6f6b0
4
- data.tar.gz: 5327aa7eb5e03f5abe504e4dde6d4e619df810af3802e896e28a72e9edc5c21f
3
+ metadata.gz: 6aa1e23fadfa753380b8295f2438939b47b691be108b8f9e8307d43bce6066ad
4
+ data.tar.gz: 53641e65a503ca7145e9d1dd7bd98483589668696c11d098f3061b9d018f07ed
5
5
  SHA512:
6
- metadata.gz: 1fcc67f9270e9c8359dc4488eaf11684fcb952f563a64d41f90cae3d83c1ff31a5c271c2247bc538fa3b5877241d3a7f769a32100c9e04ed9cb327caa15fa92f
7
- data.tar.gz: 982d8a1495d2c3a6eb83b498b79a6e9d40910f05226b3e4d14a0d5ab1100d04c4145c1d7e14ccd083f5329cf380089300e131848b7d9d2e6692f498793057b91
6
+ metadata.gz: fa343936b8c54a8c293d2e4952f84b92629b4ed99d2bd32c2559a66718b1592c7d7c1a20b53474e684691bd31a1214c631853422ea42a809b988c239d431268d
7
+ data.tar.gz: 5f47fbf1ec13d6a3155741d73d2b007c3572ce47279386e946b07cca723b0643e37f0ad7daf3c4efd151b2e1aa1ba318b5f4f25e4168f66d51f08f0763c842d4
@@ -14,7 +14,7 @@ module USerializer
14
14
 
15
15
  raise HeterogeneousArray if clss.count > 1
16
16
 
17
- @root_key = opts[:root]
17
+ @root_key = opts[:root]&.to_sym
18
18
  @root_key ||= ActiveSupport::Inflector.pluralize(
19
19
  ActiveSupport::Inflector.underscore(obj_class.name).split('/').last
20
20
  ).to_sym if obj_class
@@ -7,13 +7,18 @@ module USerializer
7
7
  @opts = opts
8
8
  @block = block
9
9
 
10
+ @skip_nil = opts[:skip_nil] || false
10
11
  @conditional_block = opts[:if] || proc { true }
11
12
  end
12
13
 
13
14
  def merge_attributes(res, ser, opts)
14
15
  return unless @conditional_block.call(ser.object, opts)
15
16
 
16
- res[@key] = @block ? @block.call(ser.object, opts) : ser.send(@key)
17
+ value = @block ? @block.call(ser.object, opts) : ser.send(@key)
18
+
19
+ return if value.nil? && @skip_nil
20
+
21
+ res[@key] = value
17
22
  end
18
23
  end
19
24
  end
@@ -1,3 +1,3 @@
1
1
  module USerializer
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: userializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Montagne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-25 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.1.2
127
+ rubygems_version: 3.2.32
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Write a short summary, because RubyGems requires one.