summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-09-28 10:10:27 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-10-25 09:29:29 -0700
commit19d46ebf8700df0d5668e9262f02aa2717101184 (patch)
treedb7635e51016698815ab949b6b76b8bbbac63af0
parent70336a154e62816fb11f09885ad93e67f001af0e (diff)
downloadchef-19d46ebf8700df0d5668e9262f02aa2717101184.tar.gz
savegame for more aggressive refactoring
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/node/attribute.rb2
-rw-r--r--lib/chef/node/attribute_collections.rb33
-rw-r--r--lib/chef/node/common_api.rb12
-rw-r--r--lib/chef/node/immutable_collections.rb6
-rw-r--r--lib/chef/node/mixin/state_tracking.rb4
5 files changed, 28 insertions, 29 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index d67571a6a8..8f2fdb7956 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -565,7 +565,7 @@ class Chef
return nil if components.compact.empty?
- components.inject(ImmutableMash.new({})) do |merged, component|
+ components.inject(ImmutableMash.new(self, {})) do |merged, component|
Chef::Mixin::DeepMerge.hash_only_merge!(merged, component)
end
end
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb
index b8dde7121c..529054ed94 100644
--- a/lib/chef/node/attribute_collections.rb
+++ b/lib/chef/node/attribute_collections.rb
@@ -64,15 +64,13 @@ class Chef
MUTATOR_METHODS.each do |mutator|
define_method(mutator) do |*args, &block|
ret = super(*args, &block)
- root.reset_cache(root.top_level_breadcrumb)
+ __root.reset_cache(__root.top_level_breadcrumb)
ret
end
end
- attr_reader :root
-
- def initialize(root, data)
- @root = root
+ def initialize(root = self, data = [])
+ @__root ||= root
super(data)
map! { |e| convert_value(e) }
end
@@ -97,9 +95,9 @@ class Chef
when AttrArray
value
when Hash
- VividMash.new(root, value)
+ VividMash.new(__root, value)
when Array
- AttrArray.new(root, value)
+ AttrArray.new(__root, value)
else
value
end
@@ -124,8 +122,6 @@ class Chef
# #fetch, work as normal).
# * attr_accessor style element set and get are supported via method_missing
class VividMash < Mash
- attr_reader :root
-
include CommonAPI
# Methods that mutate a VividMash. Each of them is overridden so that it
@@ -149,21 +145,22 @@ class Chef
# object.
MUTATOR_METHODS.each do |mutator|
define_method(mutator) do |*args, &block|
- root.reset_cache(root.top_level_breadcrumb)
+ __root.reset_cache(__root.top_level_breadcrumb)
super(*args, &block)
end
end
- def initialize(root, data = {})
- @root = root
+ def initialize(root = self, data = {})
+ @__root ||= root
super(data)
end
def [](key)
- root.top_level_breadcrumb ||= key
+ pp __root.class
+ __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
@@ -171,9 +168,9 @@ class Chef
end
def []=(key, value)
- root.top_level_breadcrumb ||= key
+ __root.top_level_breadcrumb ||= key
ret = super
- root.reset_cache(root.top_level_breadcrumb)
+ __root.reset_cache(__root.top_level_breadcrumb)
ret
end
@@ -212,9 +209,9 @@ class Chef
when AttrArray
value
when Hash
- VividMash.new(root, value)
+ VividMash.new(__root, value)
when Array
- AttrArray.new(root, value)
+ AttrArray.new(__root, value)
else
value
end
diff --git a/lib/chef/node/common_api.rb b/lib/chef/node/common_api.rb
index ce2c6b6878..6aae880667 100644
--- a/lib/chef/node/common_api.rb
+++ b/lib/chef/node/common_api.rb
@@ -32,7 +32,7 @@ class Chef
# - autovivifying / autoreplacing writer
# - non-container-ey intermediate objects are replaced with hashes
def write(*args, &block)
- root.top_level_breadcrumb = nil if respond_to?(:root)
+ __root.top_level_breadcrumb = nil if respond_to?(:__root)
value = block_given? ? yield : args.pop
last = args.pop
prev_memo = prev_key = nil
@@ -56,7 +56,7 @@ class Chef
# something that is not a container ("schema violation" issues).
#
def write!(*args, &block)
- root.top_level_breadcrumb = nil if respond_to?(:root)
+ __root.top_level_breadcrumb = nil if respond_to?(:__root)
value = block_given? ? yield : args.pop
last = args.pop
obj = args.inject(self) do |memo, key|
@@ -71,7 +71,7 @@ class Chef
# return true or false based on if the attribute exists
def exist?(*path)
- root.top_level_breadcrumb = nil if respond_to?(:root)
+ __root.top_level_breadcrumb = nil if respond_to?(:__root)
path.inject(self) do |memo, key|
return false unless valid_container?(memo, key)
if memo.is_a?(Hash)
@@ -103,7 +103,7 @@ class Chef
# non-autovivifying reader that throws an exception if the attribute does not exist
def read!(*path)
raise Chef::Exceptions::NoSuchAttribute unless exist?(*path)
- root.top_level_breadcrumb = nil if respond_to?(:root)
+ __root.top_level_breadcrumb = nil if respond_to?(:__root)
path.inject(self) do |memo, key|
memo[key]
end
@@ -112,10 +112,10 @@ class Chef
# FIXME:(?) does anyone really like the autovivifying reader that we have and wants the same behavior? readers that write? ugh...
def unlink(*path, last)
- root.top_level_breadcrumb = nil if respond_to?(:root)
+ __root.top_level_breadcrumb = nil if respond_to?(:__root)
hash = path.empty? ? self : read(*path)
return nil unless hash.is_a?(Hash) || hash.is_a?(Array)
- root.top_level_breadcrumb ||= last
+ __root.top_level_breadcrumb ||= last
hash.delete(last)
end
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index d071f2ba36..5773f681e4 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -52,7 +52,8 @@ class Chef
alias :internal_push :<<
private :internal_push
- def initialize(array_data)
+ def initialize(root = self, array_data = [])
+ @__root = root
array_data.each do |value|
internal_push(immutablize(value))
end
@@ -113,7 +114,8 @@ class Chef
alias :internal_set :[]=
private :internal_set
- def initialize(mash_data)
+ def initialize(root = self, mash_data = {})
+ @__root = root
mash_data.each do |key, value|
internal_set(key, immutablize(value))
end
diff --git a/lib/chef/node/mixin/state_tracking.rb b/lib/chef/node/mixin/state_tracking.rb
index 8f62469dc0..fed040ed92 100644
--- a/lib/chef/node/mixin/state_tracking.rb
+++ b/lib/chef/node/mixin/state_tracking.rb
@@ -24,8 +24,8 @@ class Chef
def initialize(*args)
super
- @__path = []
- @__root = self
+ @__path ||= []
+ @__root ||= self
end
def [](key)