confgen 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/confgen +1 -1
  3. data/lib/confgen.rb +29 -5
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db38082b0bc9ecfd9f36366df94d5be8cca5bd3
4
- data.tar.gz: 0e5850b4b64be06cb3ef76b0d1e45d82de728a0a
3
+ metadata.gz: aaef0c7a47a59addca740b704eb029d3512d3233
4
+ data.tar.gz: 83997d440a237152b8dec7ee20fcc241810b0bde
5
5
  SHA512:
6
- metadata.gz: fb9feda1eb52a4694f4dbe1f714dcd73ced977526cc0fc5786f1ff06abd16e3069898c27d57a789a371c23e41dce738f192ee05ed18f92502f396fa0a7f94219
7
- data.tar.gz: 92cd637de802a4555af43c482a8383c6cff1d993e6238fefef930f62a9ae684de4bcaa6f5d99cacb9693d8502d419086339a19f642e3211e0f4cf4e4ba0bb03c
6
+ metadata.gz: 8509affb9f3ddb99ee75db16952ec6706fa31fecd62ff74268bfcbe4accf5ca6573a48ab79535718fcb09c53197d5ee8c406c36a914c84677eaee296d9e46066
7
+ data.tar.gz: 62d724b4debb8ceb8598d8766a1f859c5f87597be872ac892dbe4d33587762bc6707739b852f256548f08293bacd96bd74fbab70a2aed6016342b315fe041af6
@@ -2,5 +2,5 @@
2
2
 
3
3
  require("confgen")
4
4
 
5
- g = ConfGen.new()
5
+ g = ConfGen.new(Dir.pwd)
6
6
  g.generate()
@@ -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 = YAML::load(File.open('.confgen'))
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
- File.open(dst, 'w') do |f|
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Angerer