From fc4e6e624f22932bca6f6e574221d548f4802772 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 30 Jan 2019 13:03:43 -0800 Subject: [PATCH] Simplify if-statement in trigger parser --- plugins/kernel_v2/config/trigger.rb | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plugins/kernel_v2/config/trigger.rb b/plugins/kernel_v2/config/trigger.rb index 12fa27036..d3f378b72 100644 --- a/plugins/kernel_v2/config/trigger.rb +++ b/plugins/kernel_v2/config/trigger.rb @@ -44,13 +44,15 @@ module VagrantPlugins command.flatten! blk = block - if block_given? && command.last.is_a?(Hash) - extra_cfg = command.pop - elsif !block_given? && command.last.is_a?(Hash) - # We were given a hash rather than a block, - # so the last element should be the "config block" - # and the rest are commands for the trigger - blk = command.pop + if command.last.is_a?(Hash) + if block_given? + extra_cfg = command.pop + else + # We were given a hash rather than a block, + # so the last element should be the "config block" + # and the rest are commands for the trigger + blk = command.pop + end elsif !block_given? raise Vagrant::Errors::TriggersNoBlockGiven, command: command @@ -71,13 +73,15 @@ module VagrantPlugins command.flatten! blk = block - if block_given? && command.last.is_a?(Hash) - extra_cfg = command.pop - elsif !block_given? && command.last.is_a?(Hash) - # We were given a hash rather than a block, - # so the last element should be the "config block" - # and the rest are commands for the trigger - blk = command.pop + if command.last.is_a?(Hash) + if block_given? + extra_cfg = command.pop + else + # We were given a hash rather than a block, + # so the last element should be the "config block" + # and the rest are commands for the trigger + blk = command.pop + end elsif !block_given? raise Vagrant::Errors::TriggersNoBlockGiven, command: command