class Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir

Attributes

child_paths[R]
write_pretty_json[RW]

Public Class Methods

new(child_paths) click to toggle source
Calls superclass method Chef::ChefFS::FileSystem::BaseFSDir.new
# File lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb, line 37
def initialize(child_paths)
  super("", nil)
  @child_paths = child_paths
end

Public Instance Methods

can_have_child?(name, is_dir) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb, line 50
def can_have_child?(name, is_dir)
  child_paths.has_key?(name) && is_dir
end
children() click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb, line 46
def children
  @children ||= child_paths.keys.sort.map { |name| make_child_entry(name) }.select { |child| !child.nil? }
end
create_child(name, file_contents = nil) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb, line 54
def create_child(name, file_contents = nil)
  child_paths[name].each do |path|
    begin
      Dir.mkdir(path)
    rescue Errno::EEXIST
    end
  end
  child = make_child_entry(name)
  @children = nil
  child
end
fs_description() click to toggle source

Used to print out the filesystem

# File lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb, line 71
def fs_description
  repo_path = File.dirname(child_paths['cookbooks'][0])
  result = "repository at #{repo_path}\n"
  if Chef::Config[:versioned_cookbooks]
    result << "  Multiple versions per cookbook\n"
  else
    result << "  One version per cookbook\n"
  end
  child_paths.each_pair do |name, paths|
    if paths.any? { |path| File.dirname(path) != repo_path }
      result << "  #{name} at #{paths.join(', ')}\n"
    end
  end
  result
end
json_class() click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb, line 66
def json_class
  nil
end

Private Instance Methods

make_child_entry(name) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb, line 89
def make_child_entry(name)
  paths = child_paths[name].select do |path|
    File.exists?(path)
  end
  if paths.size == 0
    return nil
  end
  if name == 'cookbooks'
    dirs = paths.map { |path| ChefRepositoryFileSystemCookbooksDir.new(name, self, path) }
  elsif name == 'data_bags'
    dirs = paths.map { |path| ChefRepositoryFileSystemDataBagsDir.new(name, self, path) }
  elsif name == 'acls'
    dirs = paths.map { |path| ChefRepositoryFileSystemAclsDir.new(name, self, path) }
  else
    data_handler = case name
      when 'clients'
        Chef::ChefFS::DataHandler::ClientDataHandler.new
      when 'environments'
        Chef::ChefFS::DataHandler::EnvironmentDataHandler.new
      when 'nodes'
        Chef::ChefFS::DataHandler::NodeDataHandler.new
      when 'roles'
        Chef::ChefFS::DataHandler::RoleDataHandler.new
      when 'users'
        Chef::ChefFS::DataHandler::UserDataHandler.new
      when 'groups'
        Chef::ChefFS::DataHandler::GroupDataHandler.new
      when 'containers'
        Chef::ChefFS::DataHandler::ContainerDataHandler.new
      else
        raise "Unknown top level path #{name}"
      end
    dirs = paths.map { |path| ChefRepositoryFileSystemEntry.new(name, self, path, data_handler) }
  end
  MultiplexedDir.new(dirs)
end