class SchemaValidator

SchemaValidator validates nested schemas

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/schema_validator.rb, line 5
def validate_each(record, attribute, value)
  record.errors.add(attribute, options.fetch(:message, :invalid)) unless valid_schema?(value)
end

Private Instance Methods

valid_schema?(value) click to toggle source
# File lib/schema_validator.rb, line 11
def valid_schema?(value)
  return true unless value

  if value.is_a?(Array)
    value.all? do |schema|
      !schema || schema.valid?
    end
  else
    value.valid?
  end
end