class Minimart::InventoryRequirement::GitRequirement
A single Git requirement for a cookbook as specified in the inventory. This represents a single brach, ref, or tag for a cookbook.
Attributes
@return [String] the branch to checkout once this cookbook has been fetched.
@return [String] the location to fetch this cookbook from.
@return [String] the SHA of the Git commit to checkout once this cookbook has been fetched.
@return [String] the tag to checkout once this cookbook has been fetched
Public Class Methods
@param [String] name The name of the cookbook defined by this requirement. @param [Hash] opts @option opts [String] branch The branch to checkout once this cookbook has been fetched. @option opts [String] tag The tag to checkout once this cookbook has been fetched @option opts [String] ref The SHA of the Git commit to checkout once this cookbook has been fetched.
Minimart::InventoryRequirement::BaseRequirement::new
# File lib/minimart/inventory_requirement/git_requirement.rb, line 27 def initialize(name, opts) super @branch = opts[:branch] @ref = opts[:ref] @tag = opts[:tag] @location = opts[:location] end
Public Instance Methods
Git requirements explicitly define their location, so this method will return true. @return [Boolean] TRUE
# File lib/minimart/inventory_requirement/git_requirement.rb, line 37 def explicit_location? true end
Determine if a Git cookbook in the inventory has metadata matching this requirement. This method will return true if the metadata has the same commit information as this requirement. @param [Minimart::Mirror::DownloadMetadata] metadata The download metadata for a cookbook
in the inventory.
@return [Boolean] Defaults to true
# File lib/minimart/inventory_requirement/git_requirement.rb, line 58 def matching_source?(metadata) if metadata.has_key?('metadata_version') && metadata['metadata_version'] == '2.0' metadata['source_type'] == 'git' && metadata['location'] == @location && metadata['commitish_type'] == commitish_type.to_s && (metadata['commitish_type'] == 'ref' ? true : metadata['commitish'] == commitish.to_s) else metadata['source_type'] == 'git' && metadata['commitish_type'] == commitish_type.to_s && (metadata['commitish_type'] == 'ref' ? true : metadata['commitish'] == commitish.to_s) end end
Convert this requirement to a hash @return [Hash]
Minimart::InventoryRequirement::BaseRequirement#to_hash
# File lib/minimart/inventory_requirement/git_requirement.rb, line 43 def to_hash result = super result[:source_type] = :git result[:location] = location result[:commitish_type] = commitish_type result[:commitish] = commitish result end
Private Instance Methods
# File lib/minimart/inventory_requirement/git_requirement.rb, line 82 def commitish ref || branch || tag end
# File lib/minimart/inventory_requirement/git_requirement.rb, line 86 def commitish_type return :ref if ref return :branch if branch return :tag if tag end
# File lib/minimart/inventory_requirement/git_requirement.rb, line 73 def download_cookbook(&block) Configuration.output.puts "-- Fetching '#{name}[#{commitish}]' from '#{location}'" downloader = Download::GitRepository.new(location) downloader.fetch(commitish) do |path_to_cookbook| block.call(Minimart::Cookbook.from_path(path_to_cookbook)) end end