Make sure the state file only contains unique fields
This commit is contained in:
parent
491356c938
commit
76457eff16
|
@ -10,15 +10,17 @@ module VagrantPlugins
|
||||||
|
|
||||||
@data = {}
|
@data = {}
|
||||||
@data = JSON.parse(@path.read) if @path.exist?
|
@data = JSON.parse(@path.read) if @path.exist?
|
||||||
|
@data["installed"] ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a plugin that is installed to the state file.
|
# Add a plugin that is installed to the state file.
|
||||||
#
|
#
|
||||||
# @param [String] name The name of the plugin
|
# @param [String] name The name of the plugin
|
||||||
def add_plugin(name)
|
def add_plugin(name)
|
||||||
@data["installed"] ||= []
|
if !@data["installed"].include?(name)
|
||||||
@data["installed"] << name
|
@data["installed"] << name
|
||||||
save!
|
save!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This returns a list of installed plugins according to the state
|
# This returns a list of installed plugins according to the state
|
||||||
|
@ -27,12 +29,15 @@ module VagrantPlugins
|
||||||
#
|
#
|
||||||
# @return [Array<String>]
|
# @return [Array<String>]
|
||||||
def installed_plugins
|
def installed_plugins
|
||||||
@data["installed"] ||= []
|
|
||||||
@data["installed"]
|
@data["installed"]
|
||||||
end
|
end
|
||||||
|
|
||||||
# This saves the state back into the state file.
|
# This saves the state back into the state file.
|
||||||
def save!
|
def save!
|
||||||
|
# Scrub some fields
|
||||||
|
@data["installed"].uniq!
|
||||||
|
|
||||||
|
# Save
|
||||||
@path.open("w+") do |f|
|
@path.open("w+") do |f|
|
||||||
f.write(JSON.dump(@data))
|
f.write(JSON.dump(@data))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue