iknow_view_models 3.12.1 → 3.13.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf46376eaf22e04e38fb4b841c10ee273422c4927a1402b4cd2ca4d53f548cb7
|
|
4
|
+
data.tar.gz: eb83782759ccdc0259c25bf15eca93469272a947b0177c03cb739f478be0733b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6edef87440a300016dd2044330e25d1927d161a7706abb4fab86cfd1cffde93e980ef978097006364f7fa4330c4b669342c04f3c3768645832faa0b7f8742f99
|
|
7
|
+
data.tar.gz: a44050a5c1aebc470ab8c96e027935463b6dd05f3f796f828be33b40ad3af9cd9148fcddbc69aeadb00b1466b802b049c51378f05e63af2c67143838c74a8308
|
|
@@ -635,7 +635,12 @@ class ViewModel::ActiveRecord
|
|
|
635
635
|
deps[association_data.direct_reflection.name.to_s] = referenced_deps
|
|
636
636
|
end
|
|
637
637
|
|
|
638
|
-
|
|
638
|
+
deserialization_includes = viewmodel_class.deserialization_includes
|
|
639
|
+
unless deserialization_includes.is_a?(DeepPreloader::AbstractSpec)
|
|
640
|
+
deserialization_includes = DeepPreloader::Spec.parse(deserialization_includes)
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
DeepPreloader::Spec.new(deps).merge!(deserialization_includes)
|
|
639
644
|
end
|
|
640
645
|
|
|
641
646
|
def viewmodel_reference
|
data/lib/view_model.rb
CHANGED
|
@@ -192,12 +192,21 @@ class ViewModel
|
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
# If this viewmodel represents an AR model, what associations does it make
|
|
195
|
-
# use of? Returns a includes spec appropriate for
|
|
196
|
-
# AR-style nested hashes or DeepPreloader::Spec.
|
|
195
|
+
# use of during serialization? Returns a includes spec appropriate for
|
|
196
|
+
# DeepPreloader, either as AR-style nested hashes or DeepPreloader::Spec.
|
|
197
197
|
def eager_includes(include_referenced: true)
|
|
198
198
|
{}
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
+
# If this viewmodel represents an AR model, what associations does it make
|
|
202
|
+
# use of during deserialization? By default all mentioned associations are
|
|
203
|
+
# preloaded, however access controls and hooks may benefit from additional
|
|
204
|
+
# preloading. Returns a includes spec appropriate for DeepPreloader, either
|
|
205
|
+
# as AR-style nested hashes or DeepPreloader::Spec.
|
|
206
|
+
def deserialization_includes
|
|
207
|
+
{}
|
|
208
|
+
end
|
|
209
|
+
|
|
201
210
|
# ViewModel can serialize ViewModels, Arrays and Hashes of ViewModels, and
|
|
202
211
|
# relies on Jbuilder#merge! for other values (e.g. primitives).
|
|
203
212
|
def serialize(target, json, serialize_context: new_serialize_context)
|
|
@@ -443,4 +443,26 @@ class ViewModel::ActiveRecord::BelongsToTest < ActiveSupport::TestCase
|
|
|
443
443
|
end
|
|
444
444
|
end
|
|
445
445
|
end
|
|
446
|
+
|
|
447
|
+
class DeserializationIncludeTest < ActiveSupport::TestCase
|
|
448
|
+
include ARVMTestUtilities
|
|
449
|
+
include ViewModelSpecHelpers::Base
|
|
450
|
+
|
|
451
|
+
def model_attributes
|
|
452
|
+
super.merge(
|
|
453
|
+
viewmodel: ->(_v) {
|
|
454
|
+
def self.deserialization_includes
|
|
455
|
+
:child
|
|
456
|
+
end
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
def test_extra_dependencies
|
|
462
|
+
viewmodel_class # realize lazy dependency
|
|
463
|
+
|
|
464
|
+
root_updates, _ref_updates = ViewModel::ActiveRecord::UpdateData.parse_hashes([{ '_type' => 'Model' }])
|
|
465
|
+
assert_equal(DeepPreloader::Spec.new('child' => nil), root_updates.first.preload_dependencies)
|
|
466
|
+
end
|
|
467
|
+
end
|
|
446
468
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: iknow_view_models
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- iKnow Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|