List actually compares state with gems
This commit is contained in:
parent
8ac7b62075
commit
f257d1211f
|
@ -1,18 +1,36 @@
|
|||
require "rubygems"
|
||||
require "set"
|
||||
|
||||
module VagrantPlugins
|
||||
module CommandPlugin
|
||||
module Action
|
||||
# This middleware lists all the installed plugins.
|
||||
#
|
||||
# This is a bit more complicated than simply listing installed
|
||||
# gems or what is in the state file as installed. Instead, this
|
||||
# actually compares installed gems with what the state file claims
|
||||
# is installed, and outputs the appropriate truly installed
|
||||
# plugins.
|
||||
class ListPlugins
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env[:gem_helper].with_environment do
|
||||
specs = Gem::Specification.find_all
|
||||
# Get the list of installed plugins according to the state file
|
||||
installed = Set.new(env[:plugin_state_file].installed_plugins)
|
||||
|
||||
# Get the actual specifications of installed gems
|
||||
specs = env[:gem_helper].with_environment do
|
||||
Gem::Specification.find_all
|
||||
end
|
||||
|
||||
# Go through each spec and if it is an installed plugin, then
|
||||
# output it. This means that both the installed state and
|
||||
# gem match up.
|
||||
specs.each do |spec|
|
||||
if installed.include?(spec.name)
|
||||
# TODO: Formatting
|
||||
env[:ui].info spec.name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,7 +55,7 @@ module VagrantPlugins
|
|||
# Clear paths so that it reads the new GEM_HOME setting
|
||||
Gem.clear_paths
|
||||
|
||||
yield
|
||||
return yield
|
||||
ensure
|
||||
# Restore the old GEM_HOME
|
||||
ENV["GEM_HOME"] = old_gem_home
|
||||
|
|
|
@ -21,6 +21,16 @@ module VagrantPlugins
|
|||
save!
|
||||
end
|
||||
|
||||
# This returns a list of installed plugins according to the state
|
||||
# file. Note that this may _not_ directly match over to actually
|
||||
# installed gems.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
def installed_plugins
|
||||
@data["installed"] ||= []
|
||||
@data["installed"]
|
||||
end
|
||||
|
||||
# This saves the state back into the state file.
|
||||
def save!
|
||||
@path.open("w+") do |f|
|
||||
|
|
Loading…
Reference in New Issue