Class: Raz::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/raz/entries.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileSystem

Returns a new instance of FileSystem.



8
9
10
# File 'lib/raz/entries.rb', line 8

def initialize
  @root_entry = DirEntry.new('/', '/')
end

Instance Attribute Details

#root_entryDirEntry (readonly)

Returns:



6
7
8
# File 'lib/raz/entries.rb', line 6

def root_entry
  @root_entry
end

Instance Method Details

#add_dir(path) ⇒ DirEntry

Parameters:

  • path (String)

Returns:



33
34
35
# File 'lib/raz/entries.rb', line 33

def add_dir(path)
  make_dir_p(path)
end

#add_file(path) ⇒ FileEntry

Parameters:

  • path (String)

Returns:



41
42
43
44
45
46
# 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) ⇒ DirEntry

Returns dir entry for given path.

Parameters:

  • path (String | Array<String>)

    path to folder to create

Returns:

  • (DirEntry)

    dir entry for given path



16
17
18
19
20
21
22
23
24
25
26
27
# 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