core: statefile can track sources, not sure if we'll use it though
This commit is contained in:
parent
35d711c91b
commit
84ecca5c15
|
@ -38,6 +38,15 @@ module Vagrant
|
|||
save!
|
||||
end
|
||||
|
||||
# Adds a RubyGems index source to look up gems.
|
||||
#
|
||||
# @param [String] url URL of the source.
|
||||
def add_source(url)
|
||||
@data["sources"] ||= []
|
||||
@data["sources"] << url if !@data["sources"].include?(url)
|
||||
save!
|
||||
end
|
||||
|
||||
# This returns a hash of installed plugins according to the state
|
||||
# file. Note that this may _not_ directly match over to actually
|
||||
# installed gems.
|
||||
|
@ -55,6 +64,23 @@ module Vagrant
|
|||
save!
|
||||
end
|
||||
|
||||
# Remove a source for RubyGems.
|
||||
#
|
||||
# @param [String] url URL of the source
|
||||
def remove_source(url)
|
||||
@data["sources"] ||= []
|
||||
@data["sources"].delete(url)
|
||||
save!
|
||||
end
|
||||
|
||||
# Returns the list of RubyGems sources that will be searched for
|
||||
# plugins.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
def sources
|
||||
@data["sources"] || []
|
||||
end
|
||||
|
||||
# This saves the state back into the state file.
|
||||
def save!
|
||||
@path.open("w+") do |f|
|
||||
|
|
|
@ -57,6 +57,29 @@ describe Vagrant::Plugin::StateFile do
|
|||
subject.add_plugin("foo", version: "1.2.3")
|
||||
expect(subject.installed_plugins["foo"]["gem_version"]).to eql("1.2.3")
|
||||
end
|
||||
|
||||
describe "sources" do
|
||||
it "should have no sources" do
|
||||
expect(subject.sources).to be_empty
|
||||
end
|
||||
|
||||
it "should add sources" do
|
||||
subject.add_source("foo")
|
||||
expect(subject.sources).to eql(["foo"])
|
||||
end
|
||||
|
||||
it "should de-dup sources" do
|
||||
subject.add_source("foo")
|
||||
subject.add_source("foo")
|
||||
expect(subject.sources).to eql(["foo"])
|
||||
end
|
||||
|
||||
it "can remove sources" do
|
||||
subject.add_source("foo")
|
||||
subject.remove_source("foo")
|
||||
expect(subject.sources).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with an old-style file" do
|
||||
|
|
Loading…
Reference in New Issue