Class: FileLayer
- Inherits:
-
Object
- Object
- FileLayer
- Defined in:
- lib/homer/file_layer.rb
Class Method Summary collapse
-
.create_symlink(filename, file_path) ⇒ Object
Moves the file to dotfiles directory and creates a symlink at original location.
-
.delete_homer_folder ⇒ Object
Deletes the homer root.
-
.dotfiles_directory_path ⇒ Object
This is the directory to which the dotfiles will be moved.
-
.dotfiles_path ⇒ Object
This is the dotfiles list YML file .
- .get_generic_home_relative_path(filepath) ⇒ Object
-
.prepare_homer_folder ⇒ Object
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.
-
.read_symlink_file ⇒ Object
Reads and returns the contents of the dotfiles list YML file.
-
.root_path ⇒ Object
This is where homer.
-
.save_symlink_file(symlinks) ⇒ Object
Writes contents to dotfiles list YML file.
Class Method Details
.create_symlink(filename, file_path) ⇒ Object
Moves the file to dotfiles directory and creates a symlink at original location
38 39 40 41 42 |
# 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 ⇒ Object
Deletes the homer root
20 21 22 |
# File 'lib/homer/file_layer.rb', line 20 def delete_homer_folder FileUtils.rm_rf(root_path) end |
.dotfiles_directory_path ⇒ Object
This is the directory to which the dotfiles will be moved
54 55 56 |
# File 'lib/homer/file_layer.rb', line 54 def dotfiles_directory_path return File.join(root_path, "dotfiles/") end |
.dotfiles_path ⇒ Object
This is the dotfiles list YML file . This is where a mapping of files in dotfiles folder to actual location in filesystem exists
49 50 51 |
# 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) ⇒ Object
63 64 65 |
# File 'lib/homer/file_layer.rb', line 63 def get_generic_home_relative_path(filepath) filepath.gsub(/\/home\/[^\/]*\//, "~/") end |
.prepare_homer_folder ⇒ Object
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
11 12 13 14 15 16 17 |
# 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.}" end |
.read_symlink_file ⇒ Object
Reads and returns the contents of the dotfiles list YML file
25 26 27 28 |
# 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 ⇒ Object
This is where homer
59 60 61 |
# File 'lib/homer/file_layer.rb', line 59 def root_path return File.join(Dir.home, ".homer") end |
.save_symlink_file(symlinks) ⇒ Object
Writes contents to dotfiles list YML file
31 32 33 34 35 |
# 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 |