Class: Cel::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/cel/environment.rb

Instance Method Summary collapse

Constructor Details

#initialize(declarations = nil) ⇒ Environment

Returns a new instance of Environment.



5
6
7
8
9
# File 'lib/cel/environment.rb', line 5

def initialize(declarations = nil)
  @declarations = declarations
  @parser = Parser.new
  @checker = Checker.new(@declarations)
end

Instance Method Details

#check(expr) ⇒ Object



27
28
29
30
# File 'lib/cel/environment.rb', line 27

def check(expr)
  ast = @parser.parse(expr)
  @checker.check(ast)
end

#compile(expr) ⇒ Object



11
12
13
14
15
# File 'lib/cel/environment.rb', line 11

def compile(expr)
  ast = @parser.parse(expr)
  @checker.check(ast)
  ast
end

#decode(encoded_expr) ⇒ Object



21
22
23
24
25
# File 'lib/cel/environment.rb', line 21

def decode(encoded_expr)
  ast = Encoder.decode(encoded_expr)
  @checker.check(ast)
  ast
end

#encode(expr) ⇒ Object



17
18
19
# File 'lib/cel/environment.rb', line 17

def encode(expr)
  Encoder.encode(compile(expr))
end

#evaluate(expr, bindings = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/cel/environment.rb', line 38

def evaluate(expr, bindings = nil)
  context = Context.new(@declarations, bindings)
  expr = @parser.parse(expr) if expr.is_a?(::String)
  @checker.check(expr)
  Program.new(context).evaluate(expr)
end

#program(expr) ⇒ Object



32
33
34
35
36
# File 'lib/cel/environment.rb', line 32

def program(expr)
  expr = @parser.parse(expr) if expr.is_a?(::String)
  @checker.check(expr)
  Runner.new(@declarations, expr)
end