Class: Kumi::Core::Input::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/core/input/validator.rb

Class Method Summary collapse

Class Method Details

.format_type(type) ⇒ Object



37
38
39
# File 'lib/kumi/core/input/validator.rb', line 37

def self.format_type(type)
  TypeMatcher.format_type(type)
end

.infer_type(value) ⇒ Object



33
34
35
# File 'lib/kumi/core/input/validator.rb', line 33

def self.infer_type(value)
  TypeMatcher.infer_type(value)
end

.type_matches?(value, declared_type) ⇒ Boolean



29
30
31
# File 'lib/kumi/core/input/validator.rb', line 29

def self.type_matches?(value, declared_type)
  TypeMatcher.matches?(value, declared_type)
end

.validate_context(context, input_meta) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kumi/core/input/validator.rb', line 7

def self.validate_context(context, input_meta)
  violations = []

  context.each do |field, value|
    meta = input_meta[field]
    next unless meta

    # Type validation first
    if should_validate_type?(meta) && !TypeMatcher.matches?(value, meta[:type])
      violations << ViolationCreator.create_type_violation(field, value, meta[:type])
      next # Skip domain validation if type is wrong
    end

    # Domain validation second (only if type is correct)
    if should_validate_domain?(meta) && !Domain::Validator.validate_field(field, value, meta[:domain])
      violations << ViolationCreator.create_domain_violation(field, value, meta[:domain])
    end
  end

  violations
end