uber_config 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,28 @@
1
1
  UberConfig is a config loader that will load config files from various locations.
2
2
 
3
+ Just run:
4
+
5
+ config = UberConfig.load
6
+
3
7
  Looks for `config.yml` file or name passed in via :file param.
4
8
 
5
- Here is the order:
9
+ Here is the order of where it looks:
6
10
 
7
11
  - $abt_config global variable (for https://github.com/iron-io/abt)
8
- - test directory
9
12
  - directory of file that calls UberConfig.load
10
13
  - working directory
14
+ - TODO: look at ~/configs directory
11
15
  - ~/Dropbox/configs/#{working_directory_name}
12
16
 
13
17
  :dir can be used to change working_directory_name.
14
18
 
19
+ ## Helper methods
20
+
21
+ ### Symbolize Keys
22
+
23
+ When it loads up config files, the hash keys will be strings by default because they are
24
+ strings in the files. You can convert them to keys by running `UberConfig.symbolize_keys!`, for example:
25
+
26
+ config = UberConfig.load
27
+ config = UberConfig.symbolize_keys!(config)
28
+
@@ -60,7 +60,6 @@ module UberConfig
60
60
 
61
61
  puts "auto_dir_name: #{auto_dir_name}"
62
62
 
63
-
64
63
  # Now check in Dropbox
65
64
  dropbox_folders = ["~", "Dropbox", "configs"]
66
65
  if dir
@@ -74,8 +73,7 @@ module UberConfig
74
73
  return @config if @config
75
74
 
76
75
  # couldn't find it
77
- puts "Could not find config file."
78
- return nil
76
+ raise "UberConfig could not find config file!"
79
77
 
80
78
  end
81
79
 
@@ -83,8 +81,29 @@ module UberConfig
83
81
  puts "Checking for config file at #{cf}..."
84
82
  if File.exist?(cf)
85
83
  config = YAML::load_file(cf)
84
+ # the following makes it indifferent access, but doesn't seem to for inner hashes
85
+ #config.default_proc = proc do |h, k|
86
+ # case k
87
+ # when String then sym = k.to_sym; h[sym] if h.key?(sym)
88
+ # when Symbol then str = k.to_s; h[str] if h.key?(str)
89
+ # end
90
+ #end
86
91
  return config
87
92
  end
88
93
  nil
89
94
  end
95
+
96
+ # Destructively convert all keys to symbols, as long as they respond to to_sym.
97
+ # inspired by activesupport
98
+ def self.symbolize_keys!(hash)
99
+ keys = hash.keys
100
+ keys.each do |key|
101
+ v = hash.delete(key)
102
+ if v.is_a?(Hash)
103
+ v = symbolize_keys!(v)
104
+ end
105
+ hash[(key.to_sym rescue key) || key] = v
106
+ end
107
+ hash
108
+ end
90
109
  end
@@ -1,3 +1,3 @@
1
1
  module UberConfig
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
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: 0.0.4
4
+ version: 0.0.5
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-07-13 00:00:00.000000000 Z
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Loads configs from common locations.
15
15
  email: