Class: Inspector::Constraint::Validators::Validity

Inherits:
Object
  • Object
show all
Defined in:
lib/inspector/constraint/validators/validity.rb

Instance Method Summary collapse

Constructor Details

#initialize(validator) ⇒ Validity

Returns a new instance of Validity.



5
6
7
# File 'lib/inspector/constraint/validators/validity.rb', line 5

def initialize(validator)
  @validator = validator
end

Instance Method Details

#validate(value, constraint, violations_list) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/inspector/constraint/validators/validity.rb', line 9

def validate(value, constraint, violations_list)
  violations = @validator.validate(value, :as => constraint.validate_as(value))

  if constraint.positive?
    violations.violations.each { |violation| violations_list << violation }
    violations.children.each { |path, list| violations_list[path] = list }
  else
    if violations.empty?
      violations_list << Constraint::Violation.new(constraint)
    end
  end
end