Class: Datadog::DI::EL::Expression Private
- Inherits:
-
Object
- Object
- Datadog::DI::EL::Expression
- Defined in:
- lib/datadog/di/el/expression.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents an Expression Language expression.
Instance Attribute Summary collapse
- #dsl_expr ⇒ Object readonly private
- #evaluator ⇒ Object readonly private
- #redaction_identifier ⇒ Object readonly private
Instance Method Summary collapse
-
#evaluate(context, evaluation_deadline:) ⇒ Object
private
Evaluates the expression against
context. -
#initialize(dsl_expr, compiled_expr, regexps: [], redaction_identifier: nil) ⇒ Expression
constructor
private
A new instance of Expression.
-
#satisfied?(context, evaluation_deadline:) ⇒ Boolean
private
Returns whether the expression evaluates to a truthy value against
context.
Constructor Details
#initialize(dsl_expr, compiled_expr, regexps: [], redaction_identifier: nil) ⇒ Expression
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Expression.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/datadog/di/el/expression.rb', line 19 def initialize(dsl_expr, compiled_expr, regexps: [], redaction_identifier: nil) unless String === compiled_expr raise ArgumentError, "compiled_expr must be a string" end @dsl_expr = dsl_expr @redaction_identifier = redaction_identifier cls = Class.new(Evaluator) cls.class_exec do eval(<<-RUBY, Object.new.send(:binding), __FILE__, __LINE__ + 1) # standard:disable Security/Eval # Evaluates the compiled expression against +context+ within # the cooperative evaluation +evaluation_deadline+. # # @param context [Context] evaluation context (locals, instance # variables, and per-invocation special variables). # @param evaluation_deadline [Float] invocation-local evaluation # deadline, as CLOCK_THREAD_CPUTIME_ID float seconds. # @return [Object] the value the expression evaluates to. # @raise [DI::Error::ExpressionEvaluationError] the expression # failed to evaluate, including the EvaluationTimeout # subclass raised when the deadline is exceeded. def evaluate(context, evaluation_deadline) #{compiled_expr} end RUBY end @evaluator = cls.new(regexps) end |
Instance Attribute Details
#dsl_expr ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/datadog/di/el/expression.rb', line 49 def dsl_expr @dsl_expr end |
#evaluator ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/datadog/di/el/expression.rb', line 50 def evaluator @evaluator end |
#redaction_identifier ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 |
# File 'lib/datadog/di/el/expression.rb', line 51 def redaction_identifier @redaction_identifier end |
Instance Method Details
#evaluate(context, evaluation_deadline:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluates the expression against context.
63 64 65 |
# File 'lib/datadog/di/el/expression.rb', line 63 def evaluate(context, evaluation_deadline:) evaluator.evaluate(context, evaluation_deadline) end |
#satisfied?(context, evaluation_deadline:) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether the expression evaluates to a truthy value
against context.
77 78 79 |
# File 'lib/datadog/di/el/expression.rb', line 77 def satisfied?(context, evaluation_deadline:) !!evaluate(context, evaluation_deadline: evaluation_deadline) end |