Update trigger config merge function
This commit is contained in:
parent
7dae1acd21
commit
956ed004bb
|
@ -101,7 +101,6 @@ module VagrantPlugins
|
||||||
return trigger
|
return trigger
|
||||||
end
|
end
|
||||||
|
|
||||||
# Solve the mystery of disappearing state??
|
|
||||||
def merge(other)
|
def merge(other)
|
||||||
super.tap do |result|
|
super.tap do |result|
|
||||||
new_before_triggers = []
|
new_before_triggers = []
|
||||||
|
@ -109,17 +108,43 @@ module VagrantPlugins
|
||||||
other_defined_before_triggers = other.instance_variable_get(:@_before_triggers)
|
other_defined_before_triggers = other.instance_variable_get(:@_before_triggers)
|
||||||
other_defined_after_triggers = other.instance_variable_get(:@_after_triggers)
|
other_defined_after_triggers = other.instance_variable_get(:@_after_triggers)
|
||||||
|
|
||||||
# TODO: Is this the right solution?
|
@_before_triggers.each do |bt|
|
||||||
# If a guest in a Vagrantfile exists beyond the default, this check
|
other_bft = other_defined_before_triggers.find { |o| bt.id == o.id }
|
||||||
# will properly set up the defined triggers and validate them.
|
if other_bft
|
||||||
# overrides??? check for duplicate ids?
|
# Override, take it
|
||||||
if other_defined_before_triggers.empty? && !@_before_triggers.empty?
|
other_bft = bt.merge(other_bft)
|
||||||
result.instance_variable_set(:@_before_triggers, @_before_triggers)
|
|
||||||
|
# Preserve order, always
|
||||||
|
bt = other_bft
|
||||||
|
other_defined_before_triggers.delete(other_bft)
|
||||||
|
end
|
||||||
|
|
||||||
|
new_before_triggers << bt.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
if other_defined_before_triggers.empty? && !@_after_triggers.empty?
|
other_defined_before_triggers.each do |obt|
|
||||||
result.instance_variable_set(:@_after_triggers, @_after_triggers)
|
new_before_triggers << obt.dup
|
||||||
end
|
end
|
||||||
|
result.instance_variable_set(:@_before_triggers, new_before_triggers)
|
||||||
|
|
||||||
|
@_after_triggers.each do |at|
|
||||||
|
other_aft = other_defined_after_triggers.find { |o| at.id == o.id }
|
||||||
|
if other_aft
|
||||||
|
# Override, take it
|
||||||
|
other_aft = at.merge(other_aft)
|
||||||
|
|
||||||
|
# Preserve order, always
|
||||||
|
at = other_aft
|
||||||
|
other_defined_after_triggers.delete(other_aft)
|
||||||
|
end
|
||||||
|
|
||||||
|
new_after_triggers << at.dup
|
||||||
|
end
|
||||||
|
|
||||||
|
other_defined_after_triggers.each do |oat|
|
||||||
|
new_after_triggers << oat.dup
|
||||||
|
end
|
||||||
|
result.instance_variable_set(:@_after_triggers, new_after_triggers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -152,4 +152,43 @@ describe VagrantPlugins::Kernel_V2::TriggerConfig do
|
||||||
expect(trigger).to be_a(VagrantPlugins::Kernel_V2::VagrantConfigTrigger)
|
expect(trigger).to be_a(VagrantPlugins::Kernel_V2::VagrantConfigTrigger)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#merge" do
|
||||||
|
it "merges defined triggers" do
|
||||||
|
a = described_class.new()
|
||||||
|
b = described_class.new()
|
||||||
|
|
||||||
|
a.before(splat, hash_block)
|
||||||
|
a.after(arr, hash_block)
|
||||||
|
b.before(splat, hash_block)
|
||||||
|
b.after(arr, hash_block)
|
||||||
|
|
||||||
|
result = a.merge(b)
|
||||||
|
bf_trigger = result.instance_variable_get(:@_before_triggers)
|
||||||
|
af_trigger = result.instance_variable_get(:@_after_triggers)
|
||||||
|
|
||||||
|
expect(bf_trigger).to be_a(Array)
|
||||||
|
expect(af_trigger).to be_a(Array)
|
||||||
|
expect(bf_trigger.size).to eq(6)
|
||||||
|
expect(af_trigger.size).to eq(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "merges the other triggers if a class is empty" do
|
||||||
|
a = described_class.new()
|
||||||
|
b = described_class.new()
|
||||||
|
|
||||||
|
a.before(splat, hash_block)
|
||||||
|
a.after(arr, hash_block)
|
||||||
|
|
||||||
|
b_bf_trigger = b.instance_variable_get(:@_before_triggers)
|
||||||
|
b_af_trigger = b.instance_variable_get(:@_after_triggers)
|
||||||
|
|
||||||
|
result = a.merge(b)
|
||||||
|
bf_trigger = result.instance_variable_get(:@_before_triggers)
|
||||||
|
af_trigger = result.instance_variable_get(:@_after_triggers)
|
||||||
|
|
||||||
|
expect(bf_trigger.size).to eq(3)
|
||||||
|
expect(af_trigger.size).to eq(3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue