Class: Berkshelf::Installer::Worker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(berksfile) ⇒ Worker



70
71
72
73
# File 'lib/berkshelf/installer.rb', line 70

def initialize(berksfile)
  @berksfile  = berksfile
  @downloader = Downloader.new(berksfile)
end

Instance Attribute Details

#berksfileObject (readonly)

Returns the value of attribute berksfile.



67
68
69
# File 'lib/berkshelf/installer.rb', line 67

def berksfile
  @berksfile
end

#downloaderObject (readonly)

Returns the value of attribute downloader.



68
69
70
# File 'lib/berkshelf/installer.rb', line 68

def downloader
  @downloader
end

Instance Method Details

#install(dependency) ⇒ CachedCookbook

Install a specific dependency.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/berkshelf/installer.rb', line 81

def install(dependency)
  Berkshelf.log.info "Installing #{dependency}"

  if dependency.installed?
    Berkshelf.log.debug "  Already installed - skipping install"

    Berkshelf.formatter.use(dependency)
    dependency.cached_cookbook
  else
    name, version = dependency.name, dependency.locked_version.to_s
    source = berksfile.source_for(name, version)

    # Raise error if our Berksfile.lock has cookbook versions that
    # can't be found in sources
    raise MissingLockfileCookbookVersion.new(name, version, 'in any of the sources') unless source

    Berkshelf.log.debug "  Downloading #{dependency.name} (#{dependency.locked_version}) from #{source}"

    cookbook = source.cookbook(name, version)

    Berkshelf.log.debug "    => #{cookbook.inspect}"

    Berkshelf.formatter.install(source, cookbook)

    downloader.download(name, version) do |stash|
      CookbookStore.import(name, version, stash)
    end
  end
end