class ChefFS::FileSystem::FileSystemEntry

Attributes

file_path[R]

Public Class Methods

new(name, parent, file_path = nil) click to toggle source
Calls superclass method ChefFS::FileSystem::BaseFSDir::new
# File lib/chef_fs/file_system/file_system_entry.rb, line 29
def initialize(name, parent, file_path = nil)
  super(name, parent)
  @file_path = file_path || "#{parent.file_path}/#{name}"
end

Public Instance Methods

children() click to toggle source
# File lib/chef_fs/file_system/file_system_entry.rb, line 40
def children
  begin
    Dir.entries(file_path).sort.select { |entry| entry != '.' && entry != '..' }.map { |entry| FileSystemEntry.new(entry, self) }
  rescue Errno::ENOENT
    raise ChefFS::FileSystem::NotFoundError.new(self, $!)
  end
end
create_child(child_name, file_contents=nil) click to toggle source
# File lib/chef_fs/file_system/file_system_entry.rb, line 48
def create_child(child_name, file_contents=nil)
  child = FileSystemEntry.new(child_name, self)
  if file_contents
    child.write(file_contents)
  else
    Dir.mkdir(child.file_path)
  end
  @children = nil
  child
end
delete(recurse) click to toggle source
# File lib/chef_fs/file_system/file_system_entry.rb, line 63
def delete(recurse)
  if dir?
    if !recurse
      raise MustDeleteRecursivelyError.new(self, $!)
    end
    FileUtils.rm_rf(file_path)
  else
    File.delete(file_path)
  end
end
dir?() click to toggle source
# File lib/chef_fs/file_system/file_system_entry.rb, line 59
def dir?
  File.directory?(file_path)
end
path_for_printing() click to toggle source
# File lib/chef_fs/file_system/file_system_entry.rb, line 36
def path_for_printing
  file_path
end
read() click to toggle source
# File lib/chef_fs/file_system/file_system_entry.rb, line 74
def read
  begin
    File.open(file_path, "rb") {|f| f.read}
  rescue Errno::ENOENT
    raise ChefFS::FileSystem::NotFoundError.new(self, $!)
  end
end
write(content) click to toggle source
# File lib/chef_fs/file_system/file_system_entry.rb, line 82
def write(content)
  File.open(file_path, 'wb') do |file|
    file.write(content)
  end
end