class Distillery::ROM::Path::File
Path
from a file
Public Class Methods
new(entry, basedir=nil)
click to toggle source
Returns a new instance of File
.
@param entry [String] path to file in basedir @param basedir [String, nil] base directory
# File lib/distillery/rom/path/file.rb, line 14 def initialize(entry, basedir=nil) if entry.start_with?('/') raise ArgumentError, "entry must be relative to basedir" end @entry = entry @basedir = basedir || '.' end
Public Instance Methods
basename()
click to toggle source
(see ROM::Path#basename
)
# File lib/distillery/rom/path/file.rb, line 47 def basename ::File.basename(@entry) end
copy(to, length = nil, offset = 0, force: false, link: :hard)
click to toggle source
(see ROM#copy
)
# File lib/distillery/rom/path/file.rb, line 57 def copy(to, length = nil, offset = 0, force: false, link: :hard) (!force && length.nil? && offset.zero? && ::File.exists?(to) && self.same?(ROM.from_file(to))) || ROM.filecopy(self.file, to, length, offset, force: force, link: link) end
delete!()
click to toggle source
(see ROM#delete!
)
# File lib/distillery/rom/path/file.rb, line 91 def delete! ::File.unlink(self.file) == 1 rescue SystemCallError false end
entry()
click to toggle source
(see ROM::Path#entry
)
# File lib/distillery/rom/path/file.rb, line 42 def entry @entry end
file()
click to toggle source
(see ROM::Path#file
)
# File lib/distillery/rom/path/file.rb, line 29 def file if @basedir == '.' then @entry else ::File.join(@basedir, @entry) end end
reader(&block)
click to toggle source
(see ROM::Path#reader
)
# File lib/distillery/rom/path/file.rb, line 52 def reader(&block) ::File.open(self.file, ::File::RDONLY, binmode: true, &block) end
rename(path, force: false)
click to toggle source
(see ROM#rename
)
# File lib/distillery/rom/path/file.rb, line 65 def rename(path, force: false) case path when String else raise ArgumentError, "unsupport path type (#{path.class})" end file = if path.start_with?('/') then path else ::File.join(@basedir, path) end if !::File.exists?(file) ::File.rename(self.file, file) == 0 elsif self.same?(ROM.from_file(file)) ::File.unlink(self.file) == 1 elsif force ::File.rename(self.file, file) == 0 else false end rescue SystemCallError false end
storage()
click to toggle source
(see ROM::Path#storage
)
# File lib/distillery/rom/path/file.rb, line 37 def storage @basedir end
to_s()
click to toggle source
(see ROM::Path#to_s
)
# File lib/distillery/rom/path/file.rb, line 24 def to_s self.file end