Class: Rodot::Dotfile
- Inherits:
-
Object
- Object
- Rodot::Dotfile
- Defined in:
- lib/rodot/dotfile.rb
Overview
Dotfile model. Manage source dotfile and dest dotfile.
Constant Summary collapse
- STATUS_ENUM =
{ no_source: "Source doesn't exist.", no_dest: "Dest doesn't exist.", no_both: "Either source & dest exists.", unlinked: "Both source & dest exist, but source doesn't symlink to dest.", linked: "Both source & dest exist, and source symlinked to desc." }.freeze
Instance Attribute Summary collapse
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #dest_exist? ⇒ Boolean
-
#initialize(source, dest) ⇒ Dotfile
constructor
A new instance of Dotfile.
- #linked? ⇒ Boolean
- #source_exist? ⇒ Boolean
- #source_symlink? ⇒ Boolean
- #status ⇒ Object
Constructor Details
#initialize(source, dest) ⇒ Dotfile
Returns a new instance of Dotfile.
16 17 18 19 |
# File 'lib/rodot/dotfile.rb', line 16 def initialize(source, dest) @source = source @dest = dest end |
Instance Attribute Details
#dest ⇒ Object
Returns the value of attribute dest.
6 7 8 |
# File 'lib/rodot/dotfile.rb', line 6 def dest @dest end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/rodot/dotfile.rb', line 5 def source @source end |
Instance Method Details
#dest_exist? ⇒ Boolean
25 26 27 |
# File 'lib/rodot/dotfile.rb', line 25 def dest_exist? File.exist?(@dest) end |
#linked? ⇒ Boolean
33 34 35 36 37 |
# File 'lib/rodot/dotfile.rb', line 33 def linked? false unless source_exist? && dest_exist? false unless source_symlink? File.readlink(source) == @dest end |
#source_exist? ⇒ Boolean
21 22 23 |
# File 'lib/rodot/dotfile.rb', line 21 def source_exist? File.exist?(@source) end |
#source_symlink? ⇒ Boolean
29 30 31 |
# File 'lib/rodot/dotfile.rb', line 29 def source_symlink? File.symlink?(@source) end |
#status ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/rodot/dotfile.rb', line 39 def status source_exists = source_exist? desc_exists = dest_exist? if source_exists && desc_exists end end |