Sha256: 8083211a7f2756983854567ca07565b4c3c944dbf7d6bd11f1847a2f3f76792a

Contents?: true

Size: 1.48 KB

Versions: 40

Compression:

Stored size: 1.48 KB

Contents

require 'forwardable'

module Vagrant
  # Represents a collection of boxes, providing helpful methods for
  # finding boxes.
  class BoxCollection
    include Enumerable
    extend Forwardable
    def_delegators :@boxes, :length, :each

    # The directory that the boxes are being searched for.
    attr_reader :directory

    # Initializes the class to search for boxes in the given directory.
    def initialize(directory, action_runner)
      @directory     = directory
      @boxes         = []
      @action_runner = action_runner

      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

    # Adds a box to this collection with the given name and located
    # at the given URL.
    def add(name, url)
      raise Errors::BoxAlreadyExists, :name => name if find(name)

      @action_runner.run(:box_add,
                         :box_name => name,
                         :box_url => url,
                         :box_directory => @directory.join(name))
    end

    # Loads the list of all boxes from the source. This modifies the
    # current array.
    def reload!
      @boxes.clear

      Dir.open(@directory) do |dir|
        dir.each do |d|
          next if d == "." || d == ".." || !@directory.join(d).directory?
          @boxes << Box.new(d, @directory.join(d), @action_runner)
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 6 rubygems

Version Path
bmhatfield-vagrant-1.0.10 lib/vagrant/box_collection.rb
bmhatfield-vagrant-1.0.9 lib/vagrant/box_collection.rb
bmhatfield-vagrant-1.0.8 lib/vagrant/box_collection.rb
bmhatfield-vagrant-1.0.7 lib/vagrant/box_collection.rb
vagrantup-1.0.7 lib/vagrant/box_collection.rb
vagrantup-1.0.6 lib/vagrant/box_collection.rb
vagrantup-1.0.5 lib/vagrant/box_collection.rb
vagrantup-1.0.4 lib/vagrant/box_collection.rb
vagrantup-1.0.3 lib/vagrant/box_collection.rb
vagrantup-1.0.2 lib/vagrant/box_collection.rb
vagrantup-1.0.1 lib/vagrant/box_collection.rb
vagrantup-1.0.0 lib/vagrant/box_collection.rb
vagrantup-0.9.99.2 lib/vagrant/box_collection.rb
vagrantup-0.9.99.1 lib/vagrant/box_collection.rb
vagrantup-0.9.7 lib/vagrant/box_collection.rb
vagrantup-0.9.6 lib/vagrant/box_collection.rb
vagrantup-0.9.5 lib/vagrant/box_collection.rb
vagrantup-0.9.4 lib/vagrant/box_collection.rb
vagrantup-0.9.3 lib/vagrant/box_collection.rb
vagrantup-0.9.2 lib/vagrant/box_collection.rb