Files

Class/Module Index [+]

Quicksearch

Chef::ChefFS::FileSystem::FileSystemEntry

Attributes

file_path[R]

Public Class Methods

new(name, parent, file_path = nil) click to toggle source
# File lib/chef/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/chef_fs/file_system/file_system_entry.rb, line 40
def children
  begin
    @children ||= Dir.entries(file_path).select { |entry| entry != '.' && entry != '..' }.map { |entry| FileSystemEntry.new(entry, self) }
  rescue Errno::ENOENT
    raise Chef::ChefFS::FileSystem::NotFoundError.new($!), "#{file_path} not found"
  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 48
def create_child(child_name, file_contents=nil)
  result = FileSystemEntry.new(child_name, self)
  if file_contents
    result.write(file_contents)
  else
    Dir.mkdir(result.file_path)
  end
  result
end
delete(recurse) click to toggle source
# File lib/chef/chef_fs/file_system/file_system_entry.rb, line 62
def delete(recurse)
  if dir?
    if recurse
      FileUtils.rm_rf(file_path)
    else
      File.rmdir(file_path)
    end
  else
    File.delete(file_path)
  end
end
dir?() click to toggle source
# File lib/chef/chef_fs/file_system/file_system_entry.rb, line 58
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 36
def path_for_printing
  Chef::ChefFS::PathUtils::relative_to(file_path, File.expand_path(Dir.pwd))
end
read() click to toggle source
# File lib/chef/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 Chef::ChefFS::FileSystem::NotFoundError.new($!), "#{file_path} not found"
  end
end
write(content) click to toggle source
# File lib/chef/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

[Validate]

Generated with the Darkfish Rdoc Generator 2.