Simplify the API for Environment#push

The API has a precondition that `name` is not nil
This commit is contained in:
Seth Vargo 2014-10-24 15:44:56 -04:00
parent 3871154a74
commit 413565f961
1 changed files with 18 additions and 32 deletions

View File

@ -542,50 +542,36 @@ module Vagrant
# This executes the push with the given name, raising any exceptions that # This executes the push with the given name, raising any exceptions that
# occur. # occur.
# #
def push(name=nil) # Precondition: the push is not nil and exists.
def push(name)
@logger.info("Getting push: #{name}") @logger.info("Getting push: #{name}")
if pushes.nil? || pushes.empty? name = name.to_sym
raise Vagrant::Errors::PushesNotDefined
end
if name.nil? pushes = self.vagrantfile.config.push.__compiled_pushes
if pushes.length != 1 if !pushes.key?(name)
raise Vagrant::Errors::PushStrategyNotProvided,
pushes: pushes
end
name = pushes.first
else
if !pushes.include?(name.to_sym)
raise Vagrant::Errors::PushStrategyNotDefined, raise Vagrant::Errors::PushStrategyNotDefined,
name: name, name: name,
pushes: pushes pushes: pushes.keys
end
end end
strategy, config = pushes[name]
push_registry = Vagrant.plugin("2").manager.pushes push_registry = Vagrant.plugin("2").manager.pushes
klass, _ = push_registry.get(strategy)
push_config = vagrantfile.push(name) if klass.nil?
push_config.each do |strategy, config_blocks|
plugin, _ = push_registry.get(strategy)
if plugin.nil?
raise Vagrant::Errors::PushStrategyNotLoaded, raise Vagrant::Errors::PushStrategyNotLoaded,
name: strategy, name: strategy,
pushes: push_registry.keys pushes: push_registry.keys
end end
# TODO: This should take a plugin configuration, not a list of config klass.new(self, config).push
# blocks, or should it?
plugin.new(self, config_blocks).push
end
end end
# The list of pushes defined in this Vagrantfile. # The list of pushes defined in this Vagrantfile.
# #
# @return [Array<Symbol>] # @return [Array<Symbol>]
def pushes def pushes
vagrantfile.pushes vagrantfile.config.push.__compiled_pushes.keys
end end
# This returns a machine with the proper provider for this environment. # This returns a machine with the proper provider for this environment.