Class: Dottor::Dotfile
- Inherits:
-
Object
- Object
- Dottor::Dotfile
- Defined in:
- lib/dottor/dotfile.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #create_symlink ⇒ Object
- #delete_symlink ⇒ Object
-
#initialize(hash) ⇒ Dotfile
constructor
A new instance of Dotfile.
Constructor Details
#initialize(hash) ⇒ Dotfile
Returns a new instance of Dotfile.
5 6 7 8 |
# File 'lib/dottor/dotfile.rb', line 5 def initialize(hash) @source = hash["source"] @target = hash["target"] end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/dottor/dotfile.rb', line 3 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
3 4 5 |
# File 'lib/dottor/dotfile.rb', line 3 def target @target end |
Instance Method Details
#create_symlink ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dottor/dotfile.rb', line 10 def create_symlink # If file exists rename it to .old # TODO check if .old file already exists if File.exists?(target) old_file_name = "#{target}.old" FileUtils.mv target, old_file_name end # If symlink exists, remove it if File.symlink?(target) FileUtils.rm target end $stdout.puts("Create symlink #{File.join(current_path, source)} -> #{target}") FileUtils.symlink File.join(current_path, source), target end |
#delete_symlink ⇒ Object
27 28 29 30 31 |
# File 'lib/dottor/dotfile.rb', line 27 def delete_symlink if File.symlink?(target) FileUtils.rm target end end |