active_record_to_hash 1.0.0 → 1.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa2aa0c803cdaa15448897462fd144eeb3c1465b1010767ff3693e0f8d1b237
|
4
|
+
data.tar.gz: 657ef30f57cb45c48adb334dac896d341211d8b68ae89f197ee88997282dad34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d56deb1ac8c203ba63b6f0ad1afcef993f3af4dbe5d28a56dfe9f41825b3af69eb2850c815a986796ef9986d5958c516f3be0799a4097f8f84f32b7d3269ff62
|
7
|
+
data.tar.gz: 05efcbb527ebb3d8ad2d0aa7ce75e77c94305b99a857c349a2b7927e58f42fc5239afb55ffa43d430648192d03a9f3e202364b6ee0a76dd6fa3df82a05ddad7e
|
@@ -23,6 +23,8 @@ module ActiveRecordToHash
|
|
23
23
|
|
24
24
|
ActiveRecordToHash.handle_with_options(options) do |hash_key, attr_name, child_options|
|
25
25
|
child = ActiveRecordToHash.retrieve_child_attribute(self, attr_name, child_options, __callee__)
|
26
|
+
next if child_options[:optional] == true && child.blank?
|
27
|
+
|
26
28
|
result[hash_key] = ActiveRecordToHash.handle_alter(child, child_options)
|
27
29
|
end
|
28
30
|
|
@@ -20,7 +20,11 @@ module ActiveRecordToHash
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def retrieve_child_attribute(record, attr_name, options, callee) # rubocop:disable Metrics/AbcSize
|
23
|
-
|
23
|
+
if options.key?(:value)
|
24
|
+
return options[:value].call(record) if options[:value].is_a? Proc
|
25
|
+
|
26
|
+
return options[:value]
|
27
|
+
end
|
24
28
|
|
25
29
|
args = options[:args] || []
|
26
30
|
value = record.public_send(attr_name, *args)
|
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.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masamoto Miyata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|