class Validate::AST::DefinitionContext

Public Class Methods

create(*args, &block) click to toggle source
# File lib/validate/ast.rb, line 45
def self.create(*args, &block)
  ast = AST.build(*args, &block)
  context = new
  ast.each { |node| context.add_constraint(Builder.send(*node)) }
  context
end
new() click to toggle source
# File lib/validate/ast.rb, line 52
def initialize
  @constraints = {}
end

Public Instance Methods

add_constraint(constraint) click to toggle source
# File lib/validate/ast.rb, line 56
def add_constraint(constraint)
  if @constraints.include?(constraint.name)
    raise Error::ValidationRuleError,
          "duplicate constraint #{constraint.name}"
  end

  @constraints[constraint.name] = constraint
  self
end
evaluate(ctx) click to toggle source
# File lib/validate/ast.rb, line 66
def evaluate(ctx)
  @constraints.each_value
              .reject { |c| catch(:pending) { c.valid?(ctx.value, ctx) } }
              .each { |c| ctx.add_violation(c) }
  ctx
end