Class: Chef::ChefFS::FileSystem::Memory::MemoryDir
- Inherits:
-
BaseFSDir
show all
- Defined in:
- lib/chef/chef_fs/file_system/memory/memory_dir.rb
Instance Attribute Summary collapse
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
Methods inherited from BaseFSDir
#dir?, #empty?
#chef_object, #child, #compare_to, #create_child, #delete, #dir?, #exists?, #path_for_printing, #read, #root, #write
Constructor Details
#initialize(name, parent) ⇒ MemoryDir
Returns a new instance of MemoryDir.
9
10
11
12
|
# File 'lib/chef/chef_fs/file_system/memory/memory_dir.rb', line 9
def initialize(name, parent)
super(name, parent)
@children = []
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
14
15
16
|
# File 'lib/chef/chef_fs/file_system/memory/memory_dir.rb', line 14
def children
@children
end
|
Instance Method Details
#add_child(child) ⇒ Object
20
21
22
|
# File 'lib/chef/chef_fs/file_system/memory/memory_dir.rb', line 20
def add_child(child)
@children.push(child)
end
|
#add_dir(path) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/chef/chef_fs/file_system/memory/memory_dir.rb', line 36
def add_dir(path)
path_parts = path.split("/")
dir = self
path_parts.each do |path_part|
subdir = dir.child(path_part)
unless subdir.exists?
subdir = MemoryDir.new(path_part, dir)
dir.add_child(subdir)
end
dir = subdir
end
dir
end
|
#add_file(path, value) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/chef/chef_fs/file_system/memory/memory_dir.rb', line 28
def add_file(path, value)
path_parts = path.split("/")
dir = add_dir(path_parts[0..-2].join("/"))
file = MemoryFile.new(path_parts[-1], dir, value)
dir.add_child(file)
file
end
|
#can_have_child?(name, is_dir) ⇒ Boolean
24
25
26
|
# File 'lib/chef/chef_fs/file_system/memory/memory_dir.rb', line 24
def can_have_child?(name, is_dir)
root.cannot_be_in_regex ? (name !~ root.cannot_be_in_regex) : true
end
|
#make_child_entry(name) ⇒ Object
16
17
18
|
# File 'lib/chef/chef_fs/file_system/memory/memory_dir.rb', line 16
def make_child_entry(name)
@children.find { |child| child.name == name }
end
|