summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-10-07 16:47:43 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-10-25 09:29:29 -0700
commit9edd0113f2d046e051845cf1916fcf733d392791 (patch)
tree3d23e6552e610f3be6b860c487385e77c5b04cf4
parentcbbc1c722a662596189a1a0b9aeee584b3482873 (diff)
downloadchef-lcg/node-path-tracking.tar.gz
rename __path to __path__ and __node to __node__lcg/node-path-tracking
consistency with Unchain here: https://github.com/chef/chef/blob/master/lib/chef/decorator/unchain.rb#L23-L24 and with SimpleDelegator: https://ruby-doc.org/stdlib-2.1.0/libdoc/delegate/rdoc/SimpleDelegator.html#method-i-__getobj__ Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/node/attribute.rb2
-rw-r--r--lib/chef/node/attribute_collections.rb16
-rw-r--r--lib/chef/node/immutable_collections.rb4
-rw-r--r--lib/chef/node/mixin/state_tracking.rb30
-rw-r--r--spec/unit/node/vivid_mash_spec.rb2
-rw-r--r--spec/unit/node_spec.rb42
6 files changed, 48 insertions, 48 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index 67b114a270..2d6aff0b21 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -596,7 +596,7 @@ class Chef
end
end
- # needed for __path
+ # needed for __path__
def convert_key(key)
key.kind_of?(Symbol) ? key.to_s : key
end
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb
index 412fb52a48..b01b447978 100644
--- a/lib/chef/node/attribute_collections.rb
+++ b/lib/chef/node/attribute_collections.rb
@@ -94,15 +94,15 @@ class Chef
when AttrArray
value
when Hash
- VividMash.new(value, __root)
+ VividMash.new(value, __root__)
when Array
- AttrArray.new(value, __root)
+ AttrArray.new(value, __root__)
else
value
end
end
- # needed for __path
+ # needed for __path__
def convert_key(key)
key
end
@@ -143,7 +143,7 @@ class Chef
# object.
def delete(key, &block)
- send_reset_cache(__path + [ key ])
+ send_reset_cache(__path__ + [ key ])
super
end
@@ -161,7 +161,7 @@ class Chef
def [](key)
value = super
if !key?(key)
- value = self.class.new({}, __root)
+ value = self.class.new({}, __root__)
self[key] = value
else
value
@@ -170,7 +170,7 @@ class Chef
def []=(key, value)
ret = super
- send_reset_cache(__path + [ key ])
+ send_reset_cache(__path__ + [ key ])
ret
end
@@ -209,9 +209,9 @@ class Chef
when AttrArray
value
when Hash
- VividMash.new(value, __root)
+ VividMash.new(value, __root__)
when Array
- AttrArray.new(value, __root)
+ AttrArray.new(value, __root__)
else
value
end
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index 623290f287..938135cbee 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -27,9 +27,9 @@ class Chef
def immutablize(value)
case value
when Hash
- ImmutableMash.new(value, __root)
+ ImmutableMash.new(value, __root__)
when Array
- ImmutableArray.new(value, __root)
+ ImmutableArray.new(value, __root__)
else
value
end
diff --git a/lib/chef/node/mixin/state_tracking.rb b/lib/chef/node/mixin/state_tracking.rb
index 2447de1c16..9be102eeeb 100644
--- a/lib/chef/node/mixin/state_tracking.rb
+++ b/lib/chef/node/mixin/state_tracking.rb
@@ -19,24 +19,24 @@ class Chef
class Node
module Mixin
module StateTracking
- attr_reader :__path
- attr_reader :__root
+ attr_reader :__path__
+ attr_reader :__root__
NULL = Object.new
def initialize(data = NULL, root = self)
- # __path and __root must be nil when we call super so it knows
+ # __path__ and __root__ must be nil when we call super so it knows
# to avoid resetting the cache on construction
data == NULL ? super() : super(data)
- @__path = []
- @__root = root
+ @__path__ = []
+ @__root__ = root
end
def [](key)
ret = super
if ret.is_a?(StateTracking)
- ret.__path = __path + [ convert_key(key) ]
- ret.__root = __root
+ ret.__path__ = __path__ + [ convert_key(key) ]
+ ret.__root__ = __root__
end
ret
end
@@ -44,26 +44,26 @@ class Chef
def []=(key, value)
ret = super
if ret.is_a?(StateTracking)
- ret.__path = __path + [ convert_key(key) ]
- ret.__root = __root
+ ret.__path__ = __path__ + [ convert_key(key) ]
+ ret.__root__ = __root__
end
ret
end
protected
- def __path=(path)
- @__path = path
+ def __path__=(path)
+ @__path__ = path
end
- def __root=(root)
- @__root = root
+ def __root__=(root)
+ @__root__ = root
end
private
- def send_reset_cache(path = __path)
- __root.reset_cache(path.first) if !__root.nil? && __root.respond_to?(:reset_cache) && !path.nil?
+ def send_reset_cache(path = __path__)
+ __root__.reset_cache(path.first) if !__root__.nil? && __root__.respond_to?(:reset_cache) && !path.nil?
end
end
end
diff --git a/spec/unit/node/vivid_mash_spec.rb b/spec/unit/node/vivid_mash_spec.rb
index 0955b6b1c3..017e6206fc 100644
--- a/spec/unit/node/vivid_mash_spec.rb
+++ b/spec/unit/node/vivid_mash_spec.rb
@@ -36,7 +36,7 @@ describe Chef::Node::VividMash do
end
it "sets the root to the root object" do
- expect(vivid["one"]["two"].__root).to eql(vivid)
+ expect(vivid["one"]["two"].__root__).to eql(vivid)
end
it "does not send reset cache" do
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 70461e238b..cfc19db480 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1709,53 +1709,53 @@ describe Chef::Node do
end
end
- describe "path tracking via __path" do
+ describe "path tracking via __path__" do
it "works through hash keys" do
node.default["foo"] = { "bar" => { "baz" => "qux" } }
- expect(node["foo"]["bar"].__path).to eql(%w{foo bar})
+ expect(node["foo"]["bar"].__path__).to eql(%w{foo bar})
end
it "works through the default level" do
node.default["foo"] = { "bar" => { "baz" => "qux" } }
- expect(node.default["foo"]["bar"].__path).to eql(%w{foo bar})
+ expect(node.default["foo"]["bar"].__path__).to eql(%w{foo bar})
end
it "works through arrays" do
node.default["foo"] = [ { "bar" => { "baz" => "qux" } } ]
- expect(node["foo"][0].__path).to eql(["foo", 0])
- expect(node["foo"][0]["bar"].__path).to eql(["foo", 0, "bar"])
+ expect(node["foo"][0].__path__).to eql(["foo", 0])
+ expect(node["foo"][0]["bar"].__path__).to eql(["foo", 0, "bar"])
end
it "works through arrays at the default level" do
node.default["foo"] = [ { "bar" => { "baz" => "qux" } } ]
- expect(node.default["foo"][0].__path).to eql(["foo", 0])
- expect(node.default["foo"][0]["bar"].__path).to eql(["foo", 0, "bar"])
+ expect(node.default["foo"][0].__path__).to eql(["foo", 0])
+ expect(node.default["foo"][0]["bar"].__path__).to eql(["foo", 0, "bar"])
end
- # if we set __path in the initializer we'd get this wrong, this is why we
+ # if we set __path__ in the initializer we'd get this wrong, this is why we
# update the path on every #[] or #[]= operator
it "works on access when the node has been rearranged" do
node.default["foo"] = { "bar" => { "baz" => "qux" } }
a = node.default["foo"]
node.default["fizz"] = a
- expect(node["fizz"]["bar"].__path).to eql(%w{fizz bar})
- expect(node["foo"]["bar"].__path).to eql(%w{foo bar})
+ expect(node["fizz"]["bar"].__path__).to eql(%w{fizz bar})
+ expect(node["foo"]["bar"].__path__).to eql(%w{foo bar})
end
- # We have a problem because the __path is stored on in each node, but the
+ # We have a problem because the __path__ is stored on in each node, but the
# node can be wired up at multiple locations in the tree via pointers. One
# solution would be to deep-dup the value in `#[]=(key, value)` and fix the
- # __path on all the dup'd nodes. The problem is that this would create an
+ # __path__ on all the dup'd nodes. The problem is that this would create an
# unusual situation where after assignment, you couldn't mutate the thing you
# hand a handle on. I'm not entirely positive this behavior is the correct
# thing to support, but it is more hash-like (although if we start with a hash
# then convert_value does its thing and we *do* get dup'd on assignment). This
# behavior likely makes any implementation of a deep merge cache built over the
- # top of __path tracking have edge conditions where it will fail.
+ # top of __path__ tracking have edge conditions where it will fail.
#
# Removing this support would be a breaking change. The test is included here
# because it seems most likely that someone would break this behavior while trying
- # to fix __path behavior.
+ # to fix __path__ behavior.
it "does not dup in the background when a node is assigned" do
# get a handle on a vividmash (can't be a hash or else we convert_value it)
node.default["foo"] = { "bar" => { "baz" => "qux" } }
@@ -1770,27 +1770,27 @@ describe Chef::Node do
end
end
- describe "root tracking via __root" do
+ describe "root tracking via __root__" do
it "works through hash keys" do
node.default["foo"] = { "bar" => { "baz" => "qux" } }
- expect(node["foo"]["bar"].__root).to eql(node.attributes)
+ expect(node["foo"]["bar"].__root__).to eql(node.attributes)
end
it "works through the default level" do
node.default["foo"] = { "bar" => { "baz" => "qux" } }
- expect(node.default["foo"]["bar"].__root).to eql(node.attributes)
+ expect(node.default["foo"]["bar"].__root__).to eql(node.attributes)
end
it "works through arrays" do
node.default["foo"] = [ { "bar" => { "baz" => "qux" } } ]
- expect(node["foo"][0].__root).to eql(node.attributes)
- expect(node["foo"][0]["bar"].__root).to eql(node.attributes)
+ expect(node["foo"][0].__root__).to eql(node.attributes)
+ expect(node["foo"][0]["bar"].__root__).to eql(node.attributes)
end
it "works through arrays at the default level" do
node.default["foo"] = [ { "bar" => { "baz" => "qux" } } ]
- expect(node.default["foo"][0].__root).to eql(node.attributes)
- expect(node.default["foo"][0]["bar"].__root).to eql(node.attributes)
+ expect(node.default["foo"][0].__root__).to eql(node.attributes)
+ expect(node.default["foo"][0]["bar"].__root__).to eql(node.attributes)
end
end