Class: Ridley::CookbookObject
- Inherits:
-
ChefObject
- Object
- ChefObject
- Ridley::CookbookObject
- Includes:
- Logging
- Defined in:
- lib/ridley/chef_objects/cookbook_object.rb
Constant Summary collapse
- FILE_TYPES =
[ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ].freeze
Instance Method Summary collapse
-
#download(destination = Dir.mktmpdir) ⇒ String
Download the entire cookbook.
-
#download_file(filetype, path, destination) ⇒ nil
Download a single file from a cookbook.
-
#manifest ⇒ Hash
A hash containing keys for all of the different cookbook filetypes with values representing each file of that type this cookbook contains.
-
#reload ⇒ Ridley::CookbookObject
Reload the attributes of the instantiated resource.
- #to_s ⇒ Object
Methods included from Logging
Methods inherited from ChefObject
#<=>, #==, #chef_id, chef_id, chef_json_class, chef_type, #eql?, #hash, #initialize, #inspect, #save, set_chef_id, set_chef_json_class, set_chef_type, #update
Constructor Details
This class inherits a constructor from Ridley::ChefObject
Instance Method Details
#download(destination = Dir.mktmpdir) ⇒ String
Download the entire cookbook
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ridley/chef_objects/cookbook_object.rb', line 80 def download(destination = Dir.mktmpdir) destination = File.(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) ⇒ nil
Download a single file from a cookbook
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# 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.(destination) log.debug { "downloading '#{filetype}' file: #{file} to: '#{destination}'" } resource.connection.stream(file[:url], destination) end |
#manifest ⇒ Hash
A hash containing keys for all of the different cookbook filetypes with values representing each file of that type this cookbook contains
161 162 163 164 165 166 167 |
# 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 ⇒ Ridley::CookbookObject
Reload the attributes of the instantiated resource
172 173 174 175 |
# File 'lib/ridley/chef_objects/cookbook_object.rb', line 172 def reload mass_assign(resource.find(self, self.version)._attributes_) self end |
#to_s ⇒ Object
177 178 179 |
# File 'lib/ridley/chef_objects/cookbook_object.rb', line 177 def to_s "#{name}: #{manifest}" end |