lib/vfs/entries/file.rb in vfs-0.3.14 vs lib/vfs/entries/file.rb in vfs-0.3.15
- old
+ new
@@ -9,11 +9,11 @@
#
# CRUD
#
def read options = {}, &block
options[:bang] = true unless options.include? :bang
- storage.open_fs do |fs|
+ storage.open do |fs|
begin
if block
fs.read_file path, &block
else
data = ""
@@ -21,14 +21,14 @@
data
end
rescue StandardError => e
raise Vfs::Error, "can't read Dir #{self}!" if dir.exist?
attrs = get
- if attrs[:file]
+ if attrs and attrs[:file]
# unknown internal error
raise e
- elsif attrs[:dir]
+ elsif attrs and attrs[:dir]
raise Error, "You are trying to read Dir '#{self}' as if it's a File!"
else
if options[:bang]
raise Error, "file #{self} not exist!"
else
@@ -59,11 +59,11 @@
data, options = *args
options ||= {}
end
raise "can't do :override and :append at the same time!" if options[:override] and options[:append]
- storage.open_fs do |fs|
+ storage.open do |fs|
# TODO2 Performance lost, extra call to check file existence
# We need to check if the file exist before writing to it, otherwise it's
# impossible to distinguish if the StandardError caused by the 'already exist' error or
# some other error.
entry = self.entry
@@ -114,23 +114,23 @@
data = read options
write block.call(data), options
end
def destroy options = {}
- storage.open_fs do |fs|
+ storage.open do |fs|
begin
fs.delete_file path
self
rescue StandardError => e
attrs = get
- if attrs[:dir]
+ if attrs and attrs[:dir]
if options[:force]
dir.destroy
else
raise Error, "can't destroy Dir #{dir} (you are trying to destroy it as if it's a File)"
end
- elsif attrs[:file]
+ elsif attrs and attrs[:file]
# unknown internal error
raise e
else
# do nothing, file already not exist
end
@@ -192,12 +192,10 @@
template = Tilt.new(path){read}
template.render *args
end
- def size
- get :size
- end
+ def size; get :size end
def basename
::File.basename(name, File.extname(name))
end
\ No newline at end of file