Class: Cejo::Ops::Homey

Inherits:
Object
  • Object
show all
Defined in:
lib/cejo/ops/homey.rb

Overview

Mirror user DATA partition folders to $HOME

Constant Summary collapse

IGNORE_THESE =
%w[.Trash-1000 lost+found].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Homey

Returns a new instance of Homey.



11
12
13
# File 'lib/cejo/ops/homey.rb', line 11

def initialize(root)
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



9
10
11
# File 'lib/cejo/ops/homey.rb', line 9

def root
  @root
end

Returns the value of attribute target_link.



9
10
11
# File 'lib/cejo/ops/homey.rb', line 9

def target_link
  @target_link
end

Instance Method Details

#cleanup_homeObject

Remove $HOME folders found in DATA



35
36
37
38
39
# File 'lib/cejo/ops/homey.rb', line 35

def cleanup_home
  target_link.each_key do |link_name|
    link_name.delete if link_name.exist?
  end
end

#folders_foundObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cejo/ops/homey.rb', line 21

def folders_found
  folders_found = {}
  home = Pathname.new Dir.home

  root.each_child do |folder|
    next if IGNORE_THESE.include? folder.basename.to_s

    folders_found[folder] = home.join folder.basename
  end

  folders_found
end

#root_exist?Boolean

Confirms if root is a folder or return w/ exeception

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/cejo/ops/homey.rb', line 16

def root_exist?
  r = Pathname.new root
  r.exist?
end

#runObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cejo/ops/homey.rb', line 47

def run
  unless root_exist?
    print "No such a directory '#{root}' exist! Exiting."
    exit!
  end

  @root = Pathname root
  @target_link = folders_found

  cleanup_home
  symlink_folders
end


41
42
43
44
45
# File 'lib/cejo/ops/homey.rb', line 41

def symlink_folders
  target_link.each do |target, link_name|
    File.symlink target, link_name
  end
end