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

Instance Method Details

#delegate_validatorObject


4
5
6
# File 'app/models/request_type/validation.rb', line 4

def delegate_validator
  DelegateValidation::CompositeValidator.construct(request_class.delegate_validator, request_type_validator)
end

#request_type_validatorObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/request_type/validation.rb', line 8

def request_type_validator
  request_type = self

  Class.new(RequestTypeValidator) do
    request_type.request_type_validators.each do |validator|
      message = "is '%{value}' should be #{validator.valid_options.to_sentence(last_word_connector: ' or ')}"
      vro = :"#{validator.request_option}"
      delegate_attribute(vro, to: :target, default: validator.default, type_cast: validator.type_cast)
      validates_inclusion_of vro, in: validator.valid_options, if: :"#{validator.request_option}_needs_checking?", message: message
    end
  end.tap do |sub_class|
    sub_class.request_type = request_type
  end
end