Class: Vagrant::BoxCollection
- Inherits:
-
Object
- Object
- Vagrant::BoxCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/vagrant/box_collection.rb
Overview
Represents a collection of boxes, providing helpful methods for finding boxes. An instance of this is returned by Environment#boxes.
Finding a Box
To find a box, use the #find method with the name of the box. The name is an exact match search.
env.boxes.find("base") # => #<Vagrant::Box>
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
The environment this box collection belongs to.
Instance Method Summary collapse
-
#find(name) ⇒ Object
Find a box in the collection by the given name.
-
#initialize(env) ⇒ BoxCollection
constructor
A new instance of BoxCollection.
-
#reload! ⇒ Object
Loads the list of all boxes from the source.
Constructor Details
#initialize(env) ⇒ BoxCollection
Returns a new instance of BoxCollection.
22 23 24 25 26 27 |
# File 'lib/vagrant/box_collection.rb', line 22 def initialize(env) @env = env @boxes = [] reload! end |
Instance Attribute Details
#env ⇒ Object (readonly)
The environment this box collection belongs to
20 21 22 |
# File 'lib/vagrant/box_collection.rb', line 20 def env @env end |
Instance Method Details
#find(name) ⇒ Object
Find a box in the collection by the given name. The name must be a string, for now.
31 32 33 34 35 36 37 |
# File 'lib/vagrant/box_collection.rb', line 31 def find(name) @boxes.each do |box| return box if box.name == name end nil end |
#reload! ⇒ Object
Loads the list of all boxes from the source. This modifies the current array.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vagrant/box_collection.rb', line 41 def reload! @boxes.clear Dir.open(env.boxes_path) do |dir| dir.each do |d| next if d == "." || d == ".." || !File.directory?(env.boxes_path.join(d)) @boxes << Box.new(env, d) end end end |