blob: d67b1809d93b5f15718b31f6d6da4ec72ee7d584 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# frozen_string_literal: true
module PerformanceMonitoring
class PrometheusMetric
include ActiveModel::Model
attr_accessor :id, :unit, :label, :query, :query_range
validates :unit, presence: true
validates :query, presence: true, unless: :query_range
validates :query_range, presence: true, unless: :query
class << self
def from_json(json_content)
build_from_hash(json_content).tap(&:validate!)
end
private
def build_from_hash(attributes)
return new unless attributes.is_a?(Hash)
new(
id: attributes['id'],
unit: attributes['unit'],
label: attributes['label'],
query: attributes['query'],
query_range: attributes['query_range']
)
end
end
end
end
|