class Backto::Path
Attributes
relative[R]
Public Class Methods
new(path_name, relative = nil)
click to toggle source
# File lib/backto/path.rb, line 8 def initialize(path_name, relative = nil) @path_name = path_name @relative = relative end
Public Instance Methods
absolute()
click to toggle source
# File lib/backto/path.rb, line 13 def absolute @absolute ||= File.join(@path_name, relative || '') end
Also aliased as: source
chdir(path_name)
click to toggle source
# File lib/backto/path.rb, line 23 def chdir(path_name) File.join(path_name, relative) end
directory?()
click to toggle source
# File lib/backto/path.rb, line 57 def directory? @is_directory ||= File.directory?(absolute) end
hardlink(target, options)
click to toggle source
# File lib/backto/path.rb, line 31 def hardlink(target, options) FileUtils.ln source, target, options rescue Errno::EEXIST raise unless hardlink? target end
hardlink?(target)
click to toggle source
# File lib/backto/path.rb, line 51 def hardlink?(target) File.stat(target).ino == File.stat(source).ino rescue Errno::ENOENT false end
join(file)
click to toggle source
# File lib/backto/path.rb, line 19 def join(file) self.class.new(@path_name, relative ? File.join(relative, file) : file) end
mkdirs(target, options = {})
click to toggle source
# File lib/backto/path.rb, line 27 def mkdirs(target, options = {}) FileUtils.mkdir_p target, options unless File.exist? target end
softlink(target, options = {})
click to toggle source
# File lib/backto/path.rb, line 37 def softlink(target, options = {}) return if softlink? target if File.directory?(target) && directory? FileUtils.rm_r target, options if options[:force] FileUtils.ln_s source, File.dirname(target), options else FileUtils.ln_s source, target, options end end
softlink?(target)
click to toggle source
# File lib/backto/path.rb, line 47 def softlink?(target) File.symlink?(target) && File.readlink(target) == source end