class Dry::Schema::Predicate

Predicate objects used within the DSL

@api public

Attributes

args[R]

@api private

block[R]

@api private

compiler[R]

@api private

name[R]

@api private

Public Class Methods

new(compiler, name, args, block) click to toggle source

@api private

# File lib/dry/schema/predicate.rb, line 53
def initialize(compiler, name, args, block)
  @compiler = compiler
  @name = name
  @args = args
  @block = block
end

Public Instance Methods

!() click to toggle source

Negate a predicate

@example

required(:name).value(:string) { !empty? }

@return [Negation]

@api public

# File lib/dry/schema/predicate.rb, line 68
def !
  Negation.new(self)
end
ast(*)
Alias for: to_ast
ensure_valid() click to toggle source

@api private

# File lib/dry/schema/predicate.rb, line 73
def ensure_valid
  if compiler.predicates[name].arity - 1 != args.size
    raise ArgumentError, "#{name} predicate arity is invalid"
  end
end
to_ast(*) click to toggle source

Dump predicate to an AST

@return [Array]

@api private

# File lib/dry/schema/predicate.rb, line 91
def to_ast(*)
  [:predicate, [name, compiler.predicates.arg_list(name, *args)]]
end
Also aliased as: ast
to_rule() click to toggle source

Compile predicate to a rule object

@api private

# File lib/dry/schema/predicate.rb, line 82
def to_rule
  compiler.visit(to_ast)
end