Class: Chef::RunList::VersionedRecipeList

Inherits:
Array
  • Object
show all
Defined in:
lib/chef/run_list/versioned_recipe_list.rb

Instance Method Summary collapse

Constructor Details

#initializeVersionedRecipeList

Returns a new instance of VersionedRecipeList.



27
28
29
30
# File 'lib/chef/run_list/versioned_recipe_list.rb', line 27

def initialize
  super
  @versions = {}
end

Instance Method Details

#add_recipe(name, version = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# 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_namesArray

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.

Returns:

  • (Array)

    Array of strings with fully-qualified and unexpanded recipe names



91
92
93
94
95
96
97
98
99
100
101
# 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_constraintsArray

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

Returns:

  • (Array)

    Array of strings with fully-qualified recipe names



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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_constraintsObject

Return an Array of Hashes, each of the form: {:name => RECIPE_NAME, :version_constraint => Chef::VersionConstraint }



48
49
50
51
52
53
# 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_stringsObject

Return an Array of Strings, each of the form: "NAME@VERSION"



57
58
59
60
61
62
63
64
65
# 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_versionsObject



42
43
44
# 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