confile 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/confile.rb +25 -10
- 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: d3475fd96731bf8b42f8b4dc4a68d91f35a3b074
|
4
|
+
data.tar.gz: 5dd17e020f35e28a6eb609e67d4362370e610f9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f7f586dfccb35cafddc5f305d140611b97182050c7b444fd14371de842c2443b74fb94bbe40498af60df33e1430c8d1a2513a319eed0a021d7a4b3201a8f4d6
|
7
|
+
data.tar.gz: 99ffa987eb478d3e608bf0bc5d7c1fda7df4dcb7b01a023a91a6bd33f5ec5ad7566b85abe03441c1f06c016174a792839c9220da2358468c5f628bb46f2dc701
|
data/lib/confile.rb
CHANGED
@@ -3,32 +3,47 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
class Confile
|
5
5
|
def initialize(config_file)
|
6
|
-
|
6
|
+
if (File.exist?(config_file))
|
7
|
+
@confile_exists = true
|
7
8
|
|
8
|
-
|
9
|
-
@links = {}
|
10
|
-
@files = []
|
9
|
+
conf = YAML.load_file(config_file)
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
@config_dir = conf['config_dir'] || 'config'
|
12
|
+
@links = {}
|
13
|
+
@files = []
|
14
|
+
|
15
|
+
conf['links'].each do |link|
|
16
|
+
link.each_pair do |from, to|
|
17
|
+
@links[File.join(@config_dir, from)] = to
|
18
|
+
@files.push(to)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
24
|
+
def check_confile
|
25
|
+
if (!@confile_exists)
|
26
|
+
puts "nothing to link! please create a Confile."
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
20
31
|
def link
|
32
|
+
self.check_confile
|
33
|
+
|
21
34
|
@links.each_pair do |from, to|
|
22
35
|
if File.exist?(from) && !File.exist?(to)
|
23
|
-
puts "linking... #{
|
36
|
+
puts "linking... #{to} -> #{from}"
|
24
37
|
FileUtils.ln_s(from, to)
|
25
38
|
else
|
26
|
-
puts "skipping... #{
|
39
|
+
puts "skipping... #{to} -> #{from}"
|
27
40
|
end
|
28
41
|
end
|
29
42
|
end
|
30
43
|
|
31
44
|
def unlink
|
45
|
+
self.check_confile
|
46
|
+
|
32
47
|
@files.each do |file|
|
33
48
|
puts "unlinking... #{file}"
|
34
49
|
FileUtils.rm(file)
|