class Ki::DirectoryBase
Public Class Methods
find!(path, *locations)
click to toggle source
# File lib/data_storage/dir_base.rb, line 26 def self.find!(path, *locations) locations.each do |loc| dest = loc.go(path) if dest.exists? return dest end end raise "Could not find '#{path}' from '#{locations.map { |l| l.path }.join("', '")}'" end
new(path)
click to toggle source
# File lib/data_storage/dir_base.rb, line 22 def initialize(path) init_from_path(path) end
Public Instance Methods
child(name)
click to toggle source
# File lib/data_storage/dir_base.rb, line 100 def child(name) DirectoryBase.new(name) end
empty?(*sub_path)
click to toggle source
# File lib/data_storage/dir_base.rb, line 104 def empty?(*sub_path) Dir.entries(go(*sub_path).path).size == 2 end
exists?(*sub_path)
click to toggle source
# File lib/data_storage/dir_base.rb, line 59 def exists?(*sub_path) File.exists?(go(*sub_path).path) end
go(*path)
click to toggle source
# File lib/data_storage/dir_base.rb, line 45 def go(*path) if path.empty? self else path = File.join(path).split(File::Separator) child = child(path.delete_at(0)).parent(self) if path.empty? child else child.go(*path) end end end
init_from_path(path)
click to toggle source
# File lib/data_storage/dir_base.rb, line 37 def init_from_path(path) @path = path end
ki_path(*sub_paths)
click to toggle source
# File lib/data_storage/dir_base.rb, line 91 def ki_path(*sub_paths) if defined? @parent paths = [@parent.ki_path, @path] else paths = ["/"] end File.join([paths, sub_paths].flatten) end
mkdir(*path)
click to toggle source
# File lib/data_storage/dir_base.rb, line 63 def mkdir(*path) dest = go(*path) if !dest.exists? FileUtils.mkdir_p(dest.path) end dest end
name()
click to toggle source
# File lib/data_storage/dir_base.rb, line 41 def name File.basename(@path) end
path(*sub_paths)
click to toggle source
# File lib/data_storage/dir_base.rb, line 71 def path(*sub_paths) new_path = [@path, sub_paths].flatten if defined? @parent new_path.unshift(@parent.path) end File.join(new_path) end
root()
click to toggle source
# File lib/data_storage/dir_base.rb, line 79 def root if defined? @parent @parent.root else self end end
root?()
click to toggle source
# File lib/data_storage/dir_base.rb, line 87 def root? !defined? @parent end