interactor-validation 0.3.5 → 0.3.6
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 +4 -4
- data/lib/interactor/validation/validates.rb +14 -2
- data/lib/interactor/validation/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d64db62a988b24630b88924e39bd64572401aed52a3b699bca548597cf1411a6
|
|
4
|
+
data.tar.gz: 5ce8276f8ee1835f5252c1d0e60bbda9044b5b734a4bc116dbb25af4956ceb1b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b80e35d7331bc9a4c7e10ee91aafde1b9aadae697aa0fb4f7a77fc7fb815452bcec8ce1e8d1cd855f98a38c18d3f22916936721fff06485d1434dac05a47130
|
|
7
|
+
data.tar.gz: 6ad6c3c9138866af06e42a25560f8c7cd49fbdd3cce497c1e5c6b301fd8d0edfaa270c45a1dac4929c57fdd18fd42773b3a22338ade9f2b23763575fa6d8c2a6
|
|
@@ -6,6 +6,9 @@ module Interactor
|
|
|
6
6
|
module Validates
|
|
7
7
|
extend ActiveSupport::Concern
|
|
8
8
|
|
|
9
|
+
# Exception raised when validation should halt immediately
|
|
10
|
+
class HaltValidation < StandardError; end
|
|
11
|
+
|
|
9
12
|
included do
|
|
10
13
|
class_attribute :_param_validations, instance_writer: false, default: {}
|
|
11
14
|
# Regex pattern cache for performance
|
|
@@ -105,8 +108,11 @@ module Interactor
|
|
|
105
108
|
# Call the original add method
|
|
106
109
|
__getobj__.add(attribute, message, **options)
|
|
107
110
|
|
|
108
|
-
# Set halt flag if requested
|
|
109
|
-
|
|
111
|
+
# Set halt flag and raise exception if requested
|
|
112
|
+
return unless halt
|
|
113
|
+
|
|
114
|
+
@interactor.instance_variable_set(:@halt_validation, true)
|
|
115
|
+
raise HaltValidation
|
|
110
116
|
end
|
|
111
117
|
end
|
|
112
118
|
|
|
@@ -153,6 +159,8 @@ module Interactor
|
|
|
153
159
|
rescue ActiveModel::ValidationError
|
|
154
160
|
# ActiveModel's validate! raises this when there are errors
|
|
155
161
|
# We handle errors differently, so just ignore this exception
|
|
162
|
+
rescue HaltValidation
|
|
163
|
+
# Validation halted - error already added, continue to fail context
|
|
156
164
|
end
|
|
157
165
|
end
|
|
158
166
|
|
|
@@ -191,6 +199,7 @@ module Interactor
|
|
|
191
199
|
# Accumulates errors but does not fail the context
|
|
192
200
|
# The validate! hook will fail the context if there are any errors
|
|
193
201
|
# @return [void]
|
|
202
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
|
194
203
|
def validate_params!
|
|
195
204
|
# Memoize config for performance
|
|
196
205
|
@current_config = current_config
|
|
@@ -224,10 +233,13 @@ module Interactor
|
|
|
224
233
|
# Don't fail here - let validate! hook handle failure
|
|
225
234
|
# This allows validate! to run and add additional custom errors
|
|
226
235
|
end
|
|
236
|
+
rescue HaltValidation
|
|
237
|
+
# Validation halted - error already added, stop processing
|
|
227
238
|
ensure
|
|
228
239
|
@current_config = nil # Clear memoization
|
|
229
240
|
# Don't reset @halt_validation here - let validate! handle it
|
|
230
241
|
end
|
|
242
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
|
231
243
|
|
|
232
244
|
# Get the current configuration (instance config overrides global config)
|
|
233
245
|
# @return [Configuration] the active configuration
|