Class: Chef::RunList
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/chef/run_list.rb,
lib/chef/run_list/run_list_item.rb,
lib/chef/run_list/run_list_expansion.rb
Defined Under Namespace
Classes: RunListExpansion, RunListExpansionFromAPI, RunListExpansionFromCouchDB, RunListExpansionFromDisk, RunListItem
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RunList.
41
42
43
|
# File 'lib/chef/run_list.rb', line 41
def initialize
@run_list_items = Array.new
end
|
Instance Attribute Details
#run_list_items ⇒ Object
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']
36
37
38
|
# File 'lib/chef/run_list.rb', line 36
def run_list_items
@run_list_items
end
|
Instance Method Details
#<<(run_list_item) ⇒ Object
Add an item of the form “recipe” or “role”; takes a String or a RunListItem
59
60
61
62
63
|
# File 'lib/chef/run_list.rb', line 59
def <<(run_list_item)
run_list_item = run_list_item.kind_of?(RunListItem) ? run_list_item : parse_entry(run_list_item)
@run_list_items << run_list_item unless @run_list_items.include?(run_list_item)
self
end
|
#==(other) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/chef/run_list.rb', line 65
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| item.kind_of?(RunListItem) ? item : RunListItem.new(item) }
other_run_list_items == @run_list_items
end
end
|
#[](pos) ⇒ Object
85
86
87
|
# File 'lib/chef/run_list.rb', line 85
def [](pos)
@run_list_items[pos]
end
|
#[]=(pos, item) ⇒ Object
89
90
91
|
# File 'lib/chef/run_list.rb', line 89
def []=(pos, item)
@run_list_items[pos] = parse_entry(item)
end
|
#each(&block) ⇒ Object
93
94
95
|
# File 'lib/chef/run_list.rb', line 93
def each(&block)
@run_list_items.each { |i| block.call(i) }
end
|
#each_index(&block) ⇒ Object
97
98
99
|
# File 'lib/chef/run_list.rb', line 97
def each_index(&block)
@run_list_items.each_index { |i| block.call(i) }
end
|
#empty? ⇒ Boolean
81
82
83
|
# File 'lib/chef/run_list.rb', line 81
def empty?
@run_list_items.length == 0 ? true : false
end
|
#expand(data_source = 'server', couchdb = nil, rest = nil) ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/chef/run_list.rb', line 122
def expand(data_source='server', couchdb=nil, rest=nil)
couchdb = couchdb ? couchdb : Chef::CouchDB.new
expansion = expansion_for_data_source(data_source, :couchdb => couchdb, :rest => rest)
expansion.expand
expansion
end
|
#expansion_for_data_source(data_source, opts = {}) ⇒ Object
#include?(item) ⇒ Boolean
101
102
103
|
# File 'lib/chef/run_list.rb', line 101
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. TODO: 5/27/2010 cw: this method has become nothing more than a proxy, revisit its necessity
132
133
134
|
# File 'lib/chef/run_list.rb', line 132
def parse_entry(entry)
RunListItem.new(entry)
end
|
#recipe_names ⇒ Object
Also known as:
recipes
51
52
53
|
# File 'lib/chef/run_list.rb', line 51
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
117
118
119
120
|
# File 'lib/chef/run_list.rb', line 117
def remove(item)
@run_list_items.delete_if{|i| i == item}
self
end
|
#reset!(*args) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/chef/run_list.rb', line 105
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_names ⇒ Object
Also known as:
roles
45
46
47
|
# File 'lib/chef/run_list.rb', line 45
def role_names
@run_list_items.inject([]){|memo, run_list_item| memo << run_list_item.name if run_list_item.role? ; memo}
end
|
#to_s ⇒ Object
77
78
79
|
# File 'lib/chef/run_list.rb', line 77
def to_s
@run_list_items.join(", ")
end
|