module CFF::Validatable

Methods to validate CFF files/models against a formal schema.

Public Instance Methods

validate(fail_fast: false) → Array click to toggle source

Validate a CFF file or model (Index) and return an array with the result. The result array is a two-element array, with true/false at index 0 to indicate pass/fail, and an array of errors at index 1 (if any). Setting fail_fast to true will fail validation at the first detected failure, rather than gathering and returning all failures.

# File lib/cff/validatable.rb, line 51
def validate(fail_fast: false)
  SCHEMA.validate(fields, fail_fast: fail_fast)
end
validate!(fail_fast: false) click to toggle source

Validate a CFF file or model (Index) and raise a ValidationError upon failure. If an error is raised it will contain the detected validation failures for further inspection. Setting fail_fast to true will fail validation at the first detected failure, rather than gathering and returning all failures.

# File lib/cff/validatable.rb, line 36
def validate!(fail_fast: false)
  result = validate(fail_fast: fail_fast)
  return if result[0]

  raise ValidationError.new(result[1])
end