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
Public Class Methods
@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
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
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
# File lib/minimart/inventory_requirement/base_requirement.rb, line 38 def load_dependencies? Minimart::Configuration.load_deps end
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
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
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
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
This method must be overridden by any subclasses.
# File lib/minimart/inventory_requirement/base_requirement.rb, line 85 def download_cookbook(&block) nil end