class ChefFS::FileSystem::MemoryDir
Attributes
children[R]
Public Class Methods
new(name, parent)
click to toggle source
Calls superclass method
ChefFS::FileSystem::BaseFSDir::new
# File lib/chef_fs/file_system/memory_dir.rb, line 8 def initialize(name, parent) super(name, parent) @children = [] end
Public Instance Methods
add_child(child)
click to toggle source
# File lib/chef_fs/file_system/memory_dir.rb, line 19 def add_child(child) @children.push(child) end
add_dir(path)
click to toggle source
# File lib/chef_fs/file_system/memory_dir.rb, line 35 def add_dir(path) path_parts = path.split('/') dir = self path_parts.each do |path_part| subdir = dir.child(path_part) if !subdir.exists? subdir = MemoryDir.new(path_part, dir) dir.add_child(subdir) end dir = subdir end dir end
add_file(path, value)
click to toggle source
# File lib/chef_fs/file_system/memory_dir.rb, line 27 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)
click to toggle source
# File lib/chef_fs/file_system/memory_dir.rb, line 23 def can_have_child?(name, is_dir) root.cannot_be_in_regex ? (name !~ root.cannot_be_in_regex) : true end
child(name)
click to toggle source
# File lib/chef_fs/file_system/memory_dir.rb, line 15 def child(name) @children.select { |child| child.name == name }.first || ChefFS::FileSystem::NonexistentFSObject.new(name, self) end