summaryrefslogtreecommitdiff
path: root/chef/lib/chef/node
diff options
context:
space:
mode:
authorAdam Jacob <adam@opscode.com>2009-08-09 11:46:25 -0700
committerAJ Christensen <aj@opscode.com>2009-08-10 15:43:20 +1200
commit1dc31638dcc4271b9e2cbf47a6ce032c77ac9d7b (patch)
treee55b8cfd1423399abe9939df6c680d1ba03341df /chef/lib/chef/node
parent30f31903d992ae17c628bce08162a9d35466f0fb (diff)
downloadchef-1dc31638dcc4271b9e2cbf47a6ce032c77ac9d7b.tar.gz
Fixing Chef-477, by making the Chef::Node::Attribute object Enumerable, and making each behave like normal
Diffstat (limited to 'chef/lib/chef/node')
-rw-r--r--chef/lib/chef/node/attribute.rb29
1 files changed, 20 insertions, 9 deletions
diff --git a/chef/lib/chef/node/attribute.rb b/chef/lib/chef/node/attribute.rb
index 2394db0bd6..dc707405bc 100644
--- a/chef/lib/chef/node/attribute.rb
+++ b/chef/lib/chef/node/attribute.rb
@@ -24,6 +24,8 @@ class Chef
class Attribute
attr_accessor :attribute, :default, :override, :state, :current_attribute, :current_default, :current_override, :auto_vivifiy_on_read, :set_unless_value_present, :has_been_read
+ include Enumerable
+
def initialize(attribute, default, override, state=[])
@attribute = attribute
@current_attribute = attribute
@@ -83,20 +85,29 @@ class Chef
end
def get_keys
- keys = current_override.keys
- current_attribute.keys.each do |key|
- keys << key unless keys.include?(key)
+ keys
+ end
+
+ def keys
+ tkeys = []
+ if current_override
+ tkeys = current_override.keys
end
- current_default.keys.each do |key|
- keys << key unless keys.include?(key)
+ if current_attribute
+ current_attribute.keys.each do |key|
+ tkeys << key unless tkeys.include?(key)
+ end
end
- keys
+ if current_default
+ current_default.keys.each do |key|
+ tkeys << key unless tkeys.include?(key)
+ end
+ end
+ tkeys
end
def each(&block)
- get_keys.each do |k|
- block.call(k)
- end
+ each_attribute(&block)
end
def get_value(data_hash, key)