Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/usage/metric.rb')
-rw-r--r--lib/gitlab/usage/metric.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gitlab/usage/metric.rb b/lib/gitlab/usage/metric.rb
new file mode 100644
index 00000000000..e1648c78168
--- /dev/null
+++ b/lib/gitlab/usage/metric.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Usage
+ class Metric
+ include ActiveModel::Model
+
+ InvalidMetricError = Class.new(RuntimeError)
+
+ attr_accessor :default_generation_path, :value
+
+ validates :default_generation_path, presence: true
+
+ def definition
+ self.class.definitions[default_generation_path]
+ end
+
+ def unflatten_default_path
+ unflatten(default_generation_path.split('.'), value)
+ end
+
+ class << self
+ def definitions
+ @definitions ||= Gitlab::Usage::MetricDefinition.definitions
+ end
+
+ def dictionary
+ definitions.map { |key, definition| definition.to_dictionary }
+ end
+ end
+
+ private
+
+ def unflatten(keys, value)
+ loop do
+ value = { keys.pop.to_sym => value }
+ break if keys.blank?
+ end
+ value
+ end
+ end
+ end
+end