Class: Dotfile
- Inherits:
-
Object
- Object
- Dotfile
- Defined in:
- lib/polka/dotfile.rb
Class Method Summary collapse
Instance Method Summary collapse
- #backup ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(path, home_path) ⇒ Dotfile
constructor
A new instance of Dotfile.
- #setup(operation) ⇒ Object
Constructor Details
#initialize(path, home_path) ⇒ Dotfile
Returns a new instance of Dotfile.
4 5 6 7 8 |
# File 'lib/polka/dotfile.rb', line 4 def initialize(path, home_path) raise FileNotPresentError, "Could not find file at #{path}." unless File.exists?(path) @path = path @home_path = home_path end |
Class Method Details
.backup_dir(home_path) ⇒ Object
30 31 32 33 |
# File 'lib/polka/dotfile.rb', line 30 def self.backup_dir(home_path) dir = File.join(".polka_backup", Time.now.strftime("%F_%T")) @@backup_dir ||= File.join(home_path, dir) end |
Instance Method Details
#backup ⇒ Object
16 17 18 19 20 |
# File 'lib/polka/dotfile.rb', line 16 def backup Polka.log " Backing up: ".light_yellow + "#{@home_path} => #{backup_dir}" FileUtils.mkdir_p(backup_dir) unless File.exists?(backup_dir) FileUtils.mv(@home_path, backup_dir) end |
#eql?(other) ⇒ Boolean
26 27 28 |
# File 'lib/polka/dotfile.rb', line 26 def eql?(other) hash == other.hash end |
#hash ⇒ Object
22 23 24 |
# File 'lib/polka/dotfile.rb', line 22 def hash @path.hash end |