Class: Boutons::Config

Inherits:
RecursiveOpenStruct
  • Object
show all
Defined in:
lib/boutons/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config(params = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/boutons/config.rb', line 26

def config params={}
  unless @config
    params.deep_merge! with_environment
    params.deep_merge! with_configuration
    @config      = self.new params
  end
  @config
end

.defaultsObject

private



15
16
17
# File 'lib/boutons/config.rb', line 15

def defaults
  { :registry => { :zookeeper => { :hosts => [ "localhost:2181" ] } } }
end

.fileObject



8
9
10
11
12
13
# File 'lib/boutons/config.rb', line 8

def file
  %w{. config/ ~/.boutons ~/ /etc/boutons /etc}.product(%w{tml toml}).collect{|x|File.expand_path x.join("/boutons.")}.each do |file|
    return file if File.exists? file
  end
  nil
end

.method_missing(method, *args, &block) ⇒ Object



34
35
36
# File 'lib/boutons/config.rb', line 34

def method_missing method, *args, &block
  config.send(method, *args, &block) rescue nil
end

.with_configurationObject



23
24
25
# File 'lib/boutons/config.rb', line 23

def with_configuration
  file ? TOML.load_file(file,symbolize_keys:true) : {}
end

.with_environmentObject



18
19
20
21
22
# File 'lib/boutons/config.rb', line 18

def with_environment
  environment = defaults
  environment[:registry][:zookeeper][:hosts] = ENV["ZK_HOSTS"].split(",") if ENV["ZK_HOSTS"] 
  environment
end

Instance Method Details

#each(*args, &block) ⇒ Object



41
42
43
# File 'lib/boutons/config.rb', line 41

def each *args, &block
  @table.each(*args,&block)
end

#keysObject



38
39
40
# File 'lib/boutons/config.rb', line 38

def keys
  @table.keys
end