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
-
#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
Returns a new instance of 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 |
# File 'lib/dotbox/file.rb', line 27 def backup FileUtils.mkdir_p ::File.dirname(backup_path) FileUtils.mv @abs_path, backup_path FileUtils.ln_s backup_path, @abs_path 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
46 47 48 |
# File 'lib/dotbox/file.rb', line 46 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 |
#link? ⇒ Boolean
50 51 52 |
# File 'lib/dotbox/file.rb', line 50 def link? ::File.symlink? @abs_path end |
#link_of?(src) ⇒ Boolean
54 55 56 |
# File 'lib/dotbox/file.rb', line 54 def link_of?(src) ::File.readlink(@abs_path) == src end |
#remove ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/dotbox/file.rb', line 33 def remove # must get the backup path first backup_path FileUtils.rm @abs_path FileUtils.mv backup_path, @abs_path rm_empty_dir ::File.dirname(backup_path) end |
#restore ⇒ Object
41 42 43 44 |
# File 'lib/dotbox/file.rb', line 41 def restore FileUtils.mkdir_p ::File.dirname(@abs_path) FileUtils.ln_s backup_path, @abs_path end |
#type ⇒ Object
58 59 60 |
# File 'lib/dotbox/file.rb', line 58 def type @type = directory? ? 'directory' : 'file' end |