class Batali::UnitLoader

Load cookbook units

Public Instance Methods

populate!() click to toggle source

Populate the system with units

@return [self]

# File lib/batali/unit_loader.rb, line 18
def populate!
  memoize(:populate) do
    (file.source + file.chef_server).each do |src|
      src.units.find_all do |unit|
        if restrictions[unit.name]
          restrictions[unit.name] == src.identifier
        else
          true
        end
      end.each do |unit|
        system.add_unit(unit)
      end
    end
    file.cookbook.each do |ckbk|
      if ckbk.git
        source = Origin::Git.new(
          :name => ckbk.name,
          :url => ckbk.git,
          :subdirectory => ckbk.path,
          :ref => ckbk.ref || "master",
          :cache_path => cache,
        )
      elsif ckbk.path
        source = Origin::Path.new(
          :name => ckbk.name,
          :path => ckbk.path,
          :cache_path => cache,
        )
      end
      if source
        system.add_unit(source.units.first)
      end
    end
  end
end
restrictions() click to toggle source

@return [Smash]

# File lib/batali/unit_loader.rb, line 55
def restrictions
  memoize(:restrictions) do
    rest = (file.restrict || Smash.new).to_smash
    file.cookbook.each do |ckbk|
      if auto_path_restrict || ckbk.restrict
        if ckbk.path
          rest[ckbk.name] = Smash.new(:path => ckbk.path).checksum
        elsif ckbk.git
          rest[ckbk.name] = Smash.new(
            :url => ckbk.git,
            :ref => ckbk.ref,
          ).checksum
        end
      end
    end
    rest
  end
end