Class: Berkshelf::CookbookStore
- Inherits:
-
Object
- Object
- Berkshelf::CookbookStore
- Defined in:
- lib/berkshelf/cookbook_store.rb
Overview
Instance Attribute Summary collapse
-
#storage_path ⇒ String
readonly
Filepath to where cookbooks are stored.
Instance Method Summary collapse
-
#cookbook(name, version) ⇒ Berkshelf::CachedCookbook?
Returns an instance of CachedCookbook representing the Cookbook of your given name and version.
-
#cookbook_path(name, version) ⇒ Pathname
Returns an expanded path to the location on disk where the Cookbook of the given name and version is located.
-
#cookbooks(filter = nil) ⇒ Array<Berkshelf::CachedCookbook>
Returns an array of the Cookbooks that have been cached to the storage_path of this instance of CookbookStore.
-
#initialize(storage_path) ⇒ CookbookStore
constructor
Create a new instance of CookbookStore with the given storage_path.
-
#satisfy(name, constraint) ⇒ Berkshelf::CachedCookbook?
Return a CachedCookbook matching the best solution for the given name and constraint.
Constructor Details
#initialize(storage_path) ⇒ CookbookStore
Create a new instance of CookbookStore with the given storage_path.
16 17 18 19 |
# File 'lib/berkshelf/cookbook_store.rb', line 16 def initialize(storage_path) @storage_path = Pathname.new(storage_path) initialize_filesystem end |
Instance Attribute Details
#storage_path ⇒ String (readonly)
Returns filepath to where cookbooks are stored.
8 9 10 |
# File 'lib/berkshelf/cookbook_store.rb', line 8 def storage_path @storage_path end |
Instance Method Details
#cookbook(name, version) ⇒ Berkshelf::CachedCookbook?
Returns an instance of CachedCookbook representing the Cookbook of your given name and version.
30 31 32 33 34 35 |
# File 'lib/berkshelf/cookbook_store.rb', line 30 def cookbook(name, version) path = cookbook_path(name, version) return nil unless path.cookbook? CachedCookbook.from_store_path(path) end |
#cookbook_path(name, version) ⇒ Pathname
Returns an expanded path to the location on disk where the Cookbook of the given name and version is located.
64 65 66 |
# File 'lib/berkshelf/cookbook_store.rb', line 64 def cookbook_path(name, version) storage_path.join("#{name}-#{version}") end |
#cookbooks(filter = nil) ⇒ Array<Berkshelf::CachedCookbook>
Returns an array of the Cookbooks that have been cached to the storage_path of this instance of CookbookStore.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/berkshelf/cookbook_store.rb', line 44 def cookbooks(filter = nil) [].tap do |cookbooks| storage_path.each_child do |p| cached_cookbook = CachedCookbook.from_store_path(p) next unless cached_cookbook next if filter && cached_cookbook.cookbook_name != filter cookbooks << cached_cookbook end end end |
#satisfy(name, constraint) ⇒ Berkshelf::CachedCookbook?
Return a CachedCookbook matching the best solution for the given name and constraint. Nil is returned if no matching CachedCookbook is found.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/berkshelf/cookbook_store.rb', line 75 def satisfy(name, constraint) graph = Solve::Graph.new cookbooks(name).each { |cookbook| graph.artifacts(name, cookbook.version) } name, version = Solve.it!(graph, [[name, constraint]]).first cookbook(name, version) rescue Solve::Errors::NoSolutionError nil end |