Module: Cel::Extensions::Bind

Defined in:
lib/cel/extensions/bind.rb

Class Method Summary collapse

Class Method Details

.__check(funcall, checker:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cel/extensions/bind.rb', line 8

def __check(funcall, checker:)
  func = funcall.func
  args = funcall.args

  return checker.unsupported_operation(funcall) unless func == :bind

  checker.check_arity(func, args, 3)

  id, type, expr = args

  return checker.unsupported_operation(funcall) unless id.is_a?(Identifier)

  type = checker.call(type)

  checker.environment.with(declarations: { id.to_sym => type }) do
    checker.environment.check(expr)
  end
end

.bind(var, val, expr, program:) ⇒ Object



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

def bind(var, val, expr, program:)
  program.environment.with(declarations: { var.to_sym => val.type }, disable_check: false) do
    program.with_extra_context({ var.to_sym => val }).evaluate(expr)
  end
end