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

View File

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