Don't merge config keys that start with __.

This allows config classes to store internal state somehow.
master
Mitchell Hashimoto 2012-01-19 20:54:09 -08:00
parent f87c25bac8
commit d487e286f4
2 changed files with 28 additions and 1 deletions

View File

@ -33,7 +33,12 @@ module Vagrant
def merge(other)
result = self.class.new
instance_variables_hash.merge(other.instance_variables_hash).each do |key, value|
result.instance_variable_set("@#{key}".to_sym, value)
# Ignore keys that start with a double underscore. This allows
# configuration classes to still hold around internal state
# that isn't propagated.
if !key.start_with?("__")
result.instance_variable_set("@#{key}".to_sym, value)
end
end
result

View File

@ -22,4 +22,26 @@ describe Vagrant::Config::Base do
result.one.should == 2
result.two.should == 5
end
it "doesn't merge values that start with a double underscore" do
bar_class = Class.new(foo_class) do
@@counter = 0
def initialize
@__test = @@counter
@@counter += 1
end
end
one = bar_class.new
one.one = 2
one.two = 1
two = bar_class.new
two.two = 5
# Verify the counters
one.instance_variable_get(:@__test).should == 0
two.instance_variable_get(:@__test).should == 1
one.merge(two).instance_variable_get(:@__test).should == 2
end
end