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.
Files changed (2) hide show
  1. data/lib/confparser.rb +22 -28
  2. 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
- class Section < Hash
17
- attr_reader :parent
18
-
19
- def initialize (parent)
20
- super()
21
- @parent = parent
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
- alias __get__ []
25
- def [] (name)
26
- __get__(name).tap {|x|
27
- if x.is_a?(String)
28
- x.gsub!(/\$\((.+?)\)/) {|n|
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
- private :__get__
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
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.0.1.1
9
+ - 2
10
+ version: 0.0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - shura