Class: Chef::RunList

Inherits:
Object show all
Includes:
Mixin::ParamsValidate, Enumerable
Defined in:
lib/chef/run_list.rb,
lib/chef/run_list/run_list_item.rb,
lib/chef/run_list/run_list_expansion.rb,
lib/chef/run_list/versioned_recipe_list.rb

Defined Under Namespace

Classes: RunListExpansion, RunListExpansionFromAPI, RunListExpansionFromCouchDB, RunListExpansionFromDisk, RunListItem, VersionedRecipeList

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ParamsValidate

#set_or_return, #validate

Constructor Details

#initialize(*run_list_items) ⇒ RunList

Returns a new instance of RunList.



45
46
47
# 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

Instance Attribute Details

#run_list_itemsObject (readonly) Also known as: run_list

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']


40
41
42
# File 'lib/chef/run_list.rb', line 40

def run_list_items
  @run_list_items
end

Instance Method Details

#<<(run_list_item) ⇒ Object Also known as: push

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



63
64
65
66
67
# 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

#==(other) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/chef/run_list.rb', line 71

def ==(other)
  if other.kind_of?(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) ⇒ Object



95
96
97
# File 'lib/chef/run_list.rb', line 95

def [](pos)
  @run_list_items[pos]
end

#[]=(pos, item) ⇒ Object



99
100
101
# File 'lib/chef/run_list.rb', line 99

def []=(pos, item)
  @run_list_items[pos] = parse_entry(item)
end

#coerce_to_run_list_item(item) ⇒ Object



147
148
149
# File 'lib/chef/run_list.rb', line 147

def coerce_to_run_list_item(item)
  item.kind_of?(RunListItem) ? item : parse_entry(item)
end

#each(&block) ⇒ Object



103
104
105
# File 'lib/chef/run_list.rb', line 103

def each(&block)
  @run_list_items.each { |i| block.call(i) }
end

#each_index(&block) ⇒ Object



107
108
109
# File 'lib/chef/run_list.rb', line 107

def each_index(&block)
  @run_list_items.each_index { |i| block.call(i) }
end

#empty?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/chef/run_list.rb', line 91

def empty?
  @run_list_items.length == 0 ? true : false
end

#expand(environment, data_source = 'server', expansion_opts = {}) ⇒ Object

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



136
137
138
139
140
# File 'lib/chef/run_list.rb', line 136

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 = {}) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/chef/run_list.rb', line 151

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])
  when 'couchdb'
    RunListExpansionFromCouchDB.new(environment, @run_list_items, opts[:couchdb])
  end
end

#include?(item) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/chef/run_list.rb', line 111

def include?(item)
  @run_list_items.include?(parse_entry(item))
end

#parse_entry(entry) ⇒ Object

Converts a string run list entry to a RunListItem object.



143
144
145
# File 'lib/chef/run_list.rb', line 143

def parse_entry(entry)
  RunListItem.new(entry)
end

#recipe_namesObject Also known as: recipes



55
56
57
# 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

#remove(item) ⇒ Object Also known as: delete



127
128
129
130
# File 'lib/chef/run_list.rb', line 127

def remove(item)
  @run_list_items.delete_if{|i| i == item}
  self
end

#reset!(*args) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/chef/run_list.rb', line 115

def reset!(*args)
  @run_list_items.clear
  args.flatten.each do |item|
    if item.kind_of?(Chef::RunList)
      item.each { |r| self << r }
    else
      self << item
    end
  end
  self
end

#role_namesObject Also known as: roles



49
50
51
# 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

#to_json(*args) ⇒ Object



87
88
89
# File 'lib/chef/run_list.rb', line 87

def to_json(*args)
  to_a.to_json(*args)
end

#to_sObject



83
84
85
# File 'lib/chef/run_list.rb', line 83

def to_s
  @run_list_items.join(", ")
end