Class: Berkshelf::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/berkshelf/installer.rb

Defined Under Namespace

Classes: Worker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(berksfile) ⇒ Installer

Returns a new instance of Installer.

Parameters:



10
11
12
13
14
# File 'lib/berkshelf/installer.rb', line 10

def initialize(berksfile)
  @berksfile  = berksfile
  @lockfile   = berksfile.lockfile
  @worker     = Worker.pool(size: [(Celluloid.cores.to_i - 1), 2].max, args: [berksfile])
end

Instance Attribute Details

#berksfileObject (readonly)

Returns the value of attribute berksfile.



5
6
7
# File 'lib/berkshelf/installer.rb', line 5

def berksfile
  @berksfile
end

#downloaderObject (readonly)

Returns the value of attribute downloader.



7
8
9
# File 'lib/berkshelf/installer.rb', line 7

def downloader
  @downloader
end

#lockfileObject (readonly)

Returns the value of attribute lockfile.



6
7
8
# File 'lib/berkshelf/installer.rb', line 6

def lockfile
  @lockfile
end

Instance Method Details

#build_universeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/berkshelf/installer.rb', line 16

def build_universe
  berksfile.sources.collect do |source|
    Thread.new do
      begin
        Berkshelf.formatter.msg("Fetching cookbook index from #{source.uri}...")
        source.build_universe
      rescue Berkshelf::APIClientError => ex
        Berkshelf.formatter.warn "Error retrieving universe from source: #{source}"
        Berkshelf.formatter.warn "  * [#{ex.class}] #{ex}"
      end
    end
  end.map(&:join)
end

#runArray<Berkshelf::CachedCookbook>

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/berkshelf/installer.rb', line 31

def run
  lockfile.reduce!

  Berkshelf.formatter.msg('Resolving cookbook dependencies...')

  dependencies, cookbooks = if lockfile.trusted?
    install_from_lockfile
  else
    install_from_universe
  end

  Berkshelf.log.debug "  Finished resolving, calculating locks"

  to_lock = dependencies.select do |dependency|
    berksfile.has_dependency?(dependency)
  end

  Berkshelf.log.debug "  New locks"
  to_lock.each do |lock|
    Berkshelf.log.debug "    #{lock}"
  end

  lockfile.graph.update(cookbooks)
  lockfile.update(to_lock)
  lockfile.save

  cookbooks
end