model_driven_api 3.5.1 → 3.5.3
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 +4 -4
- data/config/initializers/auto_include_json.rb +13 -6
- data/lib/model_driven_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9c63c0404c13f3c0a73bc5959c4164184a07554a0cabe39b36af3b73123a341
|
4
|
+
data.tar.gz: 169edc727f279ec9be18dddb943fdab350183f5990ec8e64c83471cb3f44c01b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b1fcf103ac400e9ca7b41f6cca451a84d26425d57d252d4f3ac6a5a9b00e6c14762f16359efa213854e920cf63d479cf288140107b650ae0f62495107402f37
|
7
|
+
data.tar.gz: cca8e92d2023252c0058b2ff448aa51ccb2aa4929dca881cf822201a26f877623a14c47fc38010c29fc52634b5eca20287980fa3a72cb6f5c356648005dd042f
|
@@ -3,16 +3,23 @@
|
|
3
3
|
module AutoIncludeJson
|
4
4
|
# Recursively builds a hash suitable for ActiveRecord eager loading
|
5
5
|
def build_includes(include_option)
|
6
|
-
Rails.logger.debug "Building includes from: #{include_option.inspect} from #{caller_locations(1,1).first.label}"
|
6
|
+
Rails.logger.debug "AutoIncludeJson - Building includes from: #{include_option.inspect} from #{caller_locations(1,1).first.label}"
|
7
7
|
case include_option
|
8
8
|
when Array
|
9
|
-
include_option
|
9
|
+
include_option.map { |item| build_includes(item) }
|
10
10
|
when Hash
|
11
11
|
include_option.each_with_object({}) do |(assoc, value), hash|
|
12
|
+
# Skip keys that aren't associations
|
13
|
+
next if [:only, :except, :methods].include?(assoc)
|
14
|
+
|
12
15
|
if value.is_a?(Hash) && value[:include]
|
13
16
|
hash[assoc] = build_includes(value[:include])
|
17
|
+
elsif value.is_a?(Hash)
|
18
|
+
# If value is a hash, assume it might contain nested structure
|
19
|
+
nested = value.reject { |k, _| [:only, :except, :methods].include?(k) }
|
20
|
+
hash[assoc] = build_includes(nested) unless nested.empty?
|
14
21
|
else
|
15
|
-
hash[assoc] = {}
|
22
|
+
hash[assoc] = {} # eager load shallow association
|
16
23
|
end
|
17
24
|
end
|
18
25
|
else
|
@@ -50,7 +57,7 @@ module AutoIncludeRelationJson
|
|
50
57
|
include AutoIncludeJson
|
51
58
|
|
52
59
|
def to_json(options = nil)
|
53
|
-
Rails.logger.debug "Relation JSON to_json from #{caller_locations(1,1).first.label}"
|
60
|
+
Rails.logger.debug "AutoIncludeJson - Relation JSON to_json from #{caller_locations(1,1).first.label}"
|
54
61
|
return super unless options.is_a?(Hash) && options[:include]
|
55
62
|
|
56
63
|
includes_hash = build_includes(options[:include])
|
@@ -61,7 +68,7 @@ module AutoIncludeRelationJson
|
|
61
68
|
end
|
62
69
|
|
63
70
|
def as_json(options = nil)
|
64
|
-
Rails.logger.debug "Relation JSON as_json from #{caller_locations(1,1).first.label}"
|
71
|
+
Rails.logger.debug "AutoIncludeJson - Relation JSON as_json from #{caller_locations(1,1).first.label}"
|
65
72
|
return super unless options.is_a?(Hash) && options[:include]
|
66
73
|
|
67
74
|
includes_hash = build_includes(options[:include])
|
@@ -89,7 +96,7 @@ module AutoIncludeInstanceJson
|
|
89
96
|
private
|
90
97
|
|
91
98
|
def preload_and_sanitize!(options)
|
92
|
-
Rails.logger.debug "Instance JSON preload_and_sanitize! from #{caller_locations(1,1).first.label}"
|
99
|
+
Rails.logger.debug "AutoIncludeJson - Instance JSON preload_and_sanitize! from #{caller_locations(1,1).first.label}"
|
93
100
|
return unless options.is_a?(Hash) && options[:include]
|
94
101
|
|
95
102
|
includes_hash = build_includes(options[:include])
|