Class: Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir
Overview
Represents ROOT/cookbooks/:cookbook
Instance Attribute Summary
#file_path, #name, #parent, #path, #recursive, #ruby_only
Class Method Summary
collapse
Instance Method Summary
collapse
#child, #compare_to, #create_child, #delete, #exists?, #initialize, #path_for_printing, #read, #root, #write_pretty_json
Class Method Details
.canonical_cookbook_name(entry_name) ⇒ Object
Exposed as a class method so that it can be used elsewhere
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 107
def can_have_child?(name, is_dir)
if is_dir && !%w{ root_files .. . }.include?(name)
return true
elsif name == Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE
return false
end
super(name, is_dir)
end
|
#can_upload? ⇒ Boolean
134
135
136
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 134
def can_upload?
File.exists?(uploaded_cookbook_version_path) || children.size > 0
end
|
#canonical_cookbook_name(entry_name) ⇒ Object
126
127
128
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 126
def canonical_cookbook_name(entry_name)
self.class.canonical_cookbook_name(entry_name)
end
|
#chef_object ⇒ Object
Customizations of base class
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 90
def chef_object
cb = cookbook_version
unless 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
|
#chefignore ⇒ Object
API Required by Respository::Directory
35
36
37
38
39
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 35
def chefignore
@chefignore ||= Chef::Cookbook::Chefignore.new(file_path)
rescue Errno::EISDIR, Errno::EACCES
end
|
#children ⇒ Object
103
104
105
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 103
def children
super.select { |entry| !(entry.dir? && entry.children.size == 0 ) }
end
|
#create(file_contents = nil) ⇒ Object
#dir? ⇒ Boolean
56
57
58
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 56
def dir?
true
end
|
#fs_entry_valid? ⇒ Boolean
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 41
def fs_entry_valid?
return false unless File.directory?(file_path) && name_valid?
if can_upload?
true
else
Chef::Log.warn("Cookbook '#{name}' is empty or entirely chefignored at #{path_for_printing}")
false
end
end
|
#name_valid? ⇒ Boolean
52
53
54
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 52
def name_valid?
!name.start_with?(".")
end
|
#uploaded_cookbook_version_path ⇒ Object
#write(cookbook_path, cookbook_version_json, from_fs) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 72
def write(cookbook_path, cookbook_version_json, from_fs)
Chef::ChefFS::FileSystem.copy_to(Chef::ChefFS::FilePattern.new("/#{cookbook_path}"), from_fs, self, nil, { purge: true })
unless File.exists?(file_path)
FileUtils.mkdir_p(file_path)
end
uploaded_cookbook_version_path = File.join(file_path, Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE)
File.open(uploaded_cookbook_version_path, "w") do |file|
file.write(cookbook_version_json)
end
end
|