confile 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/confile.rb +25 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a3405a8d91708ec16cf4513738333082e1f8a15
4
- data.tar.gz: 334ef0877daad0c3dc5223f6f5cbbaa907fbd892
3
+ metadata.gz: d3475fd96731bf8b42f8b4dc4a68d91f35a3b074
4
+ data.tar.gz: 5dd17e020f35e28a6eb609e67d4362370e610f9c
5
5
  SHA512:
6
- metadata.gz: 35090d1d6832daa75d1c58049e6e265ad5c8c485b0fb5cf5ce195012fbcb8067de3977ed9882453b2a4249058981bba0b9a890d09e846a2894bed63c937096b8
7
- data.tar.gz: 6161e967198d3e9b5eda84ad2da249966e33d68e7873e3d267d8d911a290871b9cbce4a93bafe00ef948bb55d2a0c392851c81ac2aa83b51b2fb7084bdef8049
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
- conf = YAML.load_file(config_file)
6
+ if (File.exist?(config_file))
7
+ @confile_exists = true
7
8
 
8
- @config_dir = conf['config_dir'] || 'config'
9
- @links = {}
10
- @files = []
9
+ conf = YAML.load_file(config_file)
11
10
 
12
- conf['links'].each do |link|
13
- link.each_pair do |from, to|
14
- @links[File.join(@config_dir, from)] = to
15
- @files.push(to)
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... #{from} -> #{to}"
36
+ puts "linking... #{to} -> #{from}"
24
37
  FileUtils.ln_s(from, to)
25
38
  else
26
- puts "skipping... #{from} -> #{to}"
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cade Scroggins