Module: RequestType::Validation
- Included in:
- RequestType
- Defined in:
- app/models/request_type/validation.rb
Overview
This is used when validating request options when the submission is made, and before it is actually built. Unfortunately things have gotten a little tangled around this area, and a heavy refactor is required.
Defined Under Namespace
Classes: RequestTypeValidator
Instance Method Summary collapse
-
#create_validator(request_type) ⇒ Object
rubocop:todo Metrics/MethodLength.
- #delegate_validator ⇒ Object
- #request_type_validator ⇒ Object
Instance Method Details
#create_validator(request_type) ⇒ Object
rubocop:todo Metrics/MethodLength
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/request_type/validation.rb', line 9 def create_validator(request_type) # rubocop:todo Metrics/MethodLength Class.new(RequestTypeValidator) do request_type.request_type_validators.each do |validator| = "is '%{value}' should be #{ validator..to_sentence(last_word_connector: ', or ', two_words_connector: ' or ') }" vro = :"#{validator.request_option}" delegate_attribute(vro, to: :target, default: validator.default, type_cast: validator.type_cast) validates vro, inclusion: { in: validator., if: :"#{validator.request_option}_needs_checking?", message: , allow_blank: validator.allow_blank? } end end end |
#delegate_validator ⇒ Object
5 6 7 |
# File 'app/models/request_type/validation.rb', line 5 def delegate_validator DelegateValidation::CompositeValidator.construct(request_class.delegate_validator, request_type_validator) end |
#request_type_validator ⇒ Object
29 30 31 32 |
# File 'app/models/request_type/validation.rb', line 29 def request_type_validator request_type = self create_validator(request_type).tap { |sub_class| sub_class.request_type = request_type } end |