# class Chef::ChefFS::FileSystem::FileSystemEntry

### Attributes

file_path[R]

### Public Class Methods

new(name, parent, file_path = nil) click to toggle source
Calls superclass method Chef::ChefFS::FileSystem::BaseFSDir.new

    # File lib/chef/chef_fs/file_system/file_system_entry.rb, line 30
    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/chef_fs/file_system/file_system_entry.rb, line 41
    def children
      begin
        Dir.entries(file_path).sort.select { |entry| entry != '.' && entry != '..' }.map { |entry| make_child(entry) }
      rescue Errno::ENOENT
        raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
      end
    end

create_child(child_name, file_contents=nil) click to toggle source

    # File lib/chef/chef_fs/file_system/file_system_entry.rb, line 49
    def create_child(child_name, file_contents=nil)
      child = make_child(child_name)
      if file_contents
        child.write(file_contents)
      else
        begin
          Dir.mkdir(child.file_path)
        rescue Errno::EEXIST
        end
      end
      @children = nil
      child
    end

delete(recurse) click to toggle source

    # File lib/chef/chef_fs/file_system/file_system_entry.rb, line 67
    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/chef_fs/file_system/file_system_entry.rb, line 63
    def dir?
      File.directory?(file_path)
    end

path_for_printing() click to toggle source

    # File lib/chef/chef_fs/file_system/file_system_entry.rb, line 37
    def path_for_printing
      file_path
    end

read() click to toggle source

    # File lib/chef/chef_fs/file_system/file_system_entry.rb, line 78
    def read
      begin
        File.open(file_path, "rb") {|f| f.read}
      rescue Errno::ENOENT
        raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
      end
    end

write(content) click to toggle source

    # File lib/chef/chef_fs/file_system/file_system_entry.rb, line 86
    def write(content)
      File.open(file_path, 'wb') do |file|
        file.write(content)
      end
    end

### Protected Instance Methods

make_child(child_name) click to toggle source

    # File lib/chef/chef_fs/file_system/file_system_entry.rb, line 94
    def make_child(child_name)
      FileSystemEntry.new(child_name, self)
    end