Module: Metrics::Backend::Test::Interface

Defined in:
lib/metrics/backend/test.rb

Instance Method Summary collapse

Instance Method Details

#metric(name, type, description: nil, unit: nil, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/metrics/backend/test.rb', line 32

def metric(name, type, description: nil, unit: nil, &block)
	unless name.is_a?(String)
		raise ArgumentError, "Invalid name (must be String): #{name.inspect}!"
	end
	
	unless name =~ VALID_METRIC_NAME
		raise ArgumentError, "Invalid name (must match #{VALID_METRIC_NAME}): #{name.inspect}!"
	end
	
	unless type.is_a?(Symbol)
		raise ArgumentError, "Invalid type (must be Symbol): #{type.inspect}!"
	end
	
	# Description is optional but must be string if given:
	if description
		unless description.is_a?(String)
			raise ArgumentError, "Invalid description (must be String): #{description.inspect}!"
		end
	end
	
	# Unit is optional but must be string if given:
	if unit
		unless unit.is_a?(String)
			raise ArgumentError, "Invalid unit (must be String): #{unit.inspect}!"
		end
	end
	
	return Metric.new(name, type, description, unit)
end