Class: Batali::BFile
- Inherits:
-
Bogo::Config
- Object
- Bogo::Config
- Batali::BFile
- Defined in:
- lib/batali/b_file.rb
Defined Under Namespace
Classes: Cookbook, Group, Restriction
Class Method Summary collapse
-
.cookbook_coerce ⇒ Proc
Cookbook convert.
Instance Method Summary collapse
-
#auto_discover!(environment = nil) ⇒ TrueClass
Search environments for cookbooks and restraints.
Class Method Details
.cookbook_coerce ⇒ Proc
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/batali/b_file.rb', line 91 def self.cookbook_coerce proc do |v| v = [v].flatten.compact if(v.size == 1 && v.first.is_a?(Hash)) Cookbook.new(v.first) else name, args = v.first, v.slice(1, v.size) if(args.empty?) args = Smash.new elsif(args.size == 1 && args.first.is_a?(Hash)) args = args.first else args = Smash.new(:constraint => args.map(&:to_s)) end Cookbook.new(Smash.new(:name => name).merge(args)) end end end |
Instance Method Details
#auto_discover!(environment = nil) ⇒ TrueClass
Search environments for cookbooks and restraints
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/batali/b_file.rb', line 177 def auto_discover!(environment=nil) debug 'Starting cookbook auto-discovery' unless(discover) raise 'Attempting to perform auto-discovery but auto-discovery is not enabled!' end environment_items = Dir.glob(File.join(File.dirname(path), 'environments', '*.{json,rb}')).map do |e_path| result = parse_environment(e_path) if(result[:name] && result[:cookbooks]) Smash.new( result[:name] => result[:cookbooks] ) end end.compact.inject(Smash.new){|m,n| m.merge(n)} environment_items.each do |e_name, items| next if environment && e_name != environment debug "Discovery processing of environment: #{e_name}" items.each do |ckbk_name, constraints| ckbk = cookbook.detect do |c| c.name == ckbk_name end if(ckbk) unless(ckbk.constraint) debug "Skipping constraint merging due to lack of original constraints: #{ckbk.inspect}" next end new_constraints = ckbk.constraint.dup new_constraints += constraints requirement = UnitRequirement.new(*new_constraints) new_constraints = flatten_constraints(requirement.requirements) debug "Discovery merged constraints for #{ckbk.name}: #{new_constraints.inspect}" ckbk.constraint.replace(new_constraints) else debug "Discovery added cookbook #{ckbk_name}: #{constraints.inspect}" cookbook.push( Cookbook.new( :name => ckbk_name, :constraint => constraints ) ) end end end debug 'Completed cookbook auto-discovery' true end |