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 = Hash.new
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.has_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 self.include?(name)
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
  self.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
  self.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
  self.map {|recipe_name| {:name => recipe_name, :version => @versions[recipe_name]}}
end