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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90ccbf1e2c6cbd490de913f189646e01fbb2b0cda22c6530d9d0794667a6650d
4
- data.tar.gz: 2ed2d34f0d09e4ee4c295a92ef5cf34b0054062ae8dbdc433e33c10840b9e2c5
3
+ metadata.gz: 5fc6b7d1f2e4c48c65f3f603d8e322afe7f26d52e08bb418dc746f9c5b6bd6c0
4
+ data.tar.gz: 39eab5e4ae3423805b3c3d931504d08c623d8fbf602b58e4d978aeb7202aee71
5
5
  SHA512:
6
- metadata.gz: c3f08635ca1378a44fbd2a9dcade0cf3f8f7edb2169b46f8c1c13c3869d4453f64d5dd96e9f1c91018d466a078ff63d3bce1e892cc938a5a45fe89979f89cacc
7
- data.tar.gz: f02a6f45243e40fb54d7fd0ac146667c6673116b83eb93795b7b454d1ee286bb4d2d797587b9a35662a09f5f3e7ee616b2086aa1a24dc963ade74e22a1e70f92
6
+ metadata.gz: 13f7e88bc34527984aea0d73518acb2e2fa8e2a6cc4cbb408f325afd39bfedd738be907f0922efcfacebe1802002e8f8d1c86ca9c37fc9a810df767f923d4455
7
+ data.tar.gz: 71b8b322ce29db0b042c28b40c94820433d96beade6d991c5759a7828a7ce8101fcccc47fea3545538e522355fe949fd5a03493e26b22601c22e8bc31c8b2d92
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.1.3'
4
+ VERSION = '3.1.8'
5
5
  end
@@ -89,7 +89,7 @@ class ViewModel
89
89
  end
90
90
 
91
91
  def member_names
92
- _attributes
92
+ _attributes.map(&:to_s)
93
93
  end
94
94
 
95
95
  # In deserialization, verify and extract metadata from a provided hash.
@@ -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 { |id| ViewModel::Reference.new(viewmodel_class, id) }
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
 
@@ -33,7 +33,8 @@ module ViewModel::AfterTransactionRunner
33
33
  if connection.transaction_open?
34
34
  connection.add_transaction_record(self)
35
35
  else
36
- after_transaction
36
+ before_commit
37
+ after_commit
37
38
  end
38
39
  end
39
40
 
@@ -93,13 +93,15 @@ class ViewModel::TraversalContext
93
93
  end
94
94
 
95
95
  def run_callback(hook, view, **args)
96
- callbacks.each do |callback|
97
- callback.run_callback(hook, view, self, **args)
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.3
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-03-10 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord