Class: Confile
- Inherits:
-
Object
- Object
- Confile
- Defined in:
- lib/confile.rb
Instance Method Summary collapse
- #check_confile ⇒ Object
-
#initialize(config_file) ⇒ Confile
constructor
A new instance of Confile.
- #link ⇒ Object
- #unlink ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Confile
Returns a new instance of Confile.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/confile.rb', line 5 def initialize(config_file) if (File.exist?(config_file)) @confile_exists = true conf = YAML.load_file(config_file) @config_dir = conf['config_dir'] || 'config' @links = {} @files = [] conf['links'].each do |link| link.each_pair do |from, to| @links[File.join(@config_dir, from)] = to @files.push(to) end end end end |
Instance Method Details
#check_confile ⇒ Object
24 25 26 27 28 29 |
# File 'lib/confile.rb', line 24 def check_confile if (!@confile_exists) puts "nothing to link! please create a Confile." exit 1 end end |
#link ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/confile.rb', line 31 def link self.check_confile @links.each_pair do |from, to| if File.exist?(from) && !File.exist?(to) puts "linking... #{to} -> #{from}" FileUtils.ln_s(from, to) else puts "skipping... #{to} -> #{from}" end end end |
#unlink ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/confile.rb', line 44 def unlink self.check_confile @files.each do |file| puts "unlinking... #{file}" FileUtils.rm(file) end end |