Class: Lookout::Statsd

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout/statsd.rb

Class Method Summary collapse

Class Method Details

.clear_instanceObject

Clear singleton instance, for use in testing ONLY



22
23
24
# File 'lib/lookout/statsd.rb', line 22

def self.clear_instance
  @@instance = nil
end

.create_instance(opts = {}) ⇒ Object

initialize singleton instance to be an instance of Lookout::StatsdClient, with the given options



9
10
11
12
# File 'lib/lookout/statsd.rb', line 9

def self.create_instance(opts={})
  raise "Already initialized Statsd" if instance_set?
  @@instance ||= StatsdClient.new(opts)
end

.instanceObject

Access singleton instance, which must have been initialized with .create_instance or .set_instance



33
34
35
36
# File 'lib/lookout/statsd.rb', line 33

def self.instance
  raise "Statsd has not been initialized" unless instance_set?
  @@instance
end

.instance_set?Boolean

Check if the instance has been set

Returns:

  • (Boolean)


27
28
29
# File 'lib/lookout/statsd.rb', line 27

def self.instance_set?
  defined?(@@instance) && !!@@instance
end

.set_instance(instance) ⇒ Object

Explicitly set singleton instance. The instance must follow the same API as Lookout::StatsdClient



16
17
18
19
# File 'lib/lookout/statsd.rb', line 16

def self.set_instance(instance)
  raise "Already initialized Statsd" if instance_set?
  @@instance = instance
end