Module: DotfilesInstaller::Actions

Included in:
Runner
Defined in:
lib/dotfiles_installer/actions.rb

Instance Method Summary collapse

Instance Method Details

#create(source_path, home_path) ⇒ Object



24
25
26
27
28
29
# File 'lib/dotfiles_installer/actions.rb', line 24

def create(source_path, home_path)
  self.out("installed #{home_path}")
  [ self.makedir(home_path),
    self.link(source_path =~ /.erb$/ ? generate(source_path) : source_path, home_path)
  ].flatten
end

#generate(source_path) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/dotfiles_installer/actions.rb', line 39

def generate(source_path)
  source_path_dirname = File.dirname(File.expand_path(source_path))
  gen_source_filename = "~#{File.basename(source_path, ".erb")}"
  gen_source_path = File.join(source_path_dirname, gen_source_filename)
  File.open(gen_source_path, 'w') do |gen_source_file|
    gen_source_file.write ERB.new(File.read(File.expand_path(source_path))).result(binding)
  end
  gen_source_path
end


35
36
37
# File 'lib/dotfiles_installer/actions.rb', line 35

def link(source_path, home_path)
  [ %Q{ln -s "#{self.ep(source_path)}" "#{self.ep(home_path)}"} ]
end

#makedir(home_path) ⇒ Object



31
32
33
# File 'lib/dotfiles_installer/actions.rb', line 31

def makedir(home_path)
  [ %Q{mkdir -p "#{self.ep(File.dirname(home_path))}"} ]
end

#remove(home_path) ⇒ Object



9
10
11
12
13
14
# File 'lib/dotfiles_installer/actions.rb', line 9

def remove(home_path)
  self.out("uninstalled #{home_path}")
  [ self.remove_path(home_path),
    self.remove_dir_if_empty(home_path)
  ].flatten
end

#remove_dir_if_empty(home_path) ⇒ Object



20
21
22
# File 'lib/dotfiles_installer/actions.rb', line 20

def remove_dir_if_empty(home_path)
  [ %Q{rmdir -p "#{File.dirname(self.ep(home_path))}" 2> /dev/null} ]
end

#remove_path(path) ⇒ Object



16
17
18
# File 'lib/dotfiles_installer/actions.rb', line 16

def remove_path(path)
  [ %Q{rm -f "#{self.ep(path)}"} ]
end

#replace(home_path, source_path) ⇒ Object



3
4
5
6
7
# File 'lib/dotfiles_installer/actions.rb', line 3

def replace(home_path, source_path)
  [ self.remove_path(home_path),
    self.create(source_path, home_path)
  ].flatten
end