interactor-validation 0.3.5 → 0.3.7

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: d6d255c1cdb4048fbd485a9bc8b95096d521e592e6babe4ea7961ec429312386
4
+ data.tar.gz: a9bc28cb3c10f5f2415da43c3a63b8c774436e13d27e2e6facaaa0cbcbeb19b9
5
5
  SHA512:
6
- metadata.gz: 84b4ba82ce1c459eca38bc708be8fa96e0add5665d49e495cf4c36d6e0b0063e4a2eeb3ff57b22159266094523efac406b9d08ff006b10792f5a53a9dd5c6dfb
7
- data.tar.gz: 8581c319bbd2adc9dc67bea77dc7da3a3bb9431bb16841bc7acae90115b1cde1fd44c158107d522d82640fa76a8dc696badea95d15a8d882d8a70803b790d67d
6
+ metadata.gz: f5e73c0e35a659668dd31783d5fbea0869f54efe3db2d1033320c66d90fe9fb7997a2fc7079b602608ac6aa1bec60467588ba4b6fdea6bdd3b890cd24ea55bf5
7
+ data.tar.gz: 7da53549b4bd1ef65065b9480dca243f1a78922045f096281025f7e35a034c8418ce88c90cac698fd6dd8816a9c434e23050b88a42701d96803e2bcf73d8f78a
@@ -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
@@ -481,16 +493,15 @@ module Interactor
481
493
  if current_config.error_mode == :code
482
494
  # Code mode: use custom message or generate code
483
495
  code_message = custom_message || error_code_for(error_type, **interpolations)
484
- errors.add(attribute_path, code_message)
496
+ errors.add(attribute_path, code_message, halt: halt)
485
497
  elsif custom_message
486
498
  # Default mode: use ActiveModel's error messages with custom message
487
- errors.add(attribute_path, custom_message)
499
+ errors.add(attribute_path, custom_message, halt: halt)
488
500
  else
489
- errors.add(attribute_path, error_type, **interpolations)
501
+ errors.add(attribute_path, error_type, halt: halt, **interpolations)
490
502
  end
491
503
 
492
- # Set halt flag if requested
493
- @halt_validation = true if halt
504
+ # Note: halt flag is set by ErrorsWrapper.add() if halt: true
494
505
  end
495
506
  # rubocop:enable Metrics/ParameterLists
496
507
 
@@ -689,16 +700,15 @@ module Interactor
689
700
  if current_config.error_mode == :code
690
701
  # Code mode: use custom message or generate code
691
702
  code_message = custom_message || error_code_for(error_type, **interpolations)
692
- errors.add(param_name, code_message)
703
+ errors.add(param_name, code_message, halt: halt)
693
704
  elsif custom_message
694
705
  # Default mode: use ActiveModel's error messages
695
- errors.add(param_name, custom_message)
706
+ errors.add(param_name, custom_message, halt: halt)
696
707
  else
697
- errors.add(param_name, error_type, **interpolations)
708
+ errors.add(param_name, error_type, halt: halt, **interpolations)
698
709
  end
699
710
 
700
- # Set halt flag if requested
701
- @halt_validation = true if halt
711
+ # Note: halt flag is set by ErrorsWrapper.add() if halt: true
702
712
  end
703
713
 
704
714
  # Generate error code for :code mode using constants
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Interactor
4
4
  module Validation
5
- VERSION = "0.3.5"
5
+ VERSION = "0.3.7"
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Anciro