Don't merge config keys that start with __.
This allows config classes to store internal state somehow.
This commit is contained in:
parent
f87c25bac8
commit
d487e286f4
|
@ -33,8 +33,13 @@ module Vagrant
|
||||||
def merge(other)
|
def merge(other)
|
||||||
result = self.class.new
|
result = self.class.new
|
||||||
instance_variables_hash.merge(other.instance_variables_hash).each do |key, value|
|
instance_variables_hash.merge(other.instance_variables_hash).each do |key, 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)
|
result.instance_variable_set("@#{key}".to_sym, value)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,4 +22,26 @@ describe Vagrant::Config::Base do
|
||||||
result.one.should == 2
|
result.one.should == 2
|
||||||
result.two.should == 5
|
result.two.should == 5
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue