Class: Datadog::Tracing::Contrib::StatusRangeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/contrib/status_range_matcher.rb

Overview

Useful checking whether the defined range covers status code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ranges) ⇒ StatusRangeMatcher

Returns a new instance of StatusRangeMatcher.



10
11
12
13
# File 'lib/datadog/tracing/contrib/status_range_matcher.rb', line 10

def initialize(ranges)
  # Steep: https://github.com/ruby/rbs/issues/1874
  @ranges = Array(ranges) # steep:ignore IncompatibleAssignment
end

Instance Attribute Details

#ranges ⇒ Object (readonly)

Returns the value of attribute ranges.



8
9
10
# File 'lib/datadog/tracing/contrib/status_range_matcher.rb', line 8

def ranges
  @ranges
end

Instance Method Details

#+(other) ⇒ Object Also known as: concat



15
16
17
# File 'lib/datadog/tracing/contrib/status_range_matcher.rb', line 15

def +(other)
  StatusRangeMatcher.new(@ranges + other.ranges)
end

#include?(status) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
# File 'lib/datadog/tracing/contrib/status_range_matcher.rb', line 20

def include?(status)
  @ranges.any? do |e|
    case e
    when Range
      e.include? status
    when Integer
      e == status
    end
  end
end

#to_s ⇒ Object



31
32
33
# File 'lib/datadog/tracing/contrib/status_range_matcher.rb', line 31

def to_s
  @ranges.map { |range| range.is_a?(Range) ? "#{range.begin}-#{range.end}" : range.to_s }.join(",")
end