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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6efd174866dfa694eb729fd033ce69cf9a7a3d91df52662f9f387704d111aaa
4
- data.tar.gz: 5f55753b346219e89237235aeb4976ff853110e2e11374569fc2a261d3b4faaf
3
+ metadata.gz: d64db62a988b24630b88924e39bd64572401aed52a3b699bca548597cf1411a6
4
+ data.tar.gz: 5ce8276f8ee1835f5252c1d0e60bbda9044b5b734a4bc116dbb25af4956ceb1b
5
5
  SHA512:
6
- metadata.gz: 84b4ba82ce1c459eca38bc708be8fa96e0add5665d49e495cf4c36d6e0b0063e4a2eeb3ff57b22159266094523efac406b9d08ff006b10792f5a53a9dd5c6dfb
7
- data.tar.gz: 8581c319bbd2adc9dc67bea77dc7da3a3bb9431bb16841bc7acae90115b1cde1fd44c158107d522d82640fa76a8dc696badea95d15a8d882d8a70803b790d67d
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
- @interactor.instance_variable_set(:@halt_validation, true) if halt
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Interactor
4
4
  module Validation
5
- VERSION = "0.3.5"
5
+ VERSION = "0.3.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interactor-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Anciro