class DTOSchema::Validators::ObjectValidator::Builder

Public Class Methods

new(schema, validator) click to toggle source
# File lib/dto_schema/validators.rb, line 220
def initialize(schema, validator)
  @schema = schema
  @validator = validator
end

Public Instance Methods

any() click to toggle source
# File lib/dto_schema/validators.rb, line 248
def any
  AnyValidator::INSTANCE
end
bool() click to toggle source
# File lib/dto_schema/validators.rb, line 244
def bool
  BoolValidator::INSTANCE
end
check() click to toggle source
# File lib/dto_schema/validators.rb, line 252
def check
  @schema.bind_check
end
field(name, required: false, type: AnyValidator::INSTANCE, check: nil, &validations) click to toggle source
# File lib/dto_schema/validators.rb, line 225
def field (name, required: false, type: AnyValidator::INSTANCE, check: nil, &validations)
  check = Checks::parse_checks check, @schema
  check << Checks::Check.new(validations) unless validations.nil?
  field = FieldValidator.new(@schema, name, required, type, check)
  @validator.define_field(name, field)
end
invariant(fields = nil, &block) click to toggle source
# File lib/dto_schema/validators.rb, line 256
def invariant (fields = nil, &block)
  fields = [] if fields.nil?
  fields = [fields] if fields.is_a? Symbol
  @validator.define_invariant Invariant.new(fields, block)
end
list() click to toggle source
# File lib/dto_schema/validators.rb, line 240
def list
  ListValidator::Builder.new @schema
end
optional(name, type, check: nil, &validations) click to toggle source
# File lib/dto_schema/validators.rb, line 236
def optional(name, type, check: nil, &validations)
  field(name, required: false, type: type, check: check, &validations)
end
required(name, type, check: nil, &validations) click to toggle source
# File lib/dto_schema/validators.rb, line 232
def required(name, type, check: nil, &validations)
  field(name, required: true, type: type, check: check, &validations)
end