confgen 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/confgen +1 -1
- data/lib/confgen.rb +29 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaef0c7a47a59addca740b704eb029d3512d3233
|
4
|
+
data.tar.gz: 83997d440a237152b8dec7ee20fcc241810b0bde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8509affb9f3ddb99ee75db16952ec6706fa31fecd62ff74268bfcbe4accf5ca6573a48ab79535718fcb09c53197d5ee8c406c36a914c84677eaee296d9e46066
|
7
|
+
data.tar.gz: 62d724b4debb8ceb8598d8766a1f859c5f87597be872ac892dbe4d33587762bc6707739b852f256548f08293bacd96bd74fbab70a2aed6016342b315fe041af6
|
data/bin/confgen
CHANGED
data/lib/confgen.rb
CHANGED
@@ -3,10 +3,15 @@ require("highline/import")
|
|
3
3
|
require("yaml")
|
4
4
|
require("erb")
|
5
5
|
require("fileutils")
|
6
|
+
require("pathname")
|
6
7
|
|
7
8
|
class ConfGen
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
8
13
|
def generate()
|
9
|
-
config =
|
14
|
+
config = locate()
|
10
15
|
template = config['template']
|
11
16
|
destination = config['destination']
|
12
17
|
data = gather(config)
|
@@ -17,17 +22,36 @@ class ConfGen
|
|
17
22
|
if (agree("Continue [y/n]?", true))
|
18
23
|
b = binding
|
19
24
|
config["templates"].each() do |template|
|
20
|
-
src = ERB.new(template["src"]).result(b)
|
21
|
-
dst = ERB.new(template["dst"]).result(b)
|
22
|
-
tpl = ERB.new(File.read(src))
|
25
|
+
src = Pathname.new(ERB.new(@confPath.join(template["src"]).to_path()).result(b))
|
26
|
+
dst = Pathname.new(ERB.new(@confPath.join(template["dst"]).to_path()).result(b))
|
27
|
+
tpl = ERB.new(File.read(src.to_path()))
|
23
28
|
|
24
|
-
|
29
|
+
if (!dst.dirname.directory?)
|
30
|
+
FileUtils.mkdir_p(dst.dirname.to_path())
|
31
|
+
end
|
32
|
+
|
33
|
+
File.open(dst.to_path(), 'w') do |f|
|
25
34
|
f.write(tpl.result(b))
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
|
40
|
+
def locate()
|
41
|
+
current = Pathname.new(@path)
|
42
|
+
|
43
|
+
while (!current.root?())
|
44
|
+
[current.join('variables.confgen'), current.join('confgen', 'variables.confgen')].each() do |f|
|
45
|
+
if (f.file?())
|
46
|
+
@confPath = f.dirname
|
47
|
+
return YAML::load(f.open())
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
current = current.dirname
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
31
55
|
def gather(config)
|
32
56
|
data = Hash.new()
|
33
57
|
|