Parse block trigger configs

This commit is contained in:
Brian Cain 2018-03-13 11:07:41 -07:00
parent 6f00eb5679
commit e0a5b1d647
No known key found for this signature in database
GPG Key ID: 43D51080D357A001
2 changed files with 19 additions and 14 deletions

View File

@ -32,8 +32,7 @@ module VagrantPlugins
end
command.each do |cmd|
trigger = VagrantConfigTrigger.new(cmd)
trigger.add_config(blk)
trigger = create_trigger(cmd, blk)
@_before_triggers << trigger
end
end
@ -42,7 +41,7 @@ module VagrantPlugins
# trigger
#
# @param [Symbol] command Vagrant command to create trigger on
# @param [Block] block The defined before block
# @param [Block] block The defined after block
def after(*command, &block)
blk = block
if !block_given? && command.last.is_a?(Hash)
@ -55,8 +54,7 @@ module VagrantPlugins
end
command.each do |cmd|
trigger = VagrantConfigTrigger.new(cmd)
trigger.add_config(blk)
trigger = create_trigger(cmd, blk)
@_after_triggers << trigger
end
end
@ -65,6 +63,19 @@ module VagrantPlugins
# Internal methods, don't call these.
#-------------------------------------------------------------------
# @param [Symbol] command Vagrant command to create trigger on
# @param [Block] block The defined config block
def create_trigger(command, block)
trigger = VagrantConfigTrigger.new(cmd)
if block.is_a?(Hash)
trigger.set_options(block)
else
block.call(trigger, VagrantConfigTrigger)
end
trigger.finalize!
return trigger
end
def finalize!
# read through configured settings blocks and set their values
# and then set up action hooks here?

View File

@ -79,15 +79,9 @@ module VagrantPlugins
@command = command.to_sym
end
# Expecting a ruby block of a trigger config
def add_config(config_block)
if config_block.is_a?(Hash)
# We have a ruby hash
self.set_options(config_block)
else
# We have a ruby block
end
end
#-------------------------------------------------------------------
# Internal methods, don't call these.
#-------------------------------------------------------------------
def finalize!
# Ensure all config options are set to nil if untouched by user