Class: Rodot::Dotfile

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#destObject

Returns the value of attribute dest.



6
7
8
# File 'lib/rodot/dotfile.rb', line 6

def dest
  @dest
end

#sourceObject

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/rodot/dotfile.rb', line 25

def dest_exist?
  File.exist?(@dest)
end

#linked?Boolean

Returns:

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

Returns:

  • (Boolean)


21
22
23
# File 'lib/rodot/dotfile.rb', line 21

def source_exist?
  File.exist?(@source)
end

#source_symlink?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rodot/dotfile.rb', line 29

def source_symlink?
  File.symlink?(@source)
end

#statusObject



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