Class: Batali::UnitLoader

Inherits:
Utility
  • Object
show all
Includes:
Bogo::Memoization
Defined in:
lib/batali/unit_loader.rb

Overview

Load cookbook units

Instance Method Summary collapse

Instance Method Details

#populate!self

Populate the system with units

Returns:

  • (self)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/batali/unit_loader.rb', line 19

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

#restrictionsSmash

Returns:

  • (Smash)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/batali/unit_loader.rb', line 56

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