forest_admin_datasource_mongoid 1.45.1 → 1.45.2

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: 5bf71405e1b5133a5adc5c52ba242fcd24fd553ff24d8f007e19617de75c6bb8
4
- data.tar.gz: 1900293f2054d88ba1e191ddfa5fbcd92aa0c797cff39d21f98226caeaae224f
3
+ metadata.gz: de923427287155a0df371496903f860e8889430abf7aa1609bd4bf8f17f30b35
4
+ data.tar.gz: be3514f5c733a9593bbd1ebb4c09200f4567ce38a3dba131e7f91578efe6ad82
5
5
  SHA512:
6
- metadata.gz: 96f85626b50cbd6a585ef988d700e66f22a15919723202dba6802bc7870a6960d27da243fc379d0d49caafd8b85093d6c0ac5599b07f93bf566ae731c0116d6d
7
- data.tar.gz: bbb7fb6e6b4615502ff24112e3e566a9f5690bfb9ea60884889c328a34bc991e46a216d06184ab3a696eef42be2a216855a9f5c714c5d5f3b5e9fbd57ea4a1db
6
+ metadata.gz: 56e621caa5039afe72c1574bbf953621db94c901914d3a3a19c00f68afba0b1b638196f7287d1d3756ad103ba04ad012ff2db66c042919ca083bce8b1b6b554e
7
+ data.tar.gz: 4f87635abaef12140b87e6facaa0eb0fc7af1c6407a50d98cd1bb249977dc723939443fa03b7fe76a57cce249f4d4dc1d48270834428184316442c2f9d1d7cae
@@ -21,37 +21,44 @@ module ForestAdminDatasourceMongoid
21
21
  def add_null_values_on_record(record, projection)
22
22
  return nil if record.nil?
23
23
 
24
- result = record.dup
24
+ fill_null_values(record, build_null_values_tree(projection))
25
+ end
25
26
 
26
- projection.each do |field|
27
- field_prefix = field.split(':').first
28
- result[field_prefix] ||= nil
29
- end
27
+ def add_null_values(records, projection)
28
+ return [] if records.empty?
30
29
 
31
- nested_prefixes = projection.filter_map { |field| field.split(':').first if field.include?(':') }.uniq
30
+ tree = build_null_values_tree(projection)
31
+ records.filter_map { |record| fill_null_values(record, tree) }
32
+ end
32
33
 
33
- nested_prefixes.each do |nested_prefix|
34
- prefix_with_colon = "#{nested_prefix}:"
35
- child_paths = projection.filter_map do |field|
36
- field[(nested_prefix.size + 1)..] if field.start_with?(prefix_with_colon)
37
- end
34
+ private
38
35
 
39
- next unless result[nested_prefix] && !result[nested_prefix].nil?
36
+ def build_null_values_tree(paths)
37
+ paths.group_by { |path| path.split(':', 2).first }.to_h do |key, key_paths|
38
+ child_paths = key_paths.filter_map { |path| path.split(':', 2)[1] }
39
+ [key, child_paths.empty? ? nil : build_null_values_tree(child_paths)]
40
+ end
41
+ end
40
42
 
41
- if result[nested_prefix].is_a?(Array)
42
- result[nested_prefix] = result[nested_prefix].map do |child_record|
43
- add_null_values_on_record(child_record, child_paths)
44
- end
45
- elsif result[nested_prefix].is_a?(Hash)
46
- result[nested_prefix] = add_null_values_on_record(result[nested_prefix], child_paths)
47
- end
43
+ def fill_null_values(record, tree)
44
+ return nil if record.nil?
45
+
46
+ result = record.dup
47
+
48
+ tree.each do |key, sub_tree|
49
+ result[key] ||= nil
50
+ result[key] = fill_nested_null_values(result[key], sub_tree) if sub_tree
48
51
  end
49
52
 
50
53
  remove_not_exist_record(result)
51
54
  end
52
55
 
53
- def add_null_values(records, projection)
54
- records.filter_map { |record| add_null_values_on_record(record, projection) }
56
+ def fill_nested_null_values(value, sub_tree)
57
+ case value
58
+ when Array then value.map { |item| item.is_a?(Hash) ? fill_null_values(item, sub_tree) : item }
59
+ when Hash then fill_null_values(value, sub_tree)
60
+ else value
61
+ end
55
62
  end
56
63
  end
57
64
  end
@@ -1,5 +1,6 @@
1
1
  module ForestAdminDatasourceMongoid
2
2
  module Utils
3
+ # Unused internally; kept because it is a public constant of the published gem.
3
4
  MongoidSerializer = Struct.new(:object) do
4
5
  def to_hash(projection)
5
6
  hash_object(object, projection)
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceMongoid
2
- VERSION = "1.45.1"
2
+ VERSION = "1.45.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_datasource_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.45.1
4
+ version: 1.45.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2026-10-10 00:00:00.000000000 Z
12
+ date: 2026-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid