class Ridley::CookbookObject
Constants
- FILE_TYPES
Public Instance Methods
download(destination = Dir.mktmpdir)
click to toggle source
Download the entire cookbook
@param [String] destination (Dir.mktmpdir)
the place to download the cookbook too. If no value is provided the cookbook will be downloaded to a temporary location
@return [String]
the path to the directory the cookbook was downloaded to
# File lib/ridley/chef_objects/cookbook_object.rb, line 80 def download(destination = Dir.mktmpdir) destination = File.expand_path(destination) log.debug { "downloading cookbook: '#{name}'" } FILE_TYPES.each do |filetype| next unless manifest.has_key?(filetype) manifest[filetype].each do |file| file_destination = File.join(destination, file[:path].gsub('/', File::SEPARATOR)) FileUtils.mkdir_p(File.dirname(file_destination)) download_file(filetype, file[:path], file_destination) end end destination end
download_file(filetype, path, destination)
click to toggle source
Download a single file from a cookbook
@param [#to_sym] filetype
the type of file to download. These are broken up into the following types in Chef: - attribute - definition - file - library - provider - recipe - resource - root_file - template these types are where the files are stored in your cookbook's structure. For example, a recipe would be stored in the recipes directory while a root_file is stored at the root of your cookbook
@param [String] path
path of the file to download
@param [String] destination
where to download the file to
@return [nil]
# File lib/ridley/chef_objects/cookbook_object.rb, line 119 def download_file(filetype, path, destination) file_list = case filetype.to_sym when :attribute, :attributes; attributes when :definition, :definitions; definitions when :file, :files; files when :library, :libraries; libraries when :provider, :providers; providers when :recipe, :recipes; recipes when :resource, :resources; resources when :root_file, :root_files; root_files when :template, :templates; templates else raise Errors::UnknownCookbookFileType.new(filetype) end file = file_list.find { |f| f[:path] == path } return nil if file.nil? destination = File.expand_path(destination) log.debug { "downloading '#{filetype}' file: #{file} to: '#{destination}'" } resource.connection.stream(file[:url], destination) end
manifest()
click to toggle source
A hash containing keys for all of the different cookbook filetypes with values representing each file of that type this cookbook contains
@example
{ root_files: [ { :name => "afile.rb", :path => "files/ubuntu-9.10/afile.rb", :checksum => "2222", :specificity => "ubuntu-9.10" }, ], templates: [ manifest_record1, ... ], ... }
@return [Hash]
# File lib/ridley/chef_objects/cookbook_object.rb, line 161 def manifest {}.tap do |manifest| FILE_TYPES.each do |filetype| manifest[filetype] = get_attribute(filetype) end end end
reload()
click to toggle source
Reload the attributes of the instantiated resource
@return [Ridley::CookbookObject]
# File lib/ridley/chef_objects/cookbook_object.rb, line 172 def reload mass_assign(resource.find(self, self.version)._attributes_) self end
to_s()
click to toggle source
# File lib/ridley/chef_objects/cookbook_object.rb, line 177 def to_s "#{name}: #{manifest}" end