Class: Cel::Context

Inherits:
Object
  • Object
show all
Includes:
Protobuf::ContextExtensions
Defined in:
lib/cel/context.rb

Instance Method Summary collapse

Methods included from Protobuf::ContextExtensions

included, #to_cel_type_with_protobuf

Constructor Details

#initialize(bindings) ⇒ Context

Returns a new instance of Context.



5
6
7
8
9
10
11
12
13
# File 'lib/cel/context.rb', line 5

def initialize(bindings)
  @bindings = bindings.dup

  return unless @bindings

  @bindings.each do |k, v|
    @bindings[k] = to_cel_type(v)
  end
end

Instance Method Details

#lookup(identifier) ⇒ Object

Raises:



15
16
17
18
19
20
21
22
23
24
# File 'lib/cel/context.rb', line 15

def lookup(identifier)
  raise EvaluateError, "no value in context for #{identifier}" unless @bindings

  id = identifier.id
  val = @bindings.dig(*id.split(".").map(&:to_sym))

  raise EvaluateError, "no value in context for #{identifier}" unless val

  val
end

#merge(bindings) ⇒ Object



26
27
28
# File 'lib/cel/context.rb', line 26

def merge(bindings)
  Context.new(@bindings ? @bindings.merge(bindings) : bindings)
end