Class: Chef::ChefFS::FileSystem::ChefRepositoryFileSystemEntry

Inherits:
FileSystemEntry show all
Defined in:
lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb

Overview

ChefRepositoryFileSystemEntry works just like FileSystemEntry, except it pretends files in /cookbooks/chefignore don’t exist and it can inflate Chef objects

Direct Known Subclasses

ChefRepositoryFileSystemRootDir

Instance Attribute Summary collapse

Attributes inherited from FileSystemEntry

#file_path

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from FileSystemEntry

#create_child, #delete, #dir?, #path_for_printing, #read, #write

Methods inherited from BaseFSDir

#can_have_child?, #child, #dir?

Methods inherited from BaseFSObject

#can_have_child?, #child, #compare_to, #dir?, #exists?, #path_for_printing, #root

Constructor Details

#initialize(name, parent, file_path = nil) ⇒ ChefRepositoryFileSystemEntry

Returns a new instance of ChefRepositoryFileSystemEntry.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 35

def initialize(name, parent, file_path = nil)
  super(name, parent, file_path)
  # Load /cookbooks/chefignore
  if name == "cookbooks" && path == "/cookbooks" # We check name first because it's a faster fail than path
    @chefignore = Chef::Cookbook::Chefignore.new(self.file_path)
  # If we are a cookbook or a cookbook subdirectory, empty directories
  # underneath us are ignored (since they cannot be uploaded)
  elsif parent && parent.name === "cookbooks" && parent.path == "/cookbooks"
    @ignore_empty_directories = true
  elsif parent && parent.ignore_empty_directories?
    @ignore_empty_directories = true
  end
end

Instance Attribute Details

#chefignoreObject (readonly)

Returns the value of attribute chefignore.



49
50
51
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 49

def chefignore
  @chefignore
end

Instance Method Details

#chef_objectObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 55

def chef_object
  begin
    if parent.path == "/cookbooks"
      loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, parent.chefignore)
      loader.load_cookbooks
      return loader.cookbook_version
    end

    # Otherwise the information to inflate the object, is in the file (json_class).
    return Chef::JSONCompat.from_json(read)
  rescue
    Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}")
  end
  nil
end

#childrenObject



71
72
73
74
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 71

def children
  @children ||= Dir.entries(file_path).select { |entry| entry != '.' && entry != '..' && !ignored?(entry) }.
                                       map { |entry| ChefRepositoryFileSystemEntry.new(entry, self) }
end

#ignore_empty_directories?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 51

def ignore_empty_directories?
  @ignore_empty_directories
end