Class: RuboCop::Cop::StatsD::SingletonConfiguration

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
RuboCop::Cop::StatsD
Defined in:
lib/statsd/instrument/rubocop/singleton_configuration.rb

Overview

This Rubocop will check for calls to StatsD singleton configuration methods (e.g. StatsD.prefix). The library is moving away from having just a single singleton client, so these methods are deprecated.

Use the following Rubocop invocation to check your project's codebase:

rubocop --require `bundle show statsd-instrument`/lib/statsd/instrument/rubocop.rb \
  --only StatsD/SingletonConfiguration

This cop will not autocorrect violations. There are several ways of fixing the violation.

  • The best option is to configure the library using environment variables, like STATSD_ADDR, STATSD_IMPLEMENTATION, STATSD_PREFIX, and STATSD_DEFAULT_TAGS. Metric methods called on the StatsD singleton (e.g. StatsD.increment) will by default be delegated to a client that is configured using these environment variables.
  • Alternatively, you can instantiate your own client using StatsD::Instrument::Client.new, and assign it to StatsD.singleton_client. The client constructor accepts many of the same options.
  • If you have to, you can call the old methods on StatsD.legacy_singleton_client. Note that this option will go away in the next major version.

Constant Summary collapse

MSG =
<<~MESSAGE
  Singleton methods to configure StatsD are deprecated.

  - The best option is to configure the library using environment variables, like
    `STATSD_ADDR`, `STATSD_IMPLEMENTATION`, `STATSD_PREFIX`, and `STATSD_DEFAULT_TAGS`.
    Metric methods called on the StatsD singleton (e.g. `StatsD.increment`) will by default
    be delegated to a client that is configured using these environment variables.
  - Alternatively, you can instantiate your own client using `StatsD::Instrument::Client.new`,
    and assign it to `StatsD.singleton_client`. The client constructor accepts many of the
    same options.
  - If you have to, you can call the old methods on `StatsD.legacy_singleton_client`. Note
    that this option will go away in the next major version.
MESSAGE

Constants included from RuboCop::Cop::StatsD

METAPROGRAMMING_METHODS, METRIC_METHODS, SINGLETON_CONFIGURATION_METHODS

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



45
46
47
48
49
# File 'lib/statsd/instrument/rubocop/singleton_configuration.rb', line 45

def on_send(node)
  if singleton_configuration_method?(node)
    add_offense(node)
  end
end