Class: Validate::AST::DefinitionContext
- Inherits:
-
Object
- Object
- Validate::AST::DefinitionContext
- Defined in:
- lib/validate/ast.rb
Defined Under Namespace
Modules: Builder
Class Method Summary collapse
Instance Method Summary collapse
- #add_constraint(constraint) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize ⇒ DefinitionContext
constructor
A new instance of DefinitionContext.
Constructor Details
#initialize ⇒ DefinitionContext
Returns a new instance of DefinitionContext.
52 53 54 |
# File 'lib/validate/ast.rb', line 52 def initialize @constraints = {} end |
Class Method Details
Instance Method Details
#add_constraint(constraint) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
66 67 68 69 70 71 |
# 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 |