Class: Datadog::Contrib::Configuration::Resolver
- Inherits:
-
Object
- Object
- Datadog::Contrib::Configuration::Resolver
- Defined in:
- lib/ddtrace/contrib/configuration/resolver.rb
Overview
Resolves an integration-specific matcher to an associated object.
Integrations that perform any configuration matching based on patterns might want to override this class to provide richer matching. For example, match configuration based on: HTTP request parameters, request headers, async queue name.
When overriding this class, for simple use cases, only
overriding #parse_matcher
might suffice. See
#parse_matcher
's documentation for more information.
Direct Known Subclasses
ActiveRecord::Configuration::Resolver, Datadog::Contrib::Configuration::Resolvers::PatternResolver, Redis::Configuration::Resolver
Instance Attribute Summary collapse
-
#configurations ⇒ Object
readonly
Returns the value of attribute configurations.
Instance Method Summary collapse
-
#add(matcher, value) ⇒ Object
Adds a new
matcher
, associating with it avalue
. -
#get(matcher) ⇒ Object
Retrieves the stored value for a
matcher
previously stored by#add
. -
#initialize ⇒ Resolver
constructor
A new instance of Resolver.
-
#resolve(value) ⇒ Object
Matches an arbitrary value against the configured matchers previously set with
#add
.
Constructor Details
#initialize ⇒ Resolver
Returns a new instance of Resolver.
20 21 22 |
# File 'lib/ddtrace/contrib/configuration/resolver.rb', line 20 def initialize @configurations = {} end |
Instance Attribute Details
#configurations ⇒ Object (readonly)
Returns the value of attribute configurations.
18 19 20 |
# File 'lib/ddtrace/contrib/configuration/resolver.rb', line 18 def configurations @configurations end |
Instance Method Details
#add(matcher, value) ⇒ Object
Adds a new matcher
, associating with it a value
.
This value
is returned when #resolve
is called
with a matching value for this matcher. When multiple
matchers would match, #resolve
returns the latest
added one.
The matcher
can be transformed internally by the
#parse_matcher
method before being stored.
The value
can also be retrieved by calling #get
with the same matcher
added by this method.
39 40 41 |
# File 'lib/ddtrace/contrib/configuration/resolver.rb', line 39 def add(matcher, value) @configurations[parse_matcher(matcher)] = value end |
#get(matcher) ⇒ Object
Retrieves the stored value for a matcher
previously stored by #add
.
48 49 50 |
# File 'lib/ddtrace/contrib/configuration/resolver.rb', line 48 def get(matcher) @configurations[parse_matcher(matcher)] end |
#resolve(value) ⇒ Object
Matches an arbitrary value against the configured
matchers previously set with #add
.
If multiple matchers would match, returns the latest one.
59 60 61 |
# File 'lib/ddtrace/contrib/configuration/resolver.rb', line 59 def resolve(value) @configurations[value] end |