Class: Boutons::Config
- Inherits:
-
RecursiveOpenStruct
- Object
- RecursiveOpenStruct
- Boutons::Config
- Defined in:
- lib/boutons/config.rb
Class Method Summary collapse
- .config(params = {}) ⇒ Object
-
.defaults ⇒ Object
private.
- .file ⇒ Object
- .method_missing(method, *args, &block) ⇒ Object
- .with_configuration ⇒ Object
- .with_environment ⇒ Object
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 |
.defaults ⇒ Object
private
15 16 17 |
# File 'lib/boutons/config.rb', line 15 def defaults { :registry => { :zookeeper => { :hosts => [ "localhost:2181" ] } } } end |
.file ⇒ Object
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. 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_configuration ⇒ Object
23 24 25 |
# File 'lib/boutons/config.rb', line 23 def with_configuration file ? TOML.load_file(file,symbolize_keys:true) : {} end |
.with_environment ⇒ Object
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 |
#keys ⇒ Object
38 39 40 |
# File 'lib/boutons/config.rb', line 38 def keys @table.keys end |