Module: Scales::Config

Defined in:
lib/scales-core/config.rb

Constant Summary collapse

DEFAULTS =
{
  :host           => "localhost",
  :port           => 6379,
  :password       => nil,
  :database       => 0,
  :partials       => false,
  :worker_threads => 30
}
CONFIG_PATHS =
['config/cache.yml', 'cache.yml']
@@pwd =
"."

Class Method Summary collapse

Class Method Details

.configObject



19
20
21
# File 'lib/scales-core/config.rb', line 19

def config
  @@config ||= OpenStruct.new DEFAULTS.merge(load!)
end

.load!Object



27
28
29
30
31
32
33
34
35
# File 'lib/scales-core/config.rb', line 27

def load!
  load_paths = CONFIG_PATHS.map{ |path| File.exists?(File.join(@@pwd, path)) }
  return {} unless load_paths.any?
  
  cache   = File.join(@@pwd, CONFIG_PATHS[load_paths.index(true)])
  config  = YAML.load_file(cache)[Scales.env]
  
  Hash[config.map{|(k,v)| [k.to_sym,v]}]
end

.pwdObject



41
42
43
# File 'lib/scales-core/config.rb', line 41

def pwd
  @@pwd
end

.pwd=(pwd) ⇒ Object



37
38
39
# File 'lib/scales-core/config.rb', line 37

def pwd=(pwd)
  @@pwd = pwd
end

.reset!Object



23
24
25
# File 'lib/scales-core/config.rb', line 23

def reset!
  @@config = nil
end