class FileLayer
Public Class Methods
create_symlink(filename,file_path)
click to toggle source
Moves the file to dotfiles directory and creates a symlink at original location
# File lib/homer/file_layer.rb, line 38 def create_symlink(filename,file_path) file_in_dotfiles_folder = File.join(dotfiles_directory_path, filename) FileUtils.mv(file_path, file_in_dotfiles_folder) File.symlink(file_in_dotfiles_folder, file_path) end
delete_homer_folder()
click to toggle source
Deletes the homer root
# File lib/homer/file_layer.rb, line 20 def delete_homer_folder FileUtils.rm_rf(root_path) end
dotfiles_directory_path()
click to toggle source
This is the directory to which the dotfiles will be moved
# File lib/homer/file_layer.rb, line 54 def dotfiles_directory_path return File.join(root_path, "dotfiles/") end
dotfiles_path()
click to toggle source
This is the dotfiles list YML file . This is where a mapping of files in dotfiles folder to actual location in filesystem exists
# File lib/homer/file_layer.rb, line 49 def dotfiles_path return File.join(dotfiles_directory_path, "dotfiles_list.yml") end
get_generic_home_relative_path(filepath)
click to toggle source
# File lib/homer/file_layer.rb, line 63 def get_generic_home_relative_path(filepath) filepath.gsub(/\/home\/[^\/]*\//, "~/") end
prepare_homer_folder()
click to toggle source
Creates the homer root directory if it does not exist already Creates the dotfiles directory if it does not exist already Creates a dotfiles list YML file if it does not exist already
# File lib/homer/file_layer.rb, line 11 def prepare_homer_folder Dir.mkdir(root_path) unless Dir.exists?(root_path) Dir.mkdir(dotfiles_directory_path) unless Dir.exists?(dotfiles_directory_path) File.new(dotfiles_path , "w") unless File.exists?(dotfiles_path) rescue Exception => e raise "~/.homer cannot be created : #{e.message}" end
read_symlink_file()
click to toggle source
Reads and returns the contents of the dotfiles list YML file
# File lib/homer/file_layer.rb, line 25 def read_symlink_file return {} if !File.exists?(dotfiles_path) or File.zero?(dotfiles_path) YAML.load_file(dotfiles_path) end
root_path()
click to toggle source
This is where homer
# File lib/homer/file_layer.rb, line 59 def root_path return File.join(Dir.home, ".homer") end
save_symlink_file(symlinks)
click to toggle source
Writes contents to dotfiles list YML file
# File lib/homer/file_layer.rb, line 31 def save_symlink_file(symlinks) File.open(dotfiles_path,"w") do |out| YAML.dump(symlinks,out) end end