Module: Kstats::Node::Config

Defined in:
lib/kstats/node/config.rb

Class Method Summary collapse

Class Method Details

.[](key, default = nil) ⇒ Object



9
10
11
12
13
# File 'lib/kstats/node/config.rb', line 9

def self.[] key, default = nil
  path = key.to_s.split(/\./)

  explore_path(path) || default
end

.explore_path(path, current = nil, idx = 0) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kstats/node/config.rb', line 17

def self.explore_path path, current = nil, idx=0
  if idx == 0 && current.nil?
    current = @config
  end

  if current.nil?
    nil
  else
    if idx == path.count-1
      if current.instance_of?(Hash)
        current[path[idx]]
      else
        nil
      end
    else
      explore_path path, current[path[idx]], idx+1
    end
  end
end

.init(config_file) ⇒ Object



4
5
6
7
# File 'lib/kstats/node/config.rb', line 4

def self.init config_file
  @config ||= {}
  @config.merge!(config_file)
end