summaryrefslogtreecommitdiff
path: root/lib/chef/node
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-10-25 14:17:59 -0700
committerdanielsdeleo <dan@opscode.com>2012-11-02 09:26:30 -0700
commit9aebc51a4e836bc7f993dca16dd5f926570ec86e (patch)
tree430270b02a10a6806914d80ff89bd46cccd4b9a3 /lib/chef/node
parent7d109ade7745863616cc3f4b4222592adcbb7539 (diff)
downloadchef-9aebc51a4e836bc7f993dca16dd5f926570ec86e.tar.gz
[CHEF-2936] ensure all default and override attrs go in node json
default and override attributes are now split into components, so all the components need to be merged together to generate the serialized representation of a node. Unfortunately, this means that serializing a node is now lossy because the information about which component default and override attributes belong to is lost. In practice, this is not a major issue, since automatic, override, and default attributes are cleared by chef for each run.
Diffstat (limited to 'lib/chef/node')
-rw-r--r--lib/chef/node/attribute.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index c20abf532e..854a6fe971 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -49,6 +49,19 @@ class Chef
:@automatic
].freeze
+ DEFAULT_COMPONENTS = [
+ :@default,
+ :@env_default,
+ :@role_default
+ ]
+
+
+ OVERRIDE_COMPONENTS = [
+ :@override,
+ :@role_override,
+ :@env_override
+ ]
+
attr_reader :serial_number
[:all?,
@@ -173,6 +186,8 @@ class Chef
@automatic = VividMash.new(self, automatic)
@merged_attributes = nil
+ @combined_override = nil
+ @combined_default = nil
end
# Enables or disables `||=`-like attribute setting. See, e.g., Node#set_unless
@@ -187,6 +202,8 @@ class Chef
def reset_cache
@serial_number += 1
@merged_attributes = nil
+ @combined_default = nil
+ @combined_override = nil
end
alias :reset :reset_cache
@@ -248,6 +265,26 @@ class Chef
end
end
+ def combined_override
+ @combined_override ||= begin
+ resolved_attrs = OVERRIDE_COMPONENTS.inject(Mash.new) do |merged, component_ivar|
+ component_value = instance_variable_get(component_ivar)
+ Chef::Mixin::DeepMerge.merge(merged, component_value)
+ end
+ immutablize(self, resolved_attrs)
+ end
+ end
+
+ def combined_default
+ @combined_default ||= begin
+ resolved_attrs = DEFAULT_COMPONENTS.inject(Mash.new) do |merged, component_ivar|
+ component_value = instance_variable_get(component_ivar)
+ Chef::Mixin::DeepMerge.merge(merged, component_value)
+ end
+ immutablize(self, resolved_attrs)
+ end
+ end
+
def [](key)
merged_attributes[key]
end