Sha256: 887f7883a96eb763aafdff4d851bd65d2bfb2d42c7cdb0e5c81e76c44c03d46e

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require_relative '../resolver'

module Datadog
  module Tracing
    module Contrib
      module Configuration
        # Resolves a value to a configuration key
        module Resolvers
          # Matches Strings and Regexps against `object.to_s` objects
          # and Procs against plain objects.
          class PatternResolver < Contrib::Configuration::Resolver
            def resolve(value)
              return if configurations.empty?

              # Try to find a matching pattern
              _, config = configurations.reverse_each.find do |matcher, _|
                matcher === if matcher.is_a?(Proc)
                              value
                            else
                              value.to_s
                            end
              end

              config
            end

            protected

            def parse_matcher(matcher)
              if matcher.is_a?(Regexp) || matcher.is_a?(Proc)
                matcher
              else
                matcher.to_s
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ddtrace-1.10.1 lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb
ddtrace-1.10.0 lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb