class Minimart::InventoryRequirement::BaseRequirement

BaseRequirement represents a single cookbook entry as listed in the inventory. BaseRequirement is a generic interface for other inventory requirements.

Attributes

cookbook[R]
name[R]
version_requirement[R]

Public Class Methods

new(name, opts) click to toggle source

@param [String] name The name of the cookbook @param [Hash] opts @option opts [String] :version_requirement The SemVer requirement for the cookbook

# File lib/minimart/inventory_requirement/base_requirement.rb, line 13
def initialize(name, opts)
  @name = name.to_s
  @version_requirement = opts[:version_requirement]
end

Public Instance Methods

explicit_location?() click to toggle source

Determine whether or not this is a requirement which explicitly defines it's location (e.g. Git repo). Defaults to FALSE. @return [Boolean]

# File lib/minimart/inventory_requirement/base_requirement.rb, line 21
def explicit_location?
  false
end
fetch_cookbook(&block) click to toggle source

Download a cookbook that has it's location explicitly defined (see explicit_location?) @yield [Minimart::Cookbook]

# File lib/minimart/inventory_requirement/base_requirement.rb, line 44
def fetch_cookbook(&block)
  return unless explicit_location?

  download_cookbook do |cookbook|
    @cookbook = cookbook
    block.call(cookbook) if block
  end
end
load_dependencies?() click to toggle source
# File lib/minimart/inventory_requirement/base_requirement.rb, line 38
def load_dependencies?
  Minimart::Configuration.load_deps
end
matching_source?(metadata) click to toggle source

Determine if a cookbook in the inventory has metadata matching 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/base_requirement.rb, line 73
def matching_source?(metadata)
  if metadata.has_key?('metadata_version') && metadata['metadata_version'] == '2.0'
    metadata['name'] == @name &&
      metadata['version'] == @version_requirement
  else
    true
  end
end
requirements() click to toggle source

The requirements to download this cookbook. @return [Hash]

# File lib/minimart/inventory_requirement/base_requirement.rb, line 27
def requirements
  # if this cookbook has it's location specified, we instead return it's
  # dependencies as we don't need to resolve them elsewhere

  if load_dependencies?
    explicit_location? ? cookbook.dependencies : { name => version_requirement }
  else
    explicit_location? ? {} : { name => version_requirement }
  end
end
to_hash() click to toggle source

Convert the requirement to a Hash. @return [Hash]

# File lib/minimart/inventory_requirement/base_requirement.rb, line 62
def to_hash
  {
      :metadata_version => '2.0', #metadata document version.
      :name => @name
  }
end
version_requirement?() click to toggle source

Determine whether or not a version requirement was defined for the given cookbook. @return [Boolean]

# File lib/minimart/inventory_requirement/base_requirement.rb, line 56
def version_requirement?
  !!version_requirement
end

Private Instance Methods

download_cookbook(&block) click to toggle source

This method must be overridden by any subclasses.

# File lib/minimart/inventory_requirement/base_requirement.rb, line 85
def download_cookbook(&block)
  nil
end