Class: Chef::RunList
- Inherits:
-
Object
- Object
- 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
Constructor Details
#initialize ⇒ RunList
Returns a new instance of RunList.
26 27 28 29 30 |
# File 'lib/chef/run_list.rb', line 26 def initialize @run_list = Array.new @recipes = Array.new @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
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/chef/run_list.rb', line 32 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chef/run_list.rb', line 44 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
67 68 69 |
# File 'lib/chef/run_list.rb', line 67 def [](pos) @run_list[pos] end |
#[]=(pos, item) ⇒ Object
71 72 73 74 |
# File 'lib/chef/run_list.rb', line 71 def []=(pos, item) type, entry, fentry = parse_entry(item) @run_list[pos] = fentry end |
#each(&block) ⇒ Object
76 77 78 |
# File 'lib/chef/run_list.rb', line 76 def each(&block) @run_list.each { |i| block.call(i) } end |
#each_index(&block) ⇒ Object
80 81 82 |
# File 'lib/chef/run_list.rb', line 80 def each_index(&block) @run_list.each_index { |i| block.call(i) } end |
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/chef/run_list.rb', line 63 def empty? @run_list.length == 0 ? true : false end |
#expand(from = 'server') ⇒ Object
114 115 116 117 118 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 |
# File 'lib/chef/run_list.rb', line 114 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 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.load(name) end role.recipes.each { |r| recipes << r unless recipes.include?(r) } default_attrs = Chef::Mixin::DeepMerge.merge(default_attrs, role.default_attributes) override_attrs = Chef::Mixin::DeepMerge.merge(override_attrs, role.override_attributes) end end return recipes, default_attrs, override_attrs end |
#include?(item) ⇒ Boolean
84 85 86 87 |
# File 'lib/chef/run_list.rb', line 84 def include?(item) type, entry, fentry = parse_entry(item) @run_list.include?(fentry) end |
#parse_entry(entry) ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/chef/run_list.rb', line 145 def parse_entry(entry) case entry when /^(.+)\[(.+)\]$/ [ $1, $2, entry ] else [ 'recipe', entry, "recipe[#{entry}]" ] end end |
#remove(item) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/chef/run_list.rb', line 103 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
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/chef/run_list.rb', line 89 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 |