dotcfg 0.1.0.2 → 0.2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dotcfg.rb +4 -16
- metadata +1 -1
data/lib/dotcfg.rb
CHANGED
@@ -16,17 +16,6 @@ require 'yaml'
|
|
16
16
|
# => nil
|
17
17
|
#
|
18
18
|
class DotCfg
|
19
|
-
def self.normalize key
|
20
|
-
case key
|
21
|
-
when Numeric
|
22
|
-
key.to_s
|
23
|
-
when String, Symbol
|
24
|
-
key.to_s.downcase.gsub(/[\W_]+/, '_').gsub(/_\z/, '')
|
25
|
-
else
|
26
|
-
raise "invalid key: #{key} (#{key.class})"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
19
|
PROCS = {
|
31
20
|
json: {
|
32
21
|
to: proc { |data| data.to_json },
|
@@ -42,7 +31,7 @@ class DotCfg
|
|
42
31
|
|
43
32
|
attr_reader :filename, :format
|
44
33
|
|
45
|
-
def initialize filename, format = :
|
34
|
+
def initialize filename, format = :yaml
|
46
35
|
@filename = File.expand_path filename
|
47
36
|
@format = format
|
48
37
|
@cfg = Hash.new
|
@@ -54,16 +43,15 @@ class DotCfg
|
|
54
43
|
#
|
55
44
|
|
56
45
|
def [] key
|
57
|
-
key
|
58
|
-
@cfg[key] or @cfg[key.to_s]
|
46
|
+
@cfg[key]
|
59
47
|
end
|
60
48
|
|
61
49
|
def []= key, value
|
62
|
-
@cfg[
|
50
|
+
@cfg[key] = value
|
63
51
|
end
|
64
52
|
|
65
53
|
def delete key
|
66
|
-
@cfg.delete
|
54
|
+
@cfg.delete key
|
67
55
|
end
|
68
56
|
|
69
57
|
# if you need to call this, you might be Doing It Wrong (tm)
|