debian-mirror-gitlab/app/models/performance_monitoring/prometheus_panel_group.rb

37 lines
923 B
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module PerformanceMonitoring
class PrometheusPanelGroup
include ActiveModel::Model
attr_accessor :group, :priority, :panels
validates :group, presence: true
2020-07-28 23:09:34 +05:30
validates :panels, array_members: { member_class: PerformanceMonitoring::PrometheusPanel }
2020-06-23 00:09:42 +05:30
class << self
def from_json(json_content)
build_from_hash(json_content).tap(&:validate!)
end
2020-03-13 15:44:24 +05:30
2020-06-23 00:09:42 +05:30
private
2020-03-13 15:44:24 +05:30
2020-06-23 00:09:42 +05:30
def build_from_hash(attributes)
return new unless attributes.is_a?(Hash)
new(
group: attributes['group'],
priority: attributes['priority'],
2020-07-28 23:09:34 +05:30
panels: initialize_children_collection(attributes['panels'])
2020-06-23 00:09:42 +05:30
)
end
2020-07-28 23:09:34 +05:30
def initialize_children_collection(children)
return unless children.is_a?(Array)
children.map { |panels| PerformanceMonitoring::PrometheusPanel.from_json(panels) }
end
2020-03-13 15:44:24 +05:30
end
end
end