apache_config 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/apache_config.rb +8 -0
- data/test/apache_config_test.rb +8 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/apache_config.rb
CHANGED
@@ -11,6 +11,8 @@ module Apache
|
|
11
11
|
SectionOpen = /^\s*<\s*(\w+)(?:\s+([^>]+)|\s*)>$/
|
12
12
|
SectionClose = /^\s*<\/\s*(\w+)\s*>$/
|
13
13
|
|
14
|
+
attr_reader :path
|
15
|
+
|
14
16
|
def initialize(path)
|
15
17
|
@path = path
|
16
18
|
@config = parse_config(path)
|
@@ -20,6 +22,12 @@ module Apache
|
|
20
22
|
@config.children.map { |vh| VirtualHost.new(vh) }
|
21
23
|
end
|
22
24
|
|
25
|
+
def save!
|
26
|
+
File.open(@path, 'w') do |f|
|
27
|
+
f.write to_config
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
23
31
|
def to_config(root = nil, indent = "")
|
24
32
|
element = root || @config
|
25
33
|
content = ""
|
data/test/apache_config_test.rb
CHANGED
@@ -42,4 +42,12 @@ APACHE
|
|
42
42
|
|
43
43
|
assert_match "ServerAlias www.example.com foo.be", config.to_config
|
44
44
|
end
|
45
|
+
|
46
|
+
def test_saving
|
47
|
+
config = Apache::Config.new('/etc/apache2/example.conf')
|
48
|
+
config.virtual_hosts.first.aliases << 'foo.be'
|
49
|
+
config.save!
|
50
|
+
|
51
|
+
assert_match "ServerAlias www.example.com foo.be", File.read('/etc/apache2/example.conf')
|
52
|
+
end
|
45
53
|
end
|