Class: TestFs::Directory

Inherits:
Node
  • Object
show all
Defined in:
lib/test_fs/directory.rb

Overview

Directory

Represents a single directory node.

Direct Known Subclasses

RootDirectory

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#path

Constructor Details

#initialize(root_path, name) ⇒ Directory

Create a new directory at the given path with the supplied name



15
16
17
18
# File 'lib/test_fs/directory.rb', line 15

def initialize(root_path, name)
  @nodes = []
  super(root_path, name)
end

Instance Attribute Details

#nodesObject (readonly)

A collection of sub-directories or files contained in this directory



11
12
13
# File 'lib/test_fs/directory.rb', line 11

def nodes
  @nodes
end

Instance Method Details

#create!Object

Create the current directory and any associated nodes (files / directories)



37
38
39
40
# File 'lib/test_fs/directory.rb', line 37

def create!
  FileUtils.mkdir(self.path)
  self.nodes.each {|node| node.create! }
end

#dir(name) {|directory| ... } ⇒ Object

Register a sub-directory under the current directory

Yields:

  • (directory)


22
23
24
25
26
27
# File 'lib/test_fs/directory.rb', line 22

def dir(name)
  directory = Directory.new(self.path, name)
  self.nodes << directory
  
  yield directory if block_given?
end

#file(name) ⇒ Object

Register a file under the current directory



31
32
33
# File 'lib/test_fs/directory.rb', line 31

def file(name)
  self.nodes << File.new(self.path, name)
end