Class: Raz::FileSystem
- Inherits:
-
Object
- Object
- Raz::FileSystem
- Defined in:
- lib/raz/entries.rb
Instance Attribute Summary collapse
- #root_entry ⇒ DirEntry readonly
Instance Method Summary collapse
- #add_dir(path) ⇒ DirEntry
- #add_file(path) ⇒ FileEntry
-
#initialize ⇒ FileSystem
constructor
A new instance of FileSystem.
-
#make_dir_p(path) ⇒ DirEntry
Dir entry for given path.
Constructor Details
#initialize ⇒ FileSystem
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_entry ⇒ DirEntry (readonly)
6 7 8 |
# File 'lib/raz/entries.rb', line 6 def root_entry @root_entry end |
Instance Method Details
#add_dir(path) ⇒ DirEntry
33 34 35 |
# File 'lib/raz/entries.rb', line 33 def add_dir(path) make_dir_p(path) end |
#add_file(path) ⇒ FileEntry
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.
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 |