class Dotrepo::DotFile

Attributes

destination[R]
path[R]
source[R]

Public Class Methods

new(path, manager) click to toggle source
# File lib/dotrepo/dot_file.rb, line 5
def initialize path, manager
  @path        = path
  @source      = File.join manager.source, path
  @destination = File.join manager.destination, path
end

Public Instance Methods

backup_destination() click to toggle source
# File lib/dotrepo/dot_file.rb, line 19
def backup_destination
  File.rename( destination, "#{destination}.bak" )
end
create_linked_file!() click to toggle source
# File lib/dotrepo/dot_file.rb, line 29
def create_linked_file!
  if source_exists?
    raise "Source file already exists for #{File.basename(source)}"
  end

  FileUtils.mkdir_p File.dirname(source)

  if destination_exists?
    FileUtils.cp destination, source
    backup_destination
  else
    File.open( source, 'wb' ) do |file|
      file.write ""
    end
  end

  symlink_to_destination!
end
destination_exists?() click to toggle source
# File lib/dotrepo/dot_file.rb, line 15
def destination_exists?
  File.exist? destination
end
linked?() click to toggle source
# File lib/dotrepo/dot_file.rb, line 23
def linked?
  destination_exists? &&
    File.symlink?(destination) &&
    File.readlink(destination) == source
end
source_exists?() click to toggle source
# File lib/dotrepo/dot_file.rb, line 11
def source_exists?
  File.exist? source
end