Sha256: 46e976d4feaec4cc9a0d147654ee75cd72fbc7ad4eab9ce5a1e130ff8e9be4a1

Contents?: true

Size: 1.18 KB

Versions: 45

Compression:

Stored size: 1.18 KB

Contents

require 'forwardable'

module Vagrant
  # 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>
  #
  class BoxCollection
    include Enumerable
    extend Forwardable
    def_delegators :@boxes, :length, :each

    # The environment this box collection belongs to
    attr_reader :env

    def initialize(env)
      @env = env
      @boxes = []

      reload!
    end

    # Find a box in the collection by the given name. The name must
    # be a string, for now.
    def find(name)
      @boxes.each do |box|
        return box if box.name == name
      end

      nil
    end

    # Loads the list of all boxes from the source. This modifies the
    # current array.
    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
  end
end

Version data entries

45 entries across 45 versions & 5 rubygems

Version Path
vagrantup-0.8.9 lib/vagrant/box_collection.rb
vagrantup-0.8.8 lib/vagrant/box_collection.rb
vagrantup-0.8.7 lib/vagrant/box_collection.rb
vagrantup-0.8.6 lib/vagrant/box_collection.rb
vagrantup-0.8.5 lib/vagrant/box_collection.rb
vagrantup-0.8.4 lib/vagrant/box_collection.rb
vagrantup-0.8.3 lib/vagrant/box_collection.rb
vagrantup-0.8.2 lib/vagrant/box_collection.rb
vagrantup-0.8.10 lib/vagrant/box_collection.rb
vagrantup-0.8.1 lib/vagrant/box_collection.rb
vagrantup-0.8.0 lib/vagrant/box_collection.rb
vagrantup-0.7.8 lib/vagrant/box_collection.rb
vagrantup-0.7.7 lib/vagrant/box_collection.rb
vagrantup-0.7.6 lib/vagrant/box_collection.rb
vagrantup-0.7.5 lib/vagrant/box_collection.rb
vagrantup-0.7.4 lib/vagrant/box_collection.rb
vagrantup-0.7.3 lib/vagrant/box_collection.rb
vagrantup-0.7.2 lib/vagrant/box_collection.rb
vagrantup-0.7.1 lib/vagrant/box_collection.rb
vagrantup-0.7.0 lib/vagrant/box_collection.rb