From 84ecca5c154b9cf34cf87fc47a8e971eb1a08499 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 5 Jan 2014 22:50:55 -0800 Subject: [PATCH] core: statefile can track sources, not sure if we'll use it though --- lib/vagrant/plugin/state_file.rb | 26 +++++++++++++++++++++ test/unit/vagrant/plugin/state_file_test.rb | 23 ++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/vagrant/plugin/state_file.rb b/lib/vagrant/plugin/state_file.rb index 7263e9ee1..d8d7ecb0d 100644 --- a/lib/vagrant/plugin/state_file.rb +++ b/lib/vagrant/plugin/state_file.rb @@ -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] + def sources + @data["sources"] || [] + end + # This saves the state back into the state file. def save! @path.open("w+") do |f| diff --git a/test/unit/vagrant/plugin/state_file_test.rb b/test/unit/vagrant/plugin/state_file_test.rb index 4dc97fdc6..993d2c415 100644 --- a/test/unit/vagrant/plugin/state_file_test.rb +++ b/test/unit/vagrant/plugin/state_file_test.rb @@ -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