active_record_to_hash 1.2.1 → 1.3.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: 1fa2aa0c803cdaa15448897462fd144eeb3c1465b1010767ff3693e0f8d1b237
4
- data.tar.gz: 657ef30f57cb45c48adb334dac896d341211d8b68ae89f197ee88997282dad34
3
+ metadata.gz: e6fd8387c13ea938de4bd07f3136535a99c11f294e06f895565da55970e916a6
4
+ data.tar.gz: 1ed0ac8096bc6ff084516be1fb130e43a34d7578044a043da73543bf640ada14
5
5
  SHA512:
6
- metadata.gz: d56deb1ac8c203ba63b6f0ad1afcef993f3af4dbe5d28a56dfe9f41825b3af69eb2850c815a986796ef9986d5958c516f3be0799a4097f8f84f32b7d3269ff62
7
- data.tar.gz: 05efcbb527ebb3d8ad2d0aa7ce75e77c94305b99a857c349a2b7927e58f42fc5239afb55ffa43d430648192d03a9f3e202364b6ee0a76dd6fa3df82a05ddad7e
6
+ metadata.gz: df5703d7c50fa512ec6d4294a07a967a81c4faa1fb827fefc3e0cec25c3dca038bd7a2c557353fe00d235e6caa4414d8aa01a394d48f10ff1a19bcf934029e97
7
+ data.tar.gz: fe940a5caee54389c0641b12c3e64057686b6acc7e7232b42c6e16c45cebb6dbe710be35a8d1a184305101f151c7e2e4c2e6ff386d115f683baf278d61af5a62
data/README.md CHANGED
@@ -169,6 +169,10 @@ p shop.to_hash(only: [:id, :name], with_areas: :exists)
169
169
  # {:id=>1, :name=>"Shop No1", :areas=>true}
170
170
  # You can use this option only with ActiveRecord::Relation
171
171
 
172
+
173
+ p shop.to_hash(ignore_nil: true)
174
+ # When the value is nil, it skips that key.
175
+
172
176
  ```
173
177
 
174
178
  ### Configuration
@@ -15,6 +15,7 @@ module ActiveRecordToHash
15
15
  key = k.to_sym
16
16
  next if ActiveRecordToHash.to_a(options[:except]).include?(key)
17
17
  next if options[:only] && !ActiveRecordToHash.to_a(options[:only]).include?(key)
18
+ next if options[:ignore_nil] && v.nil?
18
19
 
19
20
  memo[key] = v
20
21
  end
@@ -24,6 +25,7 @@ module ActiveRecordToHash
24
25
  ActiveRecordToHash.handle_with_options(options) do |hash_key, attr_name, child_options|
25
26
  child = ActiveRecordToHash.retrieve_child_attribute(self, attr_name, child_options, __callee__)
26
27
  next if child_options[:optional] == true && child.blank?
28
+ next if options[:ignore_nil] && child.nil?
27
29
 
28
30
  result[hash_key] = ActiveRecordToHash.handle_alter(child, child_options)
29
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordToHash
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_to_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-29 00:00:00.000000000 Z
11
+ date: 2022-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails