Class: FileLayer

Inherits:
Object
  • Object
show all
Defined in:
lib/homer/file_layer.rb

Class Method Summary collapse

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.expand_path(dotfile)
  f = File.open(dotfiles_path, "a")
  raise "#{dotfile} does not exist." unless File.exists?(dotfile)
  f.puts dotfile
  f.close
end


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_folderObject



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_pathObject



52
53
54
# File 'lib/homer/file_layer.rb', line 52

def dotfiles_directory_path
  File.join(Dir.home, ".homer", "dotfiles", "/")
end

.dotfiles_pathObject



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_folderObject



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


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_pathObject



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 save_authorization_token(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


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_pathObject



64
65
66
# File 'lib/homer/file_layer.rb', line 64

def token_path
  File.join(root_path, "token")
end