Class: MotherBrain::Berkshelf::Lockfile

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/mb/berkshelf.rb

Overview

A wrapper around the berkshelf’s Berkshelf::Lockfile

Constant Summary collapse

BERKSFILE_LOCK =
'Berksfile.lock'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup

Constructor Details

#initialize(berksfile_lock_path) ⇒ Lockfile

Returns a new instance of Lockfile.



64
65
66
67
68
# File 'lib/mb/berkshelf.rb', line 64

def initialize(berksfile_lock_path)
  @berksfile_lock = ::Berkshelf::Lockfile.from_file(berksfile_lock_path)
rescue ::Berkshelf::LockfileParserError
  log.warn "Unable to parse Berksfile.lock - maybe it's an old format?"
end

Instance Attribute Details

#berksfile_lockObject (readonly)

Returns the value of attribute berksfile_lock.



62
63
64
# File 'lib/mb/berkshelf.rb', line 62

def berksfile_lock
  @berksfile_lock
end

Class Method Details

.from_path(root_path) ⇒ Object



57
58
59
# File 'lib/mb/berkshelf.rb', line 57

def from_path(root_path)
  new(File.join(root_path, BERKSFILE_LOCK))
end

Instance Method Details

#locked_versionsHash

Return a hash of all of the cookbook versions found in the Berksfile.lock The key is the name of the cookbook and the value is the version as a String. If there is no lockfile an empty hash is returned.

Returns:

  • (Hash)


75
76
77
78
79
80
# File 'lib/mb/berkshelf.rb', line 75

def locked_versions
  berksfile_lock.graph.locks.inject({}) do |hash, (name, dependency)|
    hash[name] = dependency.locked_version.to_s
    hash
  end
end