Class: Batali::UnitLoader

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

Instance Method Summary collapse

Instance Method Details

#populate!self

Populate the system with units



16
17
18
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
# File 'lib/batali/unit_loader.rb', line 16

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 => cache
        )
      elsif(ckbk.path)
        source = Origin::Path.new(
          :name => ckbk.name,
          :path => ckbk.path
        )
      end
      if(source)
        system.add_unit(source.units.first)
      end
    end
  end
end

#restrictionsSmash



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/batali/unit_loader.rb', line 52

def restrictions
  memoize(:restrictions) do
    rest = (file.restrict || Smash.new).to_smash
    file.cookbook.each do |ckbk|
      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
    rest
  end
end