Module: Barometer::Utils::ConfigReader

Defined in:
lib/barometer/utils/config_reader.rb

Class Method Summary collapse

Class Method Details

._dig(data, config, &block) ⇒ Object

iterate through the setup until we have a source name (and possibly a config for that source), then yield with that source and config

this allows for many different config formats, like { 1 => :wunderground } { 1 => [:wunderground]} { 1 => [:wunderground, :yahoo]} { 1 => [:wunderground, {weight: 2}]} { 1 => {weight: 2}} { 1 => [{weight: 2}]}



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/barometer/utils/config_reader.rb', line 25

def self._dig(data, config, &block)
  if data.respond_to?(:to_sym)
    yield(data.to_sym, config)
  elsif data.is_a?(Array)
    data.each do |datum|
      _dig(datum, {}, &block)
    end
  elsif data.is_a?(Hash)
    data.each do |datum, config|
      _dig(datum, config, &block)
    end
  end
end

.services(level, &block) ⇒ Object



10
11
12
# File 'lib/barometer/utils/config_reader.rb', line 10

def self.services(level, &block)
  _dig(Barometer.config[level], {}, &block)
end

.take_level_while(&block) ⇒ Object



4
5
6
7
8
# File 'lib/barometer/utils/config_reader.rb', line 4

def self.take_level_while(&block)
  Barometer.config.take_while do |level, level_config|
    yield level
  end
end