iknow_view_models 3.1.3 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iknow_view_models/version.rb +1 -1
- data/lib/view_model.rb +1 -1
- data/lib/view_model/active_record/association_data.rb +1 -1
- data/lib/view_model/active_record/update_context.rb +7 -2
- data/lib/view_model/after_transaction_runner.rb +2 -1
- data/lib/view_model/traversal_context.rb +6 -4
- 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: 5fc6b7d1f2e4c48c65f3f603d8e322afe7f26d52e08bb418dc746f9c5b6bd6c0
|
4
|
+
data.tar.gz: 39eab5e4ae3423805b3c3d931504d08c623d8fbf602b58e4d978aeb7202aee71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13f7e88bc34527984aea0d73518acb2e2fa8e2a6cc4cbb408f325afd39bfedd738be907f0922efcfacebe1802002e8f8d1c86ca9c37fc9a810df767f923d4455
|
7
|
+
data.tar.gz: 71b8b322ce29db0b042c28b40c94820433d96beade6d991c5759a7828a7ce8101fcccc47fea3545538e522355fe949fd5a03493e26b22601c22e8bc31c8b2d92
|
data/lib/view_model.rb
CHANGED
@@ -17,7 +17,7 @@ class ViewModel::ActiveRecord::AssociationData
|
|
17
17
|
|
18
18
|
@direct_reflection = owner.model_class.reflect_on_association(direct_association_name)
|
19
19
|
if @direct_reflection.nil?
|
20
|
-
raise InvalidAssociation.new("Association '#{direct_association_name}' not found in model '#{model_class.name}'")
|
20
|
+
raise InvalidAssociation.new("Association '#{direct_association_name}' not found in model '#{owner.model_class.name}'")
|
21
21
|
end
|
22
22
|
|
23
23
|
@indirect_association_name = indirect_association_name
|
@@ -94,11 +94,16 @@ class ViewModel::ActiveRecord
|
|
94
94
|
# won't yet include through a polymorphic boundary: for now we become
|
95
95
|
# lazy-loading and slow every time that happens.
|
96
96
|
|
97
|
-
# Combine our root and referenced updates, and separate by viewmodel type
|
97
|
+
# Combine our root and referenced updates, and separate by viewmodel type.
|
98
|
+
# Sort by id where possible to obtain as close to possible a deterministic
|
99
|
+
# update order to avoid database write deadlocks. This can't be entirely
|
100
|
+
# comprehensive, since we can't control the order that shared references
|
101
|
+
# are referred to from roots (and therefore visited).
|
98
102
|
updates_by_viewmodel_class =
|
99
103
|
root_updates.lazily
|
100
104
|
.map { |root_update| [nil, root_update] }
|
101
105
|
.concat(referenced_updates)
|
106
|
+
.sort_by { |_, update_data| update_data.metadata.id.to_s }
|
102
107
|
.group_by { |_, update_data| update_data.viewmodel_class }
|
103
108
|
|
104
109
|
# For each viewmodel type, look up referenced models and construct viewmodels to update
|
@@ -115,7 +120,7 @@ class ViewModel::ActiveRecord
|
|
115
120
|
|
116
121
|
if models.size < model_ids.size
|
117
122
|
missing_model_ids = model_ids - models.map(&:id)
|
118
|
-
missing_viewmodel_refs = missing_model_ids.map
|
123
|
+
missing_viewmodel_refs = missing_model_ids.map { |id| ViewModel::Reference.new(viewmodel_class, id) }
|
119
124
|
raise ViewModel::DeserializationError::NotFound.new(missing_viewmodel_refs)
|
120
125
|
end
|
121
126
|
|
@@ -93,13 +93,15 @@ class ViewModel::TraversalContext
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def run_callback(hook, view, **args)
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
|
96
|
+
# Run in-viewmodel callback hooks before context hooks, as they are
|
97
|
+
# permitted to alter the model.
|
100
98
|
if view.respond_to?(hook.dsl_viewmodel_callback_method)
|
101
99
|
view.public_send(hook.dsl_viewmodel_callback_method, hook.context_name => self, **args)
|
102
100
|
end
|
101
|
+
|
102
|
+
callbacks.each do |callback|
|
103
|
+
callback.run_callback(hook, view, self, **args)
|
104
|
+
end
|
103
105
|
end
|
104
106
|
|
105
107
|
def root?
|
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.1.
|
4
|
+
version: 3.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iKnow Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|