blueprinter-activerecord 1.0.2 → 1.1.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 +4 -4
- data/lib/blueprinter-activerecord/preloader.rb +18 -1
- data/lib/blueprinter-activerecord/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a433613eafed67560509b44a75f9d8468eb98addf5262865cef731b63c2175b
|
4
|
+
data.tar.gz: 37ed9a65f70a441dfc23806b0c67bf7a1622170bb607f416e280a4739cc1c472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ca1480aeaae70cef964408594dd4b72b12101925daf12d8233c0c454652c451c427a0e91c430ad18612d1bb47002496289caffdb0b8cdd48d8a537056fcb36
|
7
|
+
data.tar.gz: ae53e10d27f7c93cab9920151bee1b3a10ed3d1b46b807b5420a297ee3cdfa2bae05ebae5f26ca1e5809616d05609771b5a9368537e9c980d43b6031e1f0622f
|
@@ -57,6 +57,10 @@ module BlueprinterActiveRecord
|
|
57
57
|
#
|
58
58
|
# Returns an ActiveRecord preload plan extracted from the Blueprint and view (recursive).
|
59
59
|
#
|
60
|
+
# Preloads are found when one of the model's associations matches:
|
61
|
+
# 1. A Blueprint association name.
|
62
|
+
# 2. A :preload option on a field or association.
|
63
|
+
#
|
60
64
|
# Example:
|
61
65
|
#
|
62
66
|
# preloads = BlueprinterActiveRecord::Preloader.preloads(WidgetBlueprint, :extended, Widget)
|
@@ -69,12 +73,25 @@ module BlueprinterActiveRecord
|
|
69
73
|
#
|
70
74
|
def self.preloads(blueprint, view_name, model=nil)
|
71
75
|
view = blueprint.reflections.fetch(view_name)
|
72
|
-
view.associations.each_with_object({}) { |(_name, assoc), acc|
|
76
|
+
preload_vals = view.associations.each_with_object({}) { |(_name, assoc), acc|
|
77
|
+
# look for a matching association on the model
|
73
78
|
ref = model ? model.reflections[assoc.name.to_s] : nil
|
74
79
|
if (ref || model.nil?) && !assoc.blueprint.is_a?(Proc)
|
75
80
|
ref_model = ref && !(ref.belongs_to? && ref.polymorphic?) ? ref.klass : nil
|
76
81
|
acc[assoc.name] = preloads(assoc.blueprint, assoc.view, ref_model)
|
77
82
|
end
|
83
|
+
|
84
|
+
# look for a :preload option on the association
|
85
|
+
if (custom = assoc.options[:preload])
|
86
|
+
Helpers.merge_values custom, acc
|
87
|
+
end
|
88
|
+
}
|
89
|
+
|
90
|
+
# look for a :preload options on fields
|
91
|
+
view.fields.each_with_object(preload_vals) { |(_name, field), acc|
|
92
|
+
if (custom = field.options[:preload])
|
93
|
+
Helpers.merge_values custom, acc
|
94
|
+
end
|
78
95
|
}
|
79
96
|
end
|
80
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprinter-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Procore Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|