Class: Metrics::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/metrics/config.rb

Overview

Represents a configuration for the metrics library.

Constant Summary collapse

DEFAULT_PATH =
ENV.fetch("METRICS_CONFIG_DEFAULT_PATH", "config/metrics.rb")
DEFAULT =

Load the default configuration.

self.default

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject

Load the default configuration.



26
27
28
# File 'lib/metrics/config.rb', line 26

def self.default
	@default ||= self.load(DEFAULT_PATH)
end

.load(path) ⇒ Object

Load the configuration from the given path.



14
15
16
17
18
19
20
21
22
# File 'lib/metrics/config.rb', line 14

def self.load(path)
	config = self.new
	
	if File.exist?(path)
		config.instance_eval(File.read(path), path)
	end
	
	return config
end

Instance Method Details

#prepareObject

Prepare the backend, e.g. by loading additional libraries or instrumentation.



31
32
# File 'lib/metrics/config.rb', line 31

def prepare
end

#require_backend(env = ENV) ⇒ Object

Require a specific metrics backend implementation.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/metrics/config.rb', line 35

def require_backend(env = ENV)
	if backend = env["METRICS_BACKEND"]
		begin
			if require(backend)
				Metrics.singleton_class.prepend(Backend::Interface)
				
				return true
			end
		rescue LoadError => error
			warn "Unable to load metrics backend: #{backend.inspect}!"
		end
	end
	
	return false
end