class Chef::RunList

Attributes

run_list[R]

@run_list_items is an array of RunListItems that describe the items to execute in order. RunListItems can load from and convert to the string forms users set on roles and nodes. For example:

@run_list_items = ['recipe[foo::bar]', 'role[webserver]']

Thus,

self.role_names would return ['webserver']
self.recipe_names would return ['foo::bar']
run_list_items[R]

@run_list_items is an array of RunListItems that describe the items to execute in order. RunListItems can load from and convert to the string forms users set on roles and nodes. For example:

@run_list_items = ['recipe[foo::bar]', 'role[webserver]']

Thus,

self.role_names would return ['webserver']
self.recipe_names would return ['foo::bar']

Public Class Methods

new(*run_list_items) click to toggle source
# File lib/chef/run_list.rb, line 45
def initialize(*run_list_items)
  @run_list_items = run_list_items.map { |i| coerce_to_run_list_item(i) }
end

Public Instance Methods

<<(run_list_item) click to toggle source

Add an item of the form “recipe” or “role”; takes a String or a RunListItem

# File lib/chef/run_list.rb, line 63
def <<(run_list_item)
  run_list_item = coerce_to_run_list_item(run_list_item)
  @run_list_items << run_list_item unless @run_list_items.include?(run_list_item)
  self
end
Also aliased as: push, add
==(other) click to toggle source
# File lib/chef/run_list.rb, line 72
def ==(other)
  if other.is_a?(Chef::RunList)
    other.run_list_items == @run_list_items
  else
    return false unless other.respond_to?(:size) && (other.size == @run_list_items.size)

    other_run_list_items = other.dup

    other_run_list_items.map! { |item| coerce_to_run_list_item(item) }
    other_run_list_items == @run_list_items
  end
end
[](pos) click to toggle source
# File lib/chef/run_list.rb, line 101
def [](pos)
  @run_list_items[pos]
end
[]=(pos, item) click to toggle source
# File lib/chef/run_list.rb, line 105
def []=(pos, item)
  @run_list_items[pos] = parse_entry(item)
end
add(run_list_item)
Alias for: <<
coerce_to_run_list_item(item) click to toggle source
# File lib/chef/run_list.rb, line 155
def coerce_to_run_list_item(item)
  item.is_a?(RunListItem) ? item : parse_entry(item)
end
delete(item)
Alias for: remove
each() { |i| ... } click to toggle source

FIXME: yard with @yield

# File lib/chef/run_list.rb, line 110
def each
  @run_list_items.each { |i| yield(i) }
end
each_index() { |i| ... } click to toggle source

FIXME: yard with @yield

# File lib/chef/run_list.rb, line 115
def each_index
  @run_list_items.each_index { |i| yield(i) }
end
empty?() click to toggle source
# File lib/chef/run_list.rb, line 97
def empty?
  @run_list_items.length == 0 ? true : false
end
expand(environment, data_source = "server", expansion_opts = {}) click to toggle source

Expands this run_list: recursively expand roles into their included recipes. Returns a RunListExpansion object.

# File lib/chef/run_list.rb, line 144
def expand(environment, data_source = "server", expansion_opts = {})
  expansion = expansion_for_data_source(environment, data_source, expansion_opts)
  expansion.expand
  expansion
end
expansion_for_data_source(environment, data_source, opts = {}) click to toggle source
# File lib/chef/run_list.rb, line 159
def expansion_for_data_source(environment, data_source, opts = {})
  case data_source.to_s
  when "disk"
    RunListExpansionFromDisk.new(environment, @run_list_items)
  when "server"
    RunListExpansionFromAPI.new(environment, @run_list_items, opts[:rest])
  end
end
for_json() click to toggle source
# File lib/chef/run_list.rb, line 89
def for_json
  to_a.map(&:to_s)
end
include?(item) click to toggle source
# File lib/chef/run_list.rb, line 119
def include?(item)
  @run_list_items.include?(parse_entry(item))
end
parse_entry(entry) click to toggle source

Converts a string run list entry to a RunListItem object.

# File lib/chef/run_list.rb, line 151
def parse_entry(entry)
  RunListItem.new(entry)
end
push(run_list_item)
Alias for: <<
recipe_names() click to toggle source
# File lib/chef/run_list.rb, line 55
def recipe_names
  @run_list_items.inject([]) { |memo, run_list_item| memo << run_list_item.name if run_list_item.recipe?; memo }
end
Also aliased as: recipes
recipes()
Alias for: recipe_names
remove(item) click to toggle source
# File lib/chef/run_list.rb, line 135
def remove(item)
  @run_list_items.delete_if { |i| i == item }
  self
end
Also aliased as: delete
reset!(*args) click to toggle source
# File lib/chef/run_list.rb, line 123
def reset!(*args)
  @run_list_items.clear
  args.flatten.each do |item|
    if item.is_a?(Chef::RunList)
      item.each { |r| self << r }
    else
      self << item
    end
  end
  self
end
role_names() click to toggle source
# File lib/chef/run_list.rb, line 49
def role_names
  @run_list_items.inject([]) { |memo, run_list_item| memo << run_list_item.name if run_list_item.role?; memo }
end
Also aliased as: roles
roles()
Alias for: role_names
to_json(*a) click to toggle source
# File lib/chef/run_list.rb, line 93
def to_json(*a)
  Chef::JSONCompat.to_json(for_json, *a)
end
to_s() click to toggle source
# File lib/chef/run_list.rb, line 85
def to_s
  @run_list_items.join(", ")
end