Module: PhobosPrometheus::Helper

Defined in:
lib/phobos_prometheus/config_parser.rb

Overview

Helper for operations not dependent on instance state

Class Method Summary collapse

Class Method Details

.assert_array_of_type(metric, key, type) ⇒ Object



136
137
138
139
140
# File 'lib/phobos_prometheus/config_parser.rb', line 136

def self.assert_array_of_type(metric, key, type)
  ary = metric[key.to_s]
  ary.is_a?(Array) && \
    ary.all? { |value| value.is_a? type }
end

.assert_required_key(metric, required) ⇒ Object



132
133
134
# File 'lib/phobos_prometheus/config_parser.rb', line 132

def self.assert_required_key(metric, required)
  metric.keys.any? { |key| key.to_sym == required }
end

.check_invalid_keys(keys, metric) ⇒ Object



146
147
148
# File 'lib/phobos_prometheus/config_parser.rb', line 146

def self.check_invalid_keys(keys, metric)
  metric.keys.all? { |key| keys.include?(key.to_sym) }
end

.fail_config(message) ⇒ Object



142
143
144
# File 'lib/phobos_prometheus/config_parser.rb', line 142

def self.fail_config(message)
  raise(InvalidConfigurationError, message)
end

.read_config(path) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/phobos_prometheus/config_parser.rb', line 122

def self.read_config(path)
  Phobos::DeepStruct.new(
    YAML.safe_load(
      ERB.new(
        File.read(File.expand_path(path))
      ).result
    )
  )
end