uber_config 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -106,4 +106,28 @@ module UberConfig
106
106
  end
107
107
  hash
108
108
  end
109
+
110
+ # Non destructive, returns new hash.
111
+ def self.symbolize_keys(hash)
112
+ keys = hash.keys
113
+ ret = {}
114
+ keys.each do |key|
115
+ v = hash[key]
116
+ if v.is_a?(Hash)
117
+ v = symbolize_keys(v)
118
+ end
119
+ ret[(key.to_sym rescue key) || key] = v
120
+ end
121
+ ret
122
+ end
123
+
124
+ def self.make_indifferent(hash)
125
+ hash.default_proc = proc do |h, k|
126
+ case k
127
+ when String then sym = k.to_sym; h[sym] if h.key?(sym)
128
+ when Symbol then str = k.to_s; h[str] if h.key?(str)
129
+ end
130
+ end
131
+ end
132
+
109
133
  end
@@ -1,3 +1,3 @@
1
1
  module UberConfig
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -9,4 +9,10 @@ class TestUberConfig < Test::Unit::TestCase
9
9
  p @config
10
10
  end
11
11
 
12
+ def test_symbolize
13
+ x = {"hello"=>"there", :hi=>"yo"}
14
+ UberConfig.symbolize_keys!(x)
15
+ p x
16
+ end
17
+
12
18
  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.5
4
+ version: 0.0.6
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-19 00:00:00.000000000 Z
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Loads configs from common locations.
15
15
  email: