lib/cel/context.rb in cel-0.1.2 vs lib/cel/context.rb in cel-0.2.0
- old
+ new
@@ -1,16 +1,21 @@
# frozen_string_literal: true
module Cel
class Context
- def initialize(bindings)
+ attr_reader :declarations
+
+ def initialize(declarations, bindings)
+ @declarations = declarations
@bindings = bindings.dup
return unless @bindings
@bindings.each do |k, v|
- @bindings[k] = to_cel_type(v)
+ val = to_cel_type(v)
+ val = TYPES[@declarations[k]].cast(val) if @declarations && @declarations.key?(k)
+ @bindings[k] = val
end
end
def lookup(identifier)
raise EvaluateError, "no value in context for #{identifier}" unless @bindings
@@ -22,10 +27,10 @@
val
end
def merge(bindings)
- Context.new(@bindings ? @bindings.merge(bindings) : bindings)
+ Context.new(@declarations, @bindings ? @bindings.merge(bindings) : bindings)
end
private
def to_cel_type(v)