criteria

package
v0.49.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

Criteria

Criteria provide convenient expression for conditional logic

The basic expression syntax:

criterion: leftOperand operator rightOperator

operators:

  • =, !=, >=, <=, <, >
  • : assertly operator for contains, RegExpr, ranges etc...

predicate: criterion [logical operator criterion]

logical operators:

  • &&
  • ||

predicate examples :

    $key1 = '123' || key2 > 3
    ($key1 = '123' || key2 > 3) AND $key5:/abc/

Expression with $ is expanded before evaluation if corresponding path exists.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(context *endly.Context, root string, expected, actual interface{}) (*assertly.Validation, error)

Assert validates expected against actual

func Evaluate

func Evaluate(context *endly.Context, state data.Map, expression, eventType string, defaultValue bool) (bool, error)

Evaluate evaluates passed in criteria

Types

type Criterion

type Criterion struct {
	*Predicate
	LeftOperand  interface{}
	Operator     string
	RightOperand interface{}
}

Criterion represent evaluation criterion

func NewCriterion

func NewCriterion(leftOperand interface{}, operator string, rightOperand interface{}) *Criterion

NewCriterion creates a new criterion

func (*Criterion) Apply

func (c *Criterion) Apply(state data.Map) (bool, error)

Apply evaluates criterion with supplied context and state map . Dolar prefixed $expression will be expanded before evaluation.

type EvalEvent

type EvalEvent struct {
	Type             string
	Default          bool
	Evaluation       bool
	Criteria         string
	ExpandedCriteria string
	Error            string
}

EvalEvent represents criteria event

func NewEvalEvent

func NewEvalEvent(criteriaType string, defaultValue, evaluation bool, criteria, expendedCriteria string, err error) *EvalEvent

NewEvalEvent creates a new evaluation event.

type Parser

type Parser struct{}

Parser represents endly criteria parser

func NewParser

func NewParser() *Parser

NewParser creates a new criteria parser

func (*Parser) Parse

func (p *Parser) Parse(expression string) (*Predicate, error)

Parse parses supplied expression. It returns criteria or parsing error.

type Predicate

type Predicate struct {
	LogicalOperator string
	Criteria        []*Criterion
}

Predicate represents logical criteria

func NewPredicate

func NewPredicate(operator string, criteria ...*Criterion) *Predicate

NewPredicate creates a new criteria for supplied logical operator and criteria

func (*Predicate) Apply

func (c *Predicate) Apply(state data.Map) (bool, error)

Apply evaluates criteria with supplied context and state map . Dolar prefixed $expression will be expanded before evaluation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL