Class: Dots::DotFile

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, FileUtils
Defined in:
lib/ruby/dots/dot_file.rb

Constant Summary collapse

DOTS_HOME =
File.expand_path "~/.dots"
USER_HOME =
File.expand_path "~/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.expand_path with_file_name
  @file_name = File.basename(with_file_name)[1..-1]
  @tracked_path = "#{DOTS_HOME}/config/#{@file_name}"
end

Instance Attribute Details

#tracked_pathObject (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

#destroyObject

“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

#saveObject

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

Returns:

  • (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_sObject



20
21
22
# File 'lib/ruby/dots/dot_file.rb', line 20

def to_s
  @untracked_path
end