lib/vfs/entries/dir.rb in vfs-0.4.8 vs lib/vfs/entries/dir.rb in vfs-0.5.0

- old
+ new

@@ -1,10 +1,9 @@ module Vfs class Dir < Entry - # - # Container - # + + # Container. def [] path path = path.to_s if path =~ /.+[\/]$/ path = path.sub /\/$/, '' dir path @@ -15,30 +14,26 @@ end end alias_method :/, :[] - # - # Attributes - # + # Attributes. alias_method :exist?, :dir? + # CRUD. - # - # CRUD - # def create options = {} driver.open do try = 0 begin try += 1 driver.create_dir path rescue StandardError => error entry = self.entry attrs = entry.get if attrs and attrs[:file] #entry.exist? - entry.destroy + entry.delete elsif attrs and attrs[:dir] # dir already exist, no need to recreate it return self else parent = self.parent @@ -54,18 +49,16 @@ end end self end - def destroy options = {} - destroy_entry :dir, :file + def delete options = {} + delete_entry :dir, :file end + # Content. - # - # Content - # def entries *args, &block raise "invalid arguments #{args.inspect}!" if args.size > 2 options = args.last.is_a?(Hash) ? args.pop : {} query = args.first options[:bang] = true unless options.include? :bang @@ -73,13 +66,13 @@ type_required = options[:type] driver.open do begin list = [] - # query option is optional and supported only for some drivers (local driver for example) + # Query option is optional and supported only for some drivers (local driver for example). driver.each_entry path, query do |name, type| - # for performance reasons some drivers may return the type of entry as + # For performance reasons some drivers may return the type of entry as # optionally evaluated callback. type = type.call if (filter or type_required) and type.is_a?(Proc) next if filter and (filter != type) @@ -96,14 +89,14 @@ rescue StandardError => error attrs = get if attrs and attrs[:file] raise Error, "can't query entries on File ('#{self}')!" elsif attrs and attrs[:dir] - # some unknown error + # Some unknown error. raise error else - # TODO2 remove :bang + # TODO2 remove :bang. raise Error, "'#{self}' not exist!" if options[:bang] [] end end end @@ -136,27 +129,24 @@ entries{|e| throw :break, false} true end end + # Transfers. - # - # Transfers - # def copy_to to, options = {} options[:bang] = true unless options.include? :bang raise Error, "invalid argument, destination should be a Entry (#{to})!" unless to.is_a? Entry raise Error, "you can't copy to itself" if self == to target = if to.is_a? File to.dir elsif to.is_a? Dir - to.dir #(name) + to.dir elsif to.is_a? UniversalEntry - # raise "can't copy Dir to File ('#{self}')!" if to.file? and !options[:override] - to.dir #.create + to.dir else raise "can't copy to unknown Entry!" end # efficient_dir_copy(target, options) || unefficient_dir_copy(target, options) @@ -165,18 +155,14 @@ target end def move_to to, options = {} copy_to to, options - destroy options + delete options to end - # class << self - # attr_accessor :dont_use_efficient_dir_copy - # end - protected def unefficient_dir_copy to, options to.create options entries options.merge(type: true) do |e| if e.is_a? Dir @@ -187,11 +173,10 @@ raise 'internal error' end end end - # def efficient_dir_copy to, options # return false if self.class.dont_use_efficient_dir_copy # # driver.open do # try = 0 @@ -213,17 +198,17 @@ # end # # attrs = to.get # if attrs and attrs[:file] # if options[:override] - # to.destroy + # to.delete # else # raise Vfs::Error, "entry #{to} already exist!" # end # elsif attrs and attrs[:dir] # unknown_errors += 1 # # if options[:override] - # # to.destroy + # # to.delete # # else # # dir_already_exist = true # # # raise Vfs::Error, "entry #{to} already exist!" # # end # else # parent not exist \ No newline at end of file