Class: Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir

Inherits:
ChefRepositoryFileSystemCookbookEntry show all
Defined in:
lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb

Instance Attribute Summary

Attributes inherited from ChefRepositoryFileSystemCookbookEntry

#recursive, #ruby_only

Attributes inherited from FileSystemEntry

#file_path

Attributes inherited from BaseFSObject

#name, #parent, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ChefRepositoryFileSystemCookbookEntry

#initialize, #write_pretty_json

Methods inherited from ChefRepositoryFileSystemEntry

#data_handler, #initialize, #minimize, #write, #write_pretty_json, #write_pretty_json=

Methods inherited from FileSystemEntry

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

Methods inherited from BaseFSDir

#dir?, #empty?, #initialize

Methods inherited from BaseFSObject

#child, #compare_to, #create_child, #delete, #dir?, #exists?, #initialize, #path_for_printing, #read, #root, #write

Constructor Details

This class inherits a constructor from Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookEntry

Class Method Details

.canonical_cookbook_name(entry_name) ⇒ Object

Exposed as a class method so that it can be used elsewhere



61
62
63
64
65
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 61

def self.canonical_cookbook_name(entry_name)
  name_match = Chef::ChefFS::FileSystem::ChefServer::VersionedCookbookDir::VALID_VERSIONED_COOKBOOK_NAME.match(entry_name)
  return nil if name_match.nil?
  return name_match[1]
end

Instance Method Details

#can_have_child?(name, is_dir) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 50

def can_have_child?(name, is_dir)
  if is_dir
    # Only the given directories will be uploaded.
    return Chef::ChefFS::FileSystem::ChefServer::CookbookDir::COOKBOOK_SEGMENT_INFO.keys.include?(name.to_sym) && name != "root_files"
  elsif name == Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE
    return false
  end
  super(name, is_dir)
end

#can_upload?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 75

def can_upload?
  File.exists?(uploaded_cookbook_version_path) || children.size > 0
end

#canonical_cookbook_name(entry_name) ⇒ Object



67
68
69
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 67

def canonical_cookbook_name(entry_name)
  self.class.canonical_cookbook_name(entry_name)
end

#chef_objectObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 31

def chef_object
  begin
    cb = cookbook_version
    if !cb
      Chef::Log.error("Cookbook #{file_path} empty.")
      raise "Cookbook #{file_path} empty."
    end
    cb
  rescue => e
    Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{e}")
    Chef::Log.error(e.backtrace.join("\n"))
    raise
  end
end

#childrenObject



46
47
48
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 46

def children
  super.select { |entry| !(entry.dir? && entry.children.size == 0 ) }
end

#uploaded_cookbook_version_pathObject



71
72
73
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 71

def uploaded_cookbook_version_path
  File.join(file_path, Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE)
end