Module: Datadog::Contrib::Configurable::InstanceMethods

Defined in:
lib/ddtrace/contrib/configurable.rb

Overview

Configurable instance behavior for integrations

Instance Method Summary collapse

Instance Method Details

#configuration(matcher = :default) ⇒ Object

Get matching configuration by matcher. If no match, returns the default configuration instance.



40
41
42
43
44
# File 'lib/ddtrace/contrib/configurable.rb', line 40

def configuration(matcher = :default)
  return default_configuration_instance if matcher == :default

  resolver.get(matcher) || default_configuration_instance
end

#configurationsObject

Returns all registered matchers and their respective configurations.



55
56
57
# File 'lib/ddtrace/contrib/configurable.rb', line 55

def configurations
  resolver.configurations.merge(default: default_configuration_instance)
end

#configure(matcher = :default, options = {}, &block) ⇒ Object

Create or update configuration associated with matcher with the provided options and &block.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ddtrace/contrib/configurable.rb', line 61

def configure(matcher = :default, options = {}, &block)
  config = if matcher == :default
             default_configuration_instance
           else
             # Get or add the configuration
             resolver.get(matcher) || resolver.add(matcher, default_configuration)
           end

  # Apply the settings
  config.configure(options, &block)
  config
end

#default_configurationObject

Provides a new configuration instance for this integration.

This method normally needs to be overridden for each integration as their settings, defaults and environment variables are specific for each integration.

DEV(1.0): Rename to new_configuration, make it protected. DEV(1.0): DEV(1.0): This method always provides a new instance of the configuration object for DEV(1.0): the current integration, not the currently effective default configuration. DEV(1.0): This is a misnomer of its function. DEV(1.0): DEV(1.0): Unfortunately, change this would be a breaking change for all custom integrations, DEV(1.0): thus we have to be very intentional with the right time to make this change. DEV(1.0): Currently marking this for a 1.0 milestone.



34
35
36
# File 'lib/ddtrace/contrib/configurable.rb', line 34

def default_configuration
  Configuration::Settings.new
end

#reset_configuration!Object

Resets all configuration options



75
76
77
78
# File 'lib/ddtrace/contrib/configurable.rb', line 75

def reset_configuration!
  @resolver = nil
  @default_configuration = nil
end

#resolve(value) ⇒ Object

Resolves the matching configuration for integration-specific value. If no match, returns the default configuration instance.



48
49
50
51
52
# File 'lib/ddtrace/contrib/configurable.rb', line 48

def resolve(value)
  return default_configuration_instance if value == :default

  resolver.resolve(value) || default_configuration_instance
end