summaryrefslogtreecommitdiff
path: root/lib/chef/node/attribute.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-01-29 15:34:57 -0800
committerdanielsdeleo <dan@opscode.com>2013-01-29 15:36:08 -0800
commit01dde6e1958d236d1e2bd70b3b7efb263bac6daf (patch)
treefdf629e6d286ebf7e8fc9ea8f7646c60a09e5b71 /lib/chef/node/attribute.rb
parent66d5a5bb0db640198e2077f699224b504dc127d7 (diff)
downloadchef-01dde6e1958d236d1e2bd70b3b7efb263bac6daf.tar.gz
[CHEF-3806] add attribute value debug
Diffstat (limited to 'lib/chef/node/attribute.rb')
-rw-r--r--lib/chef/node/attribute.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index e2bb8b9cf9..a417406721 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -209,6 +209,34 @@ class Chef
@combined_default = nil
end
+ # Debug what's going on with an attribute. +args+ is a path spec to the
+ # attribute you're interested in. For example, to debug where the value
+ # of `node[:network][:default_interface]` is coming from, use:
+ # debug_value(:network, :default_interface).
+ # The return value is an Array of Arrays. The first element is
+ # `["set_unless_enabled?", Boolean]`, which describes whether the
+ # attribute collection is in "set_unless" mode. The rest of the Arrays
+ # are pairs of `["precedence_level", value]`, where precedence level is
+ # the component, such as role default, normal, etc. and value is the
+ # attribute value set at that precedence level. If there is no value at
+ # that precedence level, +value+ will be the symbol +:not_present+.
+ def debug_value(*args)
+ components = COMPONENTS.map do |component|
+ ivar = instance_variable_get(component)
+ value = args.inject(ivar) do |so_far, key|
+ if so_far == :not_present
+ :not_present
+ elsif so_far.has_key?(key)
+ so_far[key]
+ else
+ :not_present
+ end
+ end
+ [component.to_s.sub(/^@/,""), value]
+ end
+ [["set_unless_enabled?", @set_unless_present]] + components
+ end
+
# Enables or disables `||=`-like attribute setting. See, e.g., Node#set_unless
def set_unless_value_present=(setting)
@set_unless_present = setting