iknow_view_models 3.7.5 → 3.7.6

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: 93c994829498ed19d7214cca326ef7c361de788b5d88fb00e4927208aca9f21a
4
- data.tar.gz: 75019085c70b0feed81316211922e3cb87b6dfee0485a3c6424070db028a68cd
3
+ metadata.gz: f4e2ce83aca25f76c562927351a4c3061566428bd6d599f8d1efd3a0fe67b953
4
+ data.tar.gz: e6f11b57045e611fd9e3133f28fbfe7e9ee42c82edafdaa4a7be9a0c25311080
5
5
  SHA512:
6
- metadata.gz: 90ac0ba33c195e22e1d3f51e9be84cdccb0fe5646d8f2ee93deba2eb5aff865a6a37dd1bf0f115a0c00fc6e33b64a086a5519b1acd90a107cede3d54c018f0c2
7
- data.tar.gz: 949f86898a69d142dd5f1576054d18675785fcaae9d30c64344f1e3681f18aabae82c61cddd08a6ca3523796380cfb62e1ccb1ceee6d8d5c92753b59837c51a9
6
+ metadata.gz: 628bebb67d57d5036640357c5cc9429ada7d84b5fd70d57d9aa1a35244bf1bd50f0d6851d56c7949ef46d54db6c066810f3e7206833419cee16b7b1e9ee1c030
7
+ data.tar.gz: 497c85d6648b089bb6cac073684cf070becf37b2505b977d13ce2115eaaa7eef68da985713304548241a69b88dba3d2729925ec87ef384792cf721fdcf73b4a7
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.7.5'
4
+ VERSION = '3.7.6'
5
5
  end
@@ -81,15 +81,15 @@ class ViewModel::ActiveRecord
81
81
  viewmodel._list_attribute = reposition_to
82
82
  end
83
83
 
84
+ # Visit attributes and associations as much as possible in the order
85
+ # that they're declared in the view.
86
+ member_ordering = viewmodel.class._members.keys.each_with_index.to_h
87
+
84
88
  # update user-specified attributes
85
- valid_members = viewmodel.class._members.keys.map(&:to_s).to_set
86
- bad_keys = attributes.keys.reject { |k| valid_members.include?(k) }
87
- if bad_keys.present?
88
- causes = bad_keys.map { |k| ViewModel::DeserializationError::UnknownAttribute.new(k, blame_reference) }
89
- raise ViewModel::DeserializationError::Collection.for_errors(causes)
90
- end
89
+ attribute_keys = attributes.keys.sort_by { |k| member_ordering[k] }
90
+ attribute_keys.each do |attr_name|
91
+ serialized_value = attributes[attr_name]
91
92
 
92
- attributes.each do |attr_name, serialized_value|
93
93
  # Note that the VM::AR deserialization tree asserts ownership over any
94
94
  # references it's provided, and so they're intentionally not passed on
95
95
  # to attribute deserialization for use by their `using:` viewmodels. A
@@ -101,7 +101,13 @@ class ViewModel::ActiveRecord
101
101
  end
102
102
 
103
103
  # Update points-to associations before save
104
- points_to.each do |association_data, child_operation|
104
+ points_to_keys = points_to.keys.sort_by do |association_data|
105
+ member_ordering[association_data.association_name]
106
+ end
107
+
108
+ points_to_keys.each do |association_data|
109
+ child_operation = points_to[association_data]
110
+
105
111
  reflection = association_data.direct_reflection
106
112
  debug "-> #{debug_name}: Updating points-to association '#{reflection.name}'"
107
113
 
@@ -138,7 +144,12 @@ class ViewModel::ActiveRecord
138
144
 
139
145
  # Update association cache of pointed-from associations after save: the
140
146
  # child update will have saved the pointer.
141
- pointed_to.each do |association_data, child_operation|
147
+ pointed_to_keys = pointed_to.keys.sort_by do |association_data|
148
+ member_ordering[association_data.association_name]
149
+ end
150
+
151
+ pointed_to_keys.each do |association_data|
152
+ child_operation = pointed_to[association_data]
142
153
  reflection = association_data.direct_reflection
143
154
 
144
155
  debug "-> #{debug_name}: Updating pointed-to association '#{reflection.name}'"
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.7.5
4
+ version: 3.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-31 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack