Class: FileLayer
- Inherits:
-
Object
- Object
- FileLayer
- Defined in:
- lib/homer/file_layer.rb
Class Method Summary collapse
- .add_filename_to_dotfiles(dotfile) ⇒ Object
- .create_symlink(filename, file_path) ⇒ Object
- .delete_homer_folder ⇒ Object
- .dotfiles_directory_path ⇒ Object
- .dotfiles_path ⇒ Object
- .get_generic_home_relative_path(filepath) ⇒ Object
- .prepare_homer_folder ⇒ Object
- .read_symlink_file ⇒ Object
- .root_path ⇒ Object
- .save_authorization_token(token) ⇒ Object
- .save_symlink_file(symlinks) ⇒ Object
- .token_path ⇒ Object
Class Method Details
.add_filename_to_dotfiles(dotfile) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/homer/file_layer.rb', line 28 def add_filename_to_dotfiles(dotfile) dotfile = File.(dotfile) f = File.open(dotfiles_path, "a") raise "#{dotfile} does not exist." unless File.exists?(dotfile) f.puts dotfile f.close end |
.create_symlink(filename, file_path) ⇒ Object
47 48 49 50 |
# File 'lib/homer/file_layer.rb', line 47 def create_symlink(filename,file_path) FileUtils.mv(file_path, File.join(dotfiles_directory_path, filename)) File.symlink(File.join(dotfiles_directory_path, filename), file_path) end |
.delete_homer_folder ⇒ Object
24 25 26 |
# File 'lib/homer/file_layer.rb', line 24 def delete_homer_folder FileUtils.rm_rf(File.join(Dir.home, ".homer")) end |
.dotfiles_directory_path ⇒ Object
52 53 54 |
# File 'lib/homer/file_layer.rb', line 52 def dotfiles_directory_path File.join(Dir.home, ".homer", "dotfiles", "/") end |
.dotfiles_path ⇒ Object
56 57 58 |
# File 'lib/homer/file_layer.rb', line 56 def dotfiles_path return File.join(Dir.home, ".homer", "dotfiles", "dotfiles_list") end |
.get_generic_home_relative_path(filepath) ⇒ Object
68 69 70 |
# File 'lib/homer/file_layer.rb', line 68 def get_generic_home_relative_path(filepath) filepath.gsub(/\/home\/[^\/]*\//, "~/") end |
.prepare_homer_folder ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/homer/file_layer.rb', line 16 def prepare_homer_folder Dir.mkdir(File.join(Dir.home, ".homer")) unless Dir.exists?(File.join(Dir.home, ".homer")) Dir.mkdir(File.join(Dir.home, ".homer", "dotfiles")) unless Dir.exists?(File.join(Dir.home, ".homer", "dotfiles")) File.new(dotfiles_path , "w") unless File.exists?(dotfiles_path) rescue Exception => e raise "~/.homer cannot be created : #{e.message}" end |
.read_symlink_file ⇒ Object
36 37 38 39 |
# File 'lib/homer/file_layer.rb', line 36 def read_symlink_file return {} if !File.exists?(dotfiles_path) or File.zero?(dotfiles_path) YAML.load_file(dotfiles_path) end |
.root_path ⇒ Object
60 61 62 |
# File 'lib/homer/file_layer.rb', line 60 def root_path return File.join(Dir.home, ".homer") end |
.save_authorization_token(token) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/homer/file_layer.rb', line 8 def (token) f = File.open(token_path, "a") f.puts token f.close rescue Exception => e raise "GitHub token could not be saved : Error : #{e.message}" end |
.save_symlink_file(symlinks) ⇒ Object
41 42 43 44 45 |
# File 'lib/homer/file_layer.rb', line 41 def save_symlink_file(symlinks) File.open(dotfiles_path,"w") do |out| YAML.dump(symlinks,out) end end |
.token_path ⇒ Object
64 65 66 |
# File 'lib/homer/file_layer.rb', line 64 def token_path File.join(root_path, "token") end |