iknow_view_models 3.11.0 → 3.12.0

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: 40eb8cc78ae998113eac37ef9cd944ecefc1c4b0a71a492944ac88ff2bfa4077
4
- data.tar.gz: cb7d430a809687598e365e54a0312e97fc6ee1938cfdd1c4f9f1bd924e8364a5
3
+ metadata.gz: 07b80f46184b9f84a29e63b4f26c65b9cf7e7b7fa0a6390365e66c92cbac0325
4
+ data.tar.gz: 240963485ad8192d341ad3ce40a5d360052a69055036bf3ca64fb76d2f176c36
5
5
  SHA512:
6
- metadata.gz: dd1c4215f6e9bafaf68c618d4ba59541089016d4dcea45ab90892489cc6ada0183f95a6d07ae88899fc54d5a9bf37a3619e70bc62c54ed9c5b9de57eeec5f37f
7
- data.tar.gz: e1cd93bf28d4ad96ac347effeb96d9bbbd6a1ec9a09944091d8127555b1c22ca2e97bfa7f5ce670f86cf42647b06d3e1da13a842935eb0bd39e44c303af666ab
6
+ metadata.gz: 0ddaba32ebd18303eba6f2e91db5ca44368c538bba771c6572afa4a3b4d7e17efd69ef6bfb274218b2f1fcf73812a8bb62704aa60065c3e45900428eff91e231
7
+ data.tar.gz: 7b482657ab857da0848f7880caf8a67a08ecbf132b3495d2117ea89642270525db95bf92fe26160ff0bc9450d3b514e94ca2ef77252f47a0ae6f04934a49efd0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.11.0'
4
+ VERSION = '3.12.0'
5
5
  end
@@ -522,6 +522,10 @@ class ViewModel::ActiveRecord
522
522
 
523
523
  delegate :new?, :child_update?, :auto_child_update?, to: :metadata
524
524
 
525
+ def reference_only?
526
+ attributes.empty? && associations.empty? && referenced_associations.empty?
527
+ end
528
+
525
529
  def self.parse_hashes(root_subtree_hashes, referenced_subtree_hashes = {})
526
530
  valid_reference_keys = referenced_subtree_hashes.keys.to_set
527
531
 
@@ -44,6 +44,10 @@ class ViewModel::ActiveRecord
44
44
  @built
45
45
  end
46
46
 
47
+ def reference_only?
48
+ update_data.reference_only? && reparent_to.nil? && reposition_to.nil?
49
+ end
50
+
47
51
  # Evaluate a built update tree, applying and saving changes to the models.
48
52
  def run!(deserialize_context:)
49
53
  raise ViewModel::DeserializationError::Internal.new('Internal error: UpdateOperation run before build') unless built?
@@ -123,9 +127,14 @@ class ViewModel::ActiveRecord
123
127
  end
124
128
  end
125
129
 
126
- # validate
127
- deserialize_context.run_callback(ViewModel::Callbacks::Hook::BeforeValidate, viewmodel)
128
- viewmodel.validate!
130
+ # If a request makes no assertions about the model, we don't demand
131
+ # that the current state of the model is valid. This permits making
132
+ # edits to other models that refer to this model when this model is
133
+ # invalid.
134
+ unless reference_only? && !viewmodel.new_model?
135
+ deserialize_context.run_callback(ViewModel::Callbacks::Hook::BeforeValidate, viewmodel)
136
+ viewmodel.validate!
137
+ end
129
138
 
130
139
  # Save if the model has been altered. Covers not only models with
131
140
  # view changes but also lock version assertions.
@@ -5,8 +5,18 @@ class ViewModel::Migration
5
5
  require 'view_model/migration/one_way_error'
6
6
  require 'view_model/migration/unspecified_version_error'
7
7
 
8
+ REFERENCE_ONLY_KEYS = [
9
+ ViewModel::TYPE_ATTRIBUTE,
10
+ ViewModel::ID_ATTRIBUTE,
11
+ ViewModel::VERSION_ATTRIBUTE,
12
+ ].freeze
13
+
8
14
  def up(view, _references)
9
- raise ViewModel::Migration::OneWayError.new(view[ViewModel::TYPE_ATTRIBUTE], :up)
15
+ # Only a reference-only view may be (trivially) migrated up without an
16
+ # explicit migration.
17
+ if (view.keys - REFERENCE_ONLY_KEYS).present?
18
+ raise ViewModel::Migration::OneWayError.new(view[ViewModel::TYPE_ATTRIBUTE], :up)
19
+ end
10
20
  end
11
21
 
12
22
  def down(view, _references)
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.11.0
4
+ version: 3.12.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-07-19 00:00:00.000000000 Z
11
+ date: 2024-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack