uber_config 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/uber_config.rb CHANGED
@@ -1,8 +1,21 @@
1
1
  require 'yaml'
2
+ require 'logger'
2
3
  require "uber_config/version"
3
4
 
4
5
  module UberConfig
5
6
 
7
+ @@logger = Logger.new(STDOUT)
8
+ @@logger.level = Logger::INFO
9
+
10
+ def self.logger
11
+ @@logger
12
+ end
13
+
14
+ def self.logger=(l)
15
+ @@logger = l
16
+ end
17
+
18
+
6
19
  # Load a config file from various system locations
7
20
  # Options:
8
21
  # :file => filename, default is 'config' which means it will look for both config.yml and config.json. You can use the full filename like 'config.json'
@@ -12,11 +25,22 @@ module UberConfig
12
25
 
13
26
  # First check for abt config: https://github.com/iron-io/abt
14
27
  if defined? $abt_config
15
- puts "$abt_config found."
28
+ logger.info "$abt_config found."
16
29
  @config = $abt_config
17
30
  return @config
18
31
  end
19
32
 
33
+ if ENV['CONFIG_CACHE_KEY']
34
+ logger.info "ENV[CONFIG_CACHE_KEY] found."
35
+ logger.debug "Getting config from #{ENV['CONFIG_CACHE_KEY']}"
36
+ config_from_cache = open(ENV['CONFIG_CACHE_KEY']).read
37
+ config_from_cache = JSON.parse(config_from_cache)
38
+ config_from_cache = YAML.load(config_from_cache['value'])
39
+ logger.info "Got config from cache."
40
+ set_default_proc(config_from_cache)
41
+ return config_from_cache
42
+ end
43
+
20
44
  dir = nil
21
45
  if options[:dir]
22
46
  dir = options[:dir]
@@ -93,7 +117,7 @@ module UberConfig
93
117
  end
94
118
 
95
119
  def self.load_from(cf)
96
- puts "Checking for config file at #{cf}..."
120
+ logger.info "Checking for config file at #{cf}..."
97
121
  if File.exist?(cf)
98
122
  config = YAML::load_file(cf)
99
123
  # the following makes it indifferent access, but doesn't seem to for inner hashes
@@ -1,3 +1,3 @@
1
1
  module UberConfig
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uber_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-25 00:00:00.000000000 Z
12
+ date: 2012-09-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Loads configs from common locations.
15
15
  email: