class Chef::RunList::VersionedRecipeList

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/chef/run_list/versioned_recipe_list.rb, line 27
def initialize
  super
  @versions = {}
end

Public Instance Methods

add_recipe(name, version = nil) click to toggle source
# File lib/chef/run_list/versioned_recipe_list.rb, line 32
def add_recipe(name, version = nil)
  if version && @versions.key?(name)
    unless Chef::Version.new(@versions[name]) == Chef::Version.new(version)
      raise Chef::Exceptions::CookbookVersionConflict, "Run list requires #{name} at versions #{@versions[name]} and #{version}"
    end
  end
  @versions[name] = version if version
  self << name unless include?(name)
end
with_duplicate_names() click to toggle source

For “foo::default” also include “foo”, for “foo” also include “foo::default”, for “foo::bar” just return “foo::bar”. This makes it easier for people to search on default recipe names.

@return [Array] Array of strings with fully-qualified and unexpanded recipe names

# File lib/chef/run_list/versioned_recipe_list.rb, line 91
def with_duplicate_names
  map do |recipe_name|
    if recipe_name.end_with?("::default")
      [ recipe_name.sub(/::default$/, ""), recipe_name ]
    elsif recipe_name.include?("::")
      recipe_name
    else
      [ recipe_name, "#{recipe_name}::default" ]
    end
  end.flatten
end
with_fully_qualified_names_and_version_constraints() click to toggle source

Get an array of strings of the fully-qualified recipe names (with ::default appended) and with the versions in “NAME@VERSION” format.

@return [Array] Array of strings with fully-qualified recipe names

# File lib/chef/run_list/versioned_recipe_list.rb, line 71
def with_fully_qualified_names_and_version_constraints
  map do |recipe_name|
    qualified_recipe = if recipe_name.include?("::")
                         recipe_name
                       else
                         "#{recipe_name}::default"
                       end

    version = @versions[recipe_name]
    qualified_recipe = "#{qualified_recipe}@#{version}" if version

    qualified_recipe
  end
end
with_version_constraints() click to toggle source

Return an Array of Hashes, each of the form:

{:name => RECIPE_NAME, :version_constraint => Chef::VersionConstraint }
# File lib/chef/run_list/versioned_recipe_list.rb, line 48
def with_version_constraints
  map do |recipe_name|
    constraint = Chef::VersionConstraint.new(@versions[recipe_name])
    { name: recipe_name, version_constraint: constraint }
  end
end
with_version_constraints_strings() click to toggle source

Return an Array of Strings, each of the form:

"NAME@VERSION"
# File lib/chef/run_list/versioned_recipe_list.rb, line 57
def with_version_constraints_strings
  map do |recipe_name|
    if @versions[recipe_name]
      "#{recipe_name}@#{@versions[recipe_name]}"
    else
      recipe_name
    end
  end
end
with_versions() click to toggle source
# File lib/chef/run_list/versioned_recipe_list.rb, line 42
def with_versions
  map { |recipe_name| { name: recipe_name, version: @versions[recipe_name] } }
end