confparser 0.0.1.1 → 0.0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/confparser.rb +22 -28
- metadata +2 -2
data/lib/confparser.rb
CHANGED
@@ -13,26 +13,31 @@
|
|
13
13
|
autoload :StringIO, 'stringio'
|
14
14
|
|
15
15
|
class ConfParser < Hash
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
16
|
+
module Template
|
17
|
+
def self.included (obj)
|
18
|
+
obj.class_eval {
|
19
|
+
attr_reader :parent
|
20
|
+
alias __get__ []
|
21
|
+
private :__get__
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
(self[$1] || parent[$1]).to_s
|
23
|
+
def [] (name)
|
24
|
+
__get__(name).tap {|x|
|
25
|
+
x.gsub!(/\$\((.+?)\)/) {|n|
|
26
|
+
(self[$1] || parent[$1]).to_s
|
27
|
+
} if x.is_a?(String)
|
30
28
|
}
|
31
29
|
end
|
32
30
|
}
|
33
31
|
end
|
32
|
+
end
|
34
33
|
|
35
|
-
|
34
|
+
class Section < Hash
|
35
|
+
include Template
|
36
|
+
|
37
|
+
def initialize (parent)
|
38
|
+
super()
|
39
|
+
@parent = parent
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
43
|
class << self
|
@@ -54,8 +59,10 @@ class ConfParser < Hash
|
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
62
|
+
include Template
|
63
|
+
|
57
64
|
def initialize (io)
|
58
|
-
section, key, lineno = nil, nil, 0
|
65
|
+
@parent, section, key, lineno = {}, nil, nil, 0
|
59
66
|
|
60
67
|
io.each_line {|line|
|
61
68
|
lineno += 1
|
@@ -89,17 +96,4 @@ class ConfParser < Hash
|
|
89
96
|
}
|
90
97
|
io.close
|
91
98
|
end
|
92
|
-
|
93
|
-
alias __get__ []
|
94
|
-
def [] (name)
|
95
|
-
__get__(name).tap {|x|
|
96
|
-
if x.is_a?(String)
|
97
|
-
x.gsub!(/\$\((.+?)\)/) {|n|
|
98
|
-
(self[$1]).to_s
|
99
|
-
}
|
100
|
-
end
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
private :__get__
|
105
99
|
end
|