Class: Cel::Context
- Inherits:
-
Object
- Object
- Cel::Context
- Defined in:
- lib/cel/context.rb
Instance Attribute Summary collapse
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
Instance Method Summary collapse
-
#initialize(declarations, bindings) ⇒ Context
constructor
A new instance of Context.
- #lookup(identifier) ⇒ Object
- #merge(bindings) ⇒ Object
Constructor Details
#initialize(declarations, bindings) ⇒ Context
Returns a new instance of Context.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cel/context.rb', line 7 def initialize(declarations, bindings) @declarations = declarations @bindings = bindings.dup return unless @bindings @bindings.each do |k, v| val = to_cel_type(v) val = TYPES[@declarations[k]].cast(val) if @declarations && @declarations.key?(k) @bindings[k] = val end end |
Instance Attribute Details
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
5 6 7 |
# File 'lib/cel/context.rb', line 5 def declarations @declarations end |
Instance Method Details
#lookup(identifier) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cel/context.rb', line 20 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 |