Class: Chef::RunList
- Includes:
- Enumerable
- Defined in:
- lib/chef/run_list.rb
Instance Attribute Summary collapse
-
#recipes ⇒ Object
readonly
Returns the value of attribute recipes.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
-
#run_list ⇒ Object
readonly
Returns the value of attribute run_list.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #==(*isequal) ⇒ Object
- #[](pos) ⇒ Object
- #[]=(pos, item) ⇒ Object
- #each(&block) ⇒ Object
- #each_index(&block) ⇒ Object
- #empty? ⇒ Boolean
- #expand(from = 'server') ⇒ Object
- #include?(item) ⇒ Boolean
-
#initialize ⇒ RunList
constructor
A new instance of RunList.
- #parse_entry(entry) ⇒ Object
- #remove(item) ⇒ Object
- #reset(*args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ RunList
Returns a new instance of RunList.
26 27 28 29 30 31 |
# File 'lib/chef/run_list.rb', line 26 def initialize @run_list = Array.new @recipes = Array.new @roles = Array.new @seen_roles = Array.new end |
Instance Attribute Details
#recipes ⇒ Object (readonly)
Returns the value of attribute recipes.
24 25 26 |
# File 'lib/chef/run_list.rb', line 24 def recipes @recipes end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
24 25 26 |
# File 'lib/chef/run_list.rb', line 24 def roles @roles end |
#run_list ⇒ Object (readonly)
Returns the value of attribute run_list.
24 25 26 |
# File 'lib/chef/run_list.rb', line 24 def run_list @run_list end |
Instance Method Details
#<<(item) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/run_list.rb', line 33 def <<(item) type, entry, fentry = parse_entry(item) case type when 'recipe' @recipes << entry unless @recipes.include?(entry) when 'role' @roles << entry unless @roles.include?(entry) end @run_list << fentry unless @run_list.include?(fentry) self end |
#==(*isequal) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/chef/run_list.rb', line 45 def ==(*isequal) check_array = nil if isequal[0].kind_of?(Chef::RunList) check_array = isequal[0].run_list else check_array = isequal.flatten end return false if check_array.length != @run_list.length check_array.each_index do |i| to_check = check_array[i] type, name, fname = parse_entry(to_check) return false if @run_list[i] != fname end true end |
#[](pos) ⇒ Object
72 73 74 |
# File 'lib/chef/run_list.rb', line 72 def [](pos) @run_list[pos] end |
#[]=(pos, item) ⇒ Object
76 77 78 79 |
# File 'lib/chef/run_list.rb', line 76 def []=(pos, item) type, entry, fentry = parse_entry(item) @run_list[pos] = fentry end |
#each(&block) ⇒ Object
81 82 83 |
# File 'lib/chef/run_list.rb', line 81 def each(&block) @run_list.each { |i| block.call(i) } end |
#each_index(&block) ⇒ Object
85 86 87 |
# File 'lib/chef/run_list.rb', line 85 def each_index(&block) @run_list.each_index { |i| block.call(i) } end |
#empty? ⇒ Boolean
68 69 70 |
# File 'lib/chef/run_list.rb', line 68 def empty? @run_list.length == 0 ? true : false end |
#expand(from = 'server') ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/chef/run_list.rb', line 119 def (from='server') recipes = Array.new default_attrs = Mash.new override_attrs = Mash.new @run_list.each do |entry| type, name, fname = parse_entry(entry) case type when 'recipe' recipes << name unless recipes.include?(name) when 'role' role = nil next if @seen_roles.include?(name) if from == 'disk' || Chef::Config[:solo] # Load the role from disk role = Chef::Role.from_disk("#{name}") elsif from == 'server' # Load the role from the server r = Chef::REST.new(Chef::Config[:role_url]) role = r.get_rest("roles/#{name}") elsif from == 'couchdb' # Load the role from couchdb role = Chef::Role.cdb_load(name) end @seen_roles << name rec, d, o = role.run_list.(from) rec.each { |r| recipes << r unless recipes.include?(r) } default_attrs = Chef::Mixin::DeepMerge.merge(default_attrs, Chef::Mixin::DeepMerge.merge(role.default_attributes,d)) override_attrs = Chef::Mixin::DeepMerge.merge(override_attrs, Chef::Mixin::DeepMerge.merge(role.override_attributes, o)) end end return recipes, default_attrs, override_attrs end |
#include?(item) ⇒ Boolean
89 90 91 92 |
# File 'lib/chef/run_list.rb', line 89 def include?(item) type, entry, fentry = parse_entry(item) @run_list.include?(fentry) end |
#parse_entry(entry) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/chef/run_list.rb', line 153 def parse_entry(entry) case entry when /^(.+)\[(.+)\]$/ [ $1, $2, entry ] else [ 'recipe', entry, "recipe[#{entry}]" ] end end |
#remove(item) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/chef/run_list.rb', line 108 def remove(item) type, entry, fentry = parse_entry(item) @run_list.delete_if { |i| i == fentry } if type == "recipe" @recipes.delete_if { |i| i == entry } elsif type == "role" @roles.delete_if { |i| i == entry } end self end |
#reset(*args) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chef/run_list.rb', line 94 def reset(*args) @run_list = Array.new @recipes = Array.new @roles = Array.new args.flatten.each do |item| if item.kind_of?(Chef::RunList) item.each { |r| self << r } else self << item end end self end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/chef/run_list.rb', line 64 def to_s @run_list.join(", ") end |