Class: Dots::DotFile
- Inherits:
-
Object
- Object
- Dots::DotFile
- Includes:
- ActiveModel::Validations, FileUtils
- Defined in:
- lib/ruby/dots/dot_file.rb
Constant Summary collapse
- DOTS_HOME =
File. "~/.dots"
- USER_HOME =
File. "~/"
Instance Attribute Summary collapse
-
#tracked_path ⇒ Object
readonly
Returns the value of attribute tracked_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#destroy ⇒ Object
“Forget” the file, remove its symlink and restore its location.
-
#initialize(with_file_name) ⇒ DotFile
constructor
Instantiate the file and make sure it exists.
-
#save ⇒ Object
Persist the file in the ~/.dots repository, and symlink to its old path.
- #saved? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(with_file_name) ⇒ DotFile
Instantiate the file and make sure it exists.
14 15 16 17 18 |
# File 'lib/ruby/dots/dot_file.rb', line 14 def initialize with_file_name @untracked_path = File. with_file_name @file_name = File.basename(with_file_name)[1..-1] @tracked_path = "#{DOTS_HOME}/config/#{@file_name}" end |
Instance Attribute Details
#tracked_path ⇒ Object (readonly)
Returns the value of attribute tracked_path.
11 12 13 |
# File 'lib/ruby/dots/dot_file.rb', line 11 def tracked_path @tracked_path end |
Class Method Details
.find(by_file_name) ⇒ Object
24 25 26 |
# File 'lib/ruby/dots/dot_file.rb', line 24 def self.find by_file_name new by_file_name end |
Instance Method Details
#destroy ⇒ Object
“Forget” the file, remove its symlink and restore its location.
43 44 45 |
# File 'lib/ruby/dots/dot_file.rb', line 43 def destroy delete_symlink and restore_to_original_path end |
#save ⇒ Object
Persist the file in the ~/.dots repository, and symlink to its old path.
30 31 32 33 34 35 36 |
# File 'lib/ruby/dots/dot_file.rb', line 30 def save if valid? move_to_dots and symlink_old_path else false end end |
#saved? ⇒ Boolean
38 39 40 |
# File 'lib/ruby/dots/dot_file.rb', line 38 def saved? File.exists? @tracked_path and File.exists? @untracked_path end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/ruby/dots/dot_file.rb', line 20 def to_s @untracked_path end |