Class: Dottor::Dotfile

Inherits:
Object
  • Object
show all
Defined in:
lib/dottor/dotfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Dotfile

Returns a new instance of Dotfile.



5
6
7
8
# File 'lib/dottor/dotfile.rb', line 5

def initialize(hash)
  @source = hash["source"]
  @target = hash["target"]
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/dottor/dotfile.rb', line 3

def source
  @source
end

#targetObject

Returns the value of attribute target.



3
4
5
# File 'lib/dottor/dotfile.rb', line 3

def target
  @target
end

Instance Method Details



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dottor/dotfile.rb', line 10

def create_symlink
  # If file exists rename it to .old
  # TODO check if .old file already exists
  if File.exists?(target)
    old_file_name = "#{target}.old"
    FileUtils.mv target, old_file_name
  end

  # If symlink exists, remove it
  if File.symlink?(target)
    FileUtils.rm target
  end

  $stdout.puts("Create symlink #{File.join(current_path, source)} -> #{target}")
  FileUtils.symlink File.join(current_path, source), target
end


27
28
29
30
31
# File 'lib/dottor/dotfile.rb', line 27

def delete_symlink
  if File.symlink?(target)
    FileUtils.rm target
  end
end