Class: Aspecto::OpenTelemetry::Sampler::Operator
- Inherits:
-
Object
- Object
- Aspecto::OpenTelemetry::Sampler::Operator
- Defined in:
- lib/aspecto/opentelemetry/sampler/operator.rb
Overview
A single operator used to evaluate sampling rules
Instance Method Summary collapse
-
#initialize(operator, expected) ⇒ Operator
constructor
rubocop:disable Metrics/AbcSize.
- #satisfies?(actual) ⇒ Boolean
Constructor Details
#initialize(operator, expected) ⇒ Operator
rubocop:disable Metrics/AbcSize
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aspecto/opentelemetry/sampler/operator.rb', line 10 def initialize(operator, expected) # rubocop:disable Metrics/AbcSize @expected = expected&.downcase @expected = Regexp.new(@expected) if operator == "matches" operator_to_proc = { "eq" => proc { |actual| @expected == actual }, "ne" => proc { |actual| @expected != actual }, "starts_with" => proc { |actual| actual&.start_with?(expected) }, "ends_with" => proc { |actual| actual&.end_with?(expected) }, "contains" => proc { |actual| actual&.include?(expected) }, "not_contains" => proc { |actual| !actual&.include?(expected) }, "matches" => proc { |actual| @expected.match(actual) }, "defined" => proc { |actual| !actual.nil? }, "undefined" => proc { |actual| actual.nil? }, "any" => proc { true } } @evaluate = operator_to_proc.fetch(operator, proc { false }) end |
Instance Method Details
#satisfies?(actual) ⇒ Boolean
30 31 32 |
# File 'lib/aspecto/opentelemetry/sampler/operator.rb', line 30 def satisfies?(actual) @evaluate.call actual&.downcase end |