Class: Datadog::DI::EL::Expression Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • dsl_expr (String) —

    human-readable DSL form, kept for debugging.

  • compiled_expr (String) —

    Ruby source produced by Compiler#compile.

  • regexps (Array<Regexp>) (defaults to: []) —

    precompiled matches regexps (see Compiler#precompile_regexp), the second element returned by Compiler#compile.

  • redaction_identifier (String, nil) (defaults to: nil) —

    the identifier this expression directly references at its top level (see Compiler#redaction_identifier); nil when it is not a direct reference.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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
      def evaluate(context)
        @context = context
        #{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.



39
40
41
# File 'lib/datadog/di/el/expression.rb', line 39

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.



40
41
42
# File 'lib/datadog/di/el/expression.rb', line 40

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.



41
42
43
# File 'lib/datadog/di/el/expression.rb', line 41

def redaction_identifier
  @redaction_identifier
end

Instance Method Details

#evaluate(context) ⇒ 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.



43
44
45
# File 'lib/datadog/di/el/expression.rb', line 43

def evaluate(context)
  @evaluator.evaluate(context)
end

#satisfied?(context) ⇒ 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:

  • (Boolean)


47
48
49
# File 'lib/datadog/di/el/expression.rb', line 47

def satisfied?(context)
  !!evaluate(context)
end