class Raz::FileSystem

Attributes

root_entry[R]

@return [DirEntry]

Public Class Methods

new() click to toggle source
# File lib/raz/entries.rb, line 8
def initialize
  @root_entry = DirEntry.new('/', '/')
end

Public Instance Methods

add_dir(path) click to toggle source

@param [String] path

@return [DirEntry]

# File lib/raz/entries.rb, line 33
def add_dir(path)
  make_dir_p(path)
end
add_file(path) click to toggle source

@param [String] path

@return [FileEntry]

# File lib/raz/entries.rb, line 41
def add_file(path)
  entry = make_dir_p(File.dirname(path))

  file_entry = FileEntry.new(File.basename(path), path)
  entry[File.basename(path)] = file_entry
end
make_dir_p(path) click to toggle source

@param [String | Array<String>] path path to folder to create

@return [DirEntry] dir entry for given path

# File lib/raz/entries.rb, line 16
def make_dir_p(path)
  components = path.split(File::SEPARATOR).reject(&:empty?)

  current = root_entry
  components.each do |dir|
    entry        = current[dir]
    current[dir] = entry = DirEntry.new(dir, path) if entry.nil?
    current      = entry
  end

  current
end