Class: MotherBrain::Berkshelf::Lockfile
- Inherits:
-
Object
- Object
- MotherBrain::Berkshelf::Lockfile
- 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
-
#berksfile_lock ⇒ Object
readonly
Returns the value of attribute berksfile_lock.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(berksfile_lock_path) ⇒ Lockfile
constructor
A new instance of Lockfile.
-
#locked_versions ⇒ Hash
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.
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_lock ⇒ Object (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_versions ⇒ Hash
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.
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 |