From e0a5b1d64787d4b55560c7bd022f50652176a028 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 13 Mar 2018 11:07:41 -0700 Subject: [PATCH] Parse block trigger configs --- plugins/kernel_v2/config/trigger.rb | 21 ++++++++++++++++----- plugins/kernel_v2/config/vm_trigger.rb | 12 +++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/plugins/kernel_v2/config/trigger.rb b/plugins/kernel_v2/config/trigger.rb index 6216fc4a4..01a4e6b3f 100644 --- a/plugins/kernel_v2/config/trigger.rb +++ b/plugins/kernel_v2/config/trigger.rb @@ -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? diff --git a/plugins/kernel_v2/config/vm_trigger.rb b/plugins/kernel_v2/config/vm_trigger.rb index 59871339a..7afedb080 100644 --- a/plugins/kernel_v2/config/vm_trigger.rb +++ b/plugins/kernel_v2/config/vm_trigger.rb @@ -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