lib/chef/sugar/node.rb in chef-sugar-2.0.0 vs lib/chef/sugar/node.rb in chef-sugar-2.1.0
- old
+ new
@@ -128,13 +128,11 @@
#
# @return [nil]
# to prevent accidential method chaining if the block isn't closed
#
def namespace(*args, &block)
- @namespace_options = {
- precedence: default
- }.merge(args.last.is_a?(Hash) ? args.pop : {})
+ @namespace_options = namespace_options.merge(args.last.is_a?(Hash) ? args.pop : {})
keys = args.map(&:to_s)
@current_namespace = current_namespace + keys
instance_eval(&block)
@@ -160,10 +158,21 @@
end
private
#
+ # The namespace options.
+ #
+ # @return [Hash]
+ #
+ def namespace_options
+ @namespace_options ||= {
+ precedence: default
+ }
+ end
+
+ #
# The current namespace. This is actually a reverse-ordered array that
# vivifies the correct hash.#
#
# @return [Array<String>]
#
@@ -176,10 +185,10 @@
# for non-existent keys in the hash is a new, empty hash.
#
# @return [Hash<String, Hash>]
#
def vivified
- current_namespace.inject(@namespace_options[:precedence]) do |hash, item|
+ current_namespace.inject(namespace_options[:precedence]) do |hash, item|
hash[item] ||= {}
hash[item]
end
end
end