Class: Berkshelf::CookbookStore
- Inherits:
-
Object
- Object
- Berkshelf::CookbookStore
- Defined in:
- lib/berkshelf/cookbook_store.rb
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.
15 16 17 18 |
# File 'lib/berkshelf/cookbook_store.rb', line 15 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.
7 8 9 |
# File 'lib/berkshelf/cookbook_store.rb', line 7 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.
29 30 31 32 33 34 |
# File 'lib/berkshelf/cookbook_store.rb', line 29 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.
62 63 64 |
# File 'lib/berkshelf/cookbook_store.rb', line 62 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.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/berkshelf/cookbook_store.rb', line 43 def cookbooks(filter = nil) cookbooks = storage_path.children.collect do |path| CachedCookbook.from_store_path(path) end.compact return cookbooks unless filter cookbooks.select do |cookbook| cookbook.cookbook_name == filter 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.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/berkshelf/cookbook_store.rb', line 73 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 |