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

branch[R]

@return [String] the branch to checkout once this cookbook has been fetched.

location[R]

@return [String] the location to fetch this cookbook from.

ref[R]

@return [String] the SHA of the Git commit to checkout once this cookbook has been fetched.

tag[R]

@return [String] the tag to checkout once this cookbook has been fetched

Public Class Methods

new(name, opts) click to toggle source

@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.

# 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

explicit_location?() click to toggle source

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
matching_source?(metadata) click to toggle source

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
to_hash() click to toggle source

Convert this requirement to a hash @return [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

commitish() click to toggle source
# File lib/minimart/inventory_requirement/git_requirement.rb, line 82
def commitish
  ref || branch || tag
end
commitish_type() click to toggle source
# 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
download_cookbook(&block) click to toggle source
# 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