Class: Datadog::DI::EL::Evaluator Private
- Inherits:
-
Object
- Object
- Datadog::DI::EL::Evaluator
- Defined in:
- lib/datadog/di/el/evaluator.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.
Evaluator for expression language.
Instance Method Summary collapse
- #all(collection, &block) ⇒ Object private
- #any(collection, &block) ⇒ Object private
- #contains(haystack, needle) ⇒ Object private
- #ends_with(haystack, needle) ⇒ Object private
- #filter(collection, &block) ⇒ Object private
- #getmember(object, field) ⇒ Object private
- #index(array_or_hash, index_or_key) ⇒ Object private
- #instanceof(object, cls_name) ⇒ Object private
- #iref(var) ⇒ Object private
- #is_empty(var, var_name) ⇒ Object private
- #is_undefined(var, var_name) ⇒ Object private
- #len(var, var_name) ⇒ Object private
- #matches(haystack, needle) ⇒ Object private
- #ref(var) ⇒ Object private
- #starts_with(haystack, needle) ⇒ Object private
- #substring(object, from, to) ⇒ Object private
Instance Method Details
#all(collection, &block) ⇒ 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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/datadog/di/el/evaluator.rb', line 94 def all(collection, &block) case collection when Array collection.all? do |item| block.call(item) end when Hash # For hashes, the expression language has both @it and # @key/@value. Manufacture @it from the key and value. collection.all? do |key, value| block.call([key, value], key, value) end else raise DI::Error::ExpressionEvaluationError, "Bad collection type for all: #{collection.class}" end end |
#any(collection, &block) ⇒ 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.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/datadog/di/el/evaluator.rb', line 111 def any(collection, &block) case collection when Array collection.any? do |item| block.call(item) end when Hash collection.any? do |key, value| # For hashes, the expression language has both @it and # @key/@value. Manufacture @it from the key and value. block.call([key, value], key, value) end else raise DI::Error::ExpressionEvaluationError, "Bad collection type for any: #{collection.class}" end end |
#contains(haystack, needle) ⇒ 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.
42 43 44 45 46 47 48 49 |
# File 'lib/datadog/di/el/evaluator.rb', line 42 def contains(haystack, needle) if String === haystack && String === needle or # standard:disable Style/AndOr Array === haystack haystack.include?(needle) else raise DI::Error::ExpressionEvaluationError, "Invalid arguments for contains: #{haystack}, #{needle}" end end |
#ends_with(haystack, needle) ⇒ 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.
90 91 92 |
# File 'lib/datadog/di/el/evaluator.rb', line 90 def ends_with(haystack, needle) String === haystack && haystack.end_with?(needle) end |
#filter(collection, &block) ⇒ 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.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/datadog/di/el/evaluator.rb', line 128 def filter(collection, &block) case collection when Array collection.select do |item| block.call(item) end when Hash collection.select do |key, value| block.call([key, value], key, value) end.to_h else raise DI::Error::ExpressionEvaluationError, "Bad collection type for filter: #{collection.class}" end end |
#getmember(object, field) ⇒ 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.
56 57 58 |
# File 'lib/datadog/di/el/evaluator.rb', line 56 def getmember(object, field) object.instance_variable_get("@#{field}") end |
#index(array_or_hash, index_or_key) ⇒ 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.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/datadog/di/el/evaluator.rb', line 60 def index(array_or_hash, index_or_key) case array_or_hash when Array case index_or_key when Integer array_or_hash[index_or_key] else raise DI::Error::ExpressionEvaluationError, "Invalid index value: #{index_or_key}" end when Hash array_or_hash[index_or_key] else raise DI::Error::ExpressionEvaluationError, "Invalid argument for index: #{array_or_hash}" end end |
#instanceof(object, cls_name) ⇒ 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.
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/datadog/di/el/evaluator.rb', line 143 def instanceof(object, cls_name) cls = object.class loop do if cls.name == cls_name return true end if supercls = cls.superclass # standard:disable Lint/AssignmentInCondition cls = supercls else return false end end end |
#iref(var) ⇒ 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.
14 15 16 |
# File 'lib/datadog/di/el/evaluator.rb', line 14 def iref(var) @context.fetch_ivar(var) end |
#is_empty(var, var_name) ⇒ 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.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/datadog/di/el/evaluator.rb', line 27 def is_empty(var, var_name) case var when nil, Numeric false when Array, String var.empty? else raise DI::Error::ExpressionEvaluationError, "Unsupported type for isEmpty: #{var.class}: #{var_name}" end end |
#is_undefined(var, var_name) ⇒ 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.
38 39 40 |
# File 'lib/datadog/di/el/evaluator.rb', line 38 def is_undefined(var, var_name) var.nil? end |
#len(var, var_name) ⇒ 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.
18 19 20 21 22 23 24 25 |
# File 'lib/datadog/di/el/evaluator.rb', line 18 def len(var, var_name) case var when Array, String var.length else raise DI::Error::ExpressionEvaluationError, "Unsupported type for length: #{var.class}: #{var_name}" end end |
#matches(haystack, needle) ⇒ 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.
51 52 53 54 |
# File 'lib/datadog/di/el/evaluator.rb', line 51 def matches(haystack, needle) re = Regexp.compile(needle) !!(haystack =~ re) end |
#ref(var) ⇒ 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.
10 11 12 |
# File 'lib/datadog/di/el/evaluator.rb', line 10 def ref(var) @context.fetch(var) end |
#starts_with(haystack, needle) ⇒ 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.
83 84 85 86 87 88 |
# File 'lib/datadog/di/el/evaluator.rb', line 83 def starts_with(haystack, needle) # To guard against running arbitrary customer code, check that # the haystack is a string. This does not help if customer # overrode String#start_with? but at least it's better than nothing. String === haystack && haystack.start_with?(needle) end |
#substring(object, from, to) ⇒ 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.
76 77 78 79 80 81 |
# File 'lib/datadog/di/el/evaluator.rb', line 76 def substring(object, from, to) unless String === object raise DI::Error::ExpressionEvaluationError, "Invalid type for substring: #{object}" end object[from...to] end |