Module: DelegateValidation
- Defined in:
- app/models/delegate_validation.rb
Overview
Delegate validation is all about enabling one class to validate the information within an instance of another class. The case driving this is the ability for a Submission to validate that the request options provided by the user are valid for the RequestType instances that the submission is going to use. In that case the RequestType#delegate_validator returns a class that can then be used to validate the request options. Because RequestType isn’t subclassed it actually delegates to the Request class that it’ll instantiate, so you can find examples of the delegator stuff in SequencingRequest and LibraryCreationRequest
Defined Under Namespace
Classes: AlwaysValidValidator, CompositeValidator, Validator
Instance Method Summary collapse
-
#delegate_validation(*args) ⇒ Object
rubocop:todo Metrics/MethodLength.
Instance Method Details
#delegate_validation(*args) ⇒ Object
rubocop:todo Metrics/MethodLength
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/delegate_validation.rb', line 10 def delegate_validation(*args) # rubocop:todo Metrics/AbcSize = args. delegation_target = .delete(:to) or raise StandardError, 'Cannot delegate validation without :to!' attribute_tag = [:as] args.push() validates_each(*args) do |record, _attr, value| validator = record.send(:"#{delegation_target}_delegate_validator").new(value) validator.valid?.tap do validator.errors..each do |attrib, | record.errors.add("#{attribute_tag}.#{attrib}", .join('; ')) end end end end |