Add Config::Top#deep_clone method to deep clone Vagrant configuration.
This commit is contained in:
parent
302bc348d3
commit
aee49a61ab
|
@ -245,6 +245,12 @@ module Vagrant
|
||||||
def loaded!
|
def loaded!
|
||||||
@loaded = true
|
@loaded = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deep clones the entire configuration tree using the marshalling
|
||||||
|
# trick. All subclasses must be able to marshal properly.
|
||||||
|
def deep_clone
|
||||||
|
Marshal.load(Marshal.dump(self))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -199,6 +199,26 @@ class ConfigTest < Test::Unit::TestCase
|
||||||
assert @top.loaded?
|
assert @top.loaded?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "deep cloning" do
|
||||||
|
class DeepCloneConfig < Vagrant::Config::Base
|
||||||
|
attr_accessor :attribute
|
||||||
|
end
|
||||||
|
|
||||||
|
setup do
|
||||||
|
Vagrant::Config::Top.configures :deep, DeepCloneConfig
|
||||||
|
@top = Vagrant::Config::Top.new
|
||||||
|
@top.deep.attribute = [1,2,3]
|
||||||
|
end
|
||||||
|
|
||||||
|
should "deep clone the object" do
|
||||||
|
copy = @top.deep_clone
|
||||||
|
copy.deep.attribute << 4
|
||||||
|
assert_not_equal @top.deep.attribute, copy.deep.attribute
|
||||||
|
assert_equal 3, @top.deep.attribute.length
|
||||||
|
assert_equal 4, copy.deep.attribute.length
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "vagrant configuration" do
|
context "vagrant configuration" do
|
||||||
|
|
Loading…
Reference in New Issue