Class: Dotbox::File
Instance Attribute Summary collapse
-
#abs_path ⇒ Object
readonly
Returns the value of attribute abs_path.
-
#rel_path ⇒ Object
readonly
Returns the value of attribute rel_path.
Instance Method Summary collapse
- #backup ⇒ Object
- #backup_path ⇒ Object
- #backuped? ⇒ Boolean
- #directory? ⇒ Boolean
- #exist? ⇒ Boolean
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #link? ⇒ Boolean
- #link_of?(src) ⇒ Boolean
- #remove ⇒ Object
- #restore ⇒ Object
- #type ⇒ Object
Methods included from Actions
Constructor Details
#initialize(path) ⇒ File
10 11 12 13 |
# File 'lib/dotbox/file.rb', line 10 def initialize(path) @abs_path = ::File.(path) @rel_path = @abs_path.sub(/^#{Thor::Util.user_home}\//, '') end |
Instance Attribute Details
#abs_path ⇒ Object (readonly)
Returns the value of attribute abs_path.
6 7 8 |
# File 'lib/dotbox/file.rb', line 6 def abs_path @abs_path end |
#rel_path ⇒ Object (readonly)
Returns the value of attribute rel_path.
6 7 8 |
# File 'lib/dotbox/file.rb', line 6 def rel_path @rel_path end |
Instance Method Details
#backup ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/dotbox/file.rb', line 27 def backup if ::File.exist?(backup_path) raise "#{@rel_path} has been backuped." end FileUtils.mkdir_p ::File.dirname(backup_path) FileUtils.mv @abs_path, backup_path, verbose: true FileUtils.ln_s backup_path, @abs_path, verbose: true end |
#backup_path ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dotbox/file.rb', line 19 def backup_path if @backup_path.nil? backup_path = "#{Config.new(Dotbox::CONFIG_FILE).value}/Apps/Dotbox" @backup_path = ::File.("#{backup_path}/#{@rel_path}") end @backup_path end |
#backuped? ⇒ Boolean
57 58 59 |
# File 'lib/dotbox/file.rb', line 57 def backuped? link? && link_of?(backup_path) end |
#directory? ⇒ Boolean
15 16 17 |
# File 'lib/dotbox/file.rb', line 15 def directory? ::File.directory?(@abs_path) end |
#exist? ⇒ Boolean
73 74 75 |
# File 'lib/dotbox/file.rb', line 73 def exist? ::File.exist?(@abs_path) end |
#link? ⇒ Boolean
61 62 63 |
# File 'lib/dotbox/file.rb', line 61 def link? ::File.symlink? @abs_path end |
#link_of?(src) ⇒ Boolean
65 66 67 |
# File 'lib/dotbox/file.rb', line 65 def link_of?(src) ::File.readlink(@abs_path) == src end |
#remove ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/dotbox/file.rb', line 36 def remove # must get the backup path first backup_path FileUtils.rm @abs_path, verbose: true FileUtils.mv backup_path, @abs_path, verbose: true rm_empty_dir ::File.dirname(backup_path) end |
#restore ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dotbox/file.rb', line 44 def restore if exist? if link? && link_of?(backup_path) # Dont need restore return else FileUtils.mv @abs_path, "#{@abs_path}.bak", verbose: true end end FileUtils.mkdir_p ::File.dirname(@abs_path), verbose: true FileUtils.ln_s backup_path, @abs_path, verbose: true end |
#type ⇒ Object
69 70 71 |
# File 'lib/dotbox/file.rb', line 69 def type @type = directory? ? 'directory' : 'file' end |