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:



12
13
14
15
16
17
# File 'lib/berkshelf/installer.rb', line 12

def initialize(berksfile)
  @berksfile  = berksfile
  @lockfile   = berksfile.lockfile
  @pool       = Concurrent::FixedThreadPool.new([Concurrent.processor_count - 1, 2].max)
  @worker     = Worker.new(berksfile)
end

Instance Attribute Details

#berksfileObject (readonly)

Returns the value of attribute berksfile.



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

def berksfile
  @berksfile
end

#downloaderObject (readonly)

Returns the value of attribute downloader.



9
10
11
# File 'lib/berkshelf/installer.rb', line 9

def downloader
  @downloader
end

#lockfileObject (readonly)

Returns the value of attribute lockfile.



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

def lockfile
  @lockfile
end

Instance Method Details

#build_universeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/berkshelf/installer.rb', line 19

def build_universe
  berksfile.sources.collect do |source|
    Thread.new do

      Berkshelf.formatter.msg("Fetching cookbook index from #{source}...")
      source.build_universe
    rescue Berkshelf::APIClientError => ex
      Berkshelf.formatter.warn "Error retrieving universe from source: #{source}"
      Berkshelf.formatter.warn "  * [#{ex.class}] #{ex}"

    end
  end.map(&:join)
end

#runArray<Berkshelf::CachedCookbook>

Returns:



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
59
60
61
62
# File 'lib/berkshelf/installer.rb', line 34

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