lib/berkshelf/lockfile.rb in berkshelf-3.1.5 vs lib/berkshelf/lockfile.rb in berkshelf-3.2.0

- old
+ new

@@ -14,11 +14,14 @@ # Initialize a Lockfile from the given Berksfile # # @param [Berkshelf::Berksfile] berksfile # the Berksfile associated with the Lockfile def from_berksfile(berksfile) - filepath = File.join(File.dirname(File.expand_path(berksfile.filepath)), Lockfile::DEFAULT_FILENAME) + parent = File.expand_path(File.dirname(berksfile.filepath)) + lockfile_name = "#{File.basename(berksfile.filepath)}.lock" + + filepath = File.join(parent, lockfile_name) new(berksfile: berksfile, filepath: filepath) end end DEFAULT_FILENAME = 'Berksfile.lock'.freeze @@ -34,11 +37,11 @@ # @return [Berkshelf::Berksfile] # the Berksfile for this Lockfile attr_reader :berksfile - # @return [Hash] + # @return [Lockfile::Graph] # the dependency graph attr_reader :graph # Create a new lockfile instance associated with the given Berksfile. If a # Lockfile exists, it is automatically loaded. Otherwise, an empty instance is @@ -211,10 +214,15 @@ environment.cookbook_versions = locks environment.save end end + # @return [Array<CachedCookbook>] + def cached + graph.locks.values.collect { |dependency| dependency.cached_cookbook } + end + # The list of dependencies constrained in this lockfile. # # @return [Array<Berkshelf::Dependency>] # the list of dependencies in this lockfile def dependencies @@ -253,9 +261,13 @@ # the dependency to add # # @return [Dependency] def add(dependency) @dependencies[Dependency.name(dependency)] = dependency + end + + def locks + graph.locks end # Retrieve information about a given cookbook that is in this lockfile. # # @raise [DependencyNotFound]