Class: Cejo::Ops::Dots
- Inherits:
-
Object
- Object
- Cejo::Ops::Dots
- Defined in:
- lib/cejo/ops/dots.rb
Overview
Mirror Lar files in $HOME.
Instance Attribute Summary collapse
-
#home ⇒ Object
readonly
Returns the value of attribute home.
-
#ignore_these ⇒ Object
readonly
Returns the value of attribute ignore_these.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#target_link ⇒ Object
readonly
Returns the value of attribute target_link.
-
#utils ⇒ Object
readonly
Returns the value of attribute utils.
Instance Method Summary collapse
- #backup_files ⇒ Object
-
#backup_this(this) ⇒ Object
Move file from home to a /home/backup/file or delete it if the file it is pointing does not exist.
- #feed_target_link ⇒ Object
-
#ignored_ones ⇒ Object
ignore these ones.
-
#initialize(utils, root) ⇒ Dots
constructor
A new instance of Dots.
-
#make_folders ⇒ Object
Create only the folders, if those do not exist.
- #root_files_folders ⇒ Object
- #run ⇒ Object
- #symlink_files ⇒ Object
-
#to_home(this) ⇒ Object
transform origin file absolute path with home as its root instead /a/b/c.tar –> /home/b/c.tar.
Constructor Details
Instance Attribute Details
#home ⇒ Object (readonly)
Returns the value of attribute home.
10 11 12 |
# File 'lib/cejo/ops/dots.rb', line 10 def home @home end |
#ignore_these ⇒ Object (readonly)
Returns the value of attribute ignore_these.
10 11 12 |
# File 'lib/cejo/ops/dots.rb', line 10 def ignore_these @ignore_these end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
10 11 12 |
# File 'lib/cejo/ops/dots.rb', line 10 def root @root end |
#target_link ⇒ Object (readonly)
Returns the value of attribute target_link.
10 11 12 |
# File 'lib/cejo/ops/dots.rb', line 10 def target_link @target_link end |
#utils ⇒ Object (readonly)
Returns the value of attribute utils.
10 11 12 |
# File 'lib/cejo/ops/dots.rb', line 10 def utils @utils end |
Instance Method Details
#backup_files ⇒ Object
71 72 73 74 75 76 |
# File 'lib/cejo/ops/dots.rb', line 71 def backup_files target_link.each do |target, link_name| puts "#{target} ❯ #{link_name}" backup_this link_name end end |
#backup_this(this) ⇒ Object
Move file from home to a /home/backup/file or delete it if the file it is pointing does not exist
66 67 68 69 |
# File 'lib/cejo/ops/dots.rb', line 66 def backup_this(this) warn "WARNING: #{this} found! Deleting/Moving it." this.delete if this.exist? # TODO: if file exist back/delete up it end |
#feed_target_link ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/cejo/ops/dots.rb', line 55 def feed_target_link root_files_folders[:files].each do |target| next if ignored_ones.include? target.basename.to_s # TODO: .reject ignored_ones symlink_name = to_home target target_link.store(target, symlink_name) end end |
#ignored_ones ⇒ Object
ignore these ones
86 87 88 |
# File 'lib/cejo/ops/dots.rb', line 86 def ignored_ones ['LICENSE', root.join('.git').to_path.to_s].freeze end |
#make_folders ⇒ Object
Create only the folders, if those do not exist
45 46 47 48 49 50 51 52 53 |
# File 'lib/cejo/ops/dots.rb', line 45 def make_folders root_files_folders[:folders].each do |fld| folder = to_home fld next if folder.exist? puts folder folder.mkdir end end |
#root_files_folders ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cejo/ops/dots.rb', line 19 def root_files_folders files = [] folders = [] Find.find(root) do |file| file = Pathname.new file next if file.to_path.include? '.git' next if file == root files << file if file.file? folders << file if file.directory? end { folders: folders, files: files } end |
#run ⇒ Object
90 91 92 93 94 95 |
# File 'lib/cejo/ops/dots.rb', line 90 def run feed_target_link make_folders backup_files symlink_files end |
#symlink_files ⇒ Object
78 79 80 81 82 83 |
# File 'lib/cejo/ops/dots.rb', line 78 def symlink_files target_link.each do |target, link_name| puts "#{target} ❯ #{link_name}" link_name.make_symlink target # As enumerator yielding folder to symlink end end |
#to_home(this) ⇒ Object
transform origin file absolute path with home as its root instead /a/b/c.tar –> /home/b/c.tar
37 38 39 40 41 42 |
# File 'lib/cejo/ops/dots.rb', line 37 def to_home(this) origin = this.to_path homey = home.to_path.concat('/') result = origin.gsub(root.to_path, homey) Pathname.new result end |