summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-09-29 14:35:14 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-10-25 09:29:29 -0700
commit10904d6cf42a2a0ed69757aca3e80f512bb89379 (patch)
tree8ca5e167c77e3f2301a27c8926d7df72520fe7a3
parentc38fd335b667ccc8dcb1a0ae276be44f344c9fea (diff)
downloadchef-10904d6cf42a2a0ed69757aca3e80f512bb89379.tar.gz
standardize initializer args for VividMash+ImmutableMash
if anyone is using these directly this might be a breaking change, although it makes it considerably easier to use VividMash and IMO ImmutableMash is an implementation detail of the deep merge cache and Chef::Node object. we definitely have never documented these APIs, so I think the onus is on the consumer to update their code. VividMash.new() should now work. VividMash.new({ foo: :bar }) should also now work. IDK what object people would have been passing in as the root object before. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/node/attribute.rb40
-rw-r--r--lib/chef/node/attribute_collections.rb15
-rw-r--r--lib/chef/node/immutable_collections.rb4
-rw-r--r--lib/chef/node/mixin/state_tracking.rb2
-rw-r--r--spec/unit/node/vivid_mash_spec.rb5
5 files changed, 34 insertions, 32 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index 747f7f623c..67b114a270 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -188,19 +188,19 @@ class Chef
attr_reader :automatic
def initialize(normal, default, override, automatic)
- @default = VividMash.new(self, default)
- @env_default = VividMash.new(self, {})
- @role_default = VividMash.new(self, {})
- @force_default = VividMash.new(self, {})
+ @default = VividMash.new(default, self)
+ @env_default = VividMash.new({}, self)
+ @role_default = VividMash.new({}, self)
+ @force_default = VividMash.new({}, self)
- @normal = VividMash.new(self, normal)
+ @normal = VividMash.new(normal, self)
- @override = VividMash.new(self, override)
- @role_override = VividMash.new(self, {})
- @env_override = VividMash.new(self, {})
- @force_override = VividMash.new(self, {})
+ @override = VividMash.new(override, self)
+ @role_override = VividMash.new({}, self)
+ @env_override = VividMash.new({}, self)
+ @force_override = VividMash.new({}, self)
- @automatic = VividMash.new(self, automatic)
+ @automatic = VividMash.new(automatic, self)
super()
end
@@ -232,59 +232,59 @@ class Chef
# Set the cookbook level default attribute component to +new_data+.
def default=(new_data)
reset
- @default = VividMash.new(self, new_data)
+ @default = VividMash.new(new_data, self)
end
# Set the role level default attribute component to +new_data+
def role_default=(new_data)
reset
- @role_default = VividMash.new(self, new_data)
+ @role_default = VividMash.new(new_data, self)
end
# Set the environment level default attribute component to +new_data+
def env_default=(new_data)
reset
- @env_default = VividMash.new(self, new_data)
+ @env_default = VividMash.new(new_data, self)
end
# Set the force_default (+default!+) level attributes to +new_data+
def force_default=(new_data)
reset
- @force_default = VividMash.new(self, new_data)
+ @force_default = VividMash.new(new_data, self)
end
# Set the normal level attribute component to +new_data+
def normal=(new_data)
reset
- @normal = VividMash.new(self, new_data)
+ @normal = VividMash.new(new_data, self)
end
# Set the cookbook level override attribute component to +new_data+
def override=(new_data)
reset
- @override = VividMash.new(self, new_data)
+ @override = VividMash.new(new_data, self)
end
# Set the role level override attribute component to +new_data+
def role_override=(new_data)
reset
- @role_override = VividMash.new(self, new_data)
+ @role_override = VividMash.new(new_data, self)
end
# Set the environment level override attribute component to +new_data+
def env_override=(new_data)
reset
- @env_override = VividMash.new(self, new_data)
+ @env_override = VividMash.new(new_data, self)
end
def force_override=(new_data)
reset
- @force_override = VividMash.new(self, new_data)
+ @force_override = VividMash.new(new_data, self)
end
def automatic=(new_data)
reset
- @automatic = VividMash.new(self, new_data)
+ @automatic = VividMash.new(new_data, self)
end
#
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb
index c7482799cc..be87c028cb 100644
--- a/lib/chef/node/attribute_collections.rb
+++ b/lib/chef/node/attribute_collections.rb
@@ -69,7 +69,7 @@ class Chef
end
end
- def initialize(root = self, data = [])
+ def initialize(data = [], root = self)
@__root ||= root
super(data)
map! { |e| convert_value(e) }
@@ -95,9 +95,9 @@ class Chef
when AttrArray
value
when Hash
- VividMash.new(__root, value)
+ VividMash.new(value, __root)
when Array
- AttrArray.new(__root, value)
+ AttrArray.new(value, __root)
else
value
end
@@ -150,7 +150,8 @@ class Chef
end
end
- def initialize(root = self, data = {})
+ def initialize(data = {}, root = self)
+ puts caller unless root.class == Chef::Node::Attribute
@__root ||= root
super(data)
end
@@ -159,7 +160,7 @@ class Chef
__root.top_level_breadcrumb ||= key
value = super
if !key?(key)
- value = self.class.new(__root)
+ value = self.class.new({}, __root)
self[key] = value
else
value
@@ -208,9 +209,9 @@ class Chef
when AttrArray
value
when Hash
- VividMash.new(__root, value)
+ VividMash.new(value, __root)
when Array
- AttrArray.new(__root, value)
+ AttrArray.new(value, __root)
else
value
end
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index 9d34048c79..50ac8daf93 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -52,7 +52,7 @@ class Chef
alias :internal_push :<<
private :internal_push
- def initialize(array_data, root = self)
+ def initialize(array_data = [], root = self)
@__root = root
array_data.each do |value|
internal_push(immutablize(value))
@@ -114,7 +114,7 @@ class Chef
alias :internal_set :[]=
private :internal_set
- def initialize(mash_data, root = self)
+ def initialize(mash_data = {}, root = self)
@__root = root
mash_data.each do |key, value|
internal_set(key, immutablize(value))
diff --git a/lib/chef/node/mixin/state_tracking.rb b/lib/chef/node/mixin/state_tracking.rb
index fed040ed92..7472d2a67d 100644
--- a/lib/chef/node/mixin/state_tracking.rb
+++ b/lib/chef/node/mixin/state_tracking.rb
@@ -23,7 +23,7 @@ class Chef
attr_reader :__root
def initialize(*args)
- super
+ super(*args)
@__path ||= []
@__root ||= self
end
diff --git a/spec/unit/node/vivid_mash_spec.rb b/spec/unit/node/vivid_mash_spec.rb
index 206b15ef6c..eb22929685 100644
--- a/spec/unit/node/vivid_mash_spec.rb
+++ b/spec/unit/node/vivid_mash_spec.rb
@@ -27,8 +27,9 @@ describe Chef::Node::VividMash do
let(:vivid) do
expect(root).to receive(:reset_cache).at_least(:once).with(nil)
- Chef::Node::VividMash.new(root,
- { "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => nil }
+ Chef::Node::VividMash.new(
+ { "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => nil },
+ root
)
end