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



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

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

#evaluate(expr, bindings = nil) ⇒ Object



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

def evaluate(expr, bindings = nil)
  context = Context.new(bindings)
  expr = compile(expr) if expr.is_a?(::String)
  Program.new(context).evaluate(expr)
end

#program(expr) ⇒ Object



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

def program(expr)
  expr = compile(expr) if expr.is_a?(::String)
  Runner.new(expr)
end