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

Public: Translate a relative target path to an absolute one

Examples

dotfile = Dottor::Dotfile.new "source" => "blah", "target" => ".gitconfig"
dotfile.target
# => '/Users/stevejobs/.gitconfig'

Returns the absolute path for the given relative string. If the string is already absolute, return unmodified.



20
21
22
# File 'lib/dottor/dotfile.rb', line 20

def target
  @target
end

Instance Method Details



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dottor/dotfile.rb', line 24

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

  # If symlink exists, remove it
  if File.exists?(target) || 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


40
41
42
43
44
# File 'lib/dottor/dotfile.rb', line 40

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