diff options
author | Adam Jacob <adam@opscode.com> | 2009-08-09 11:46:25 -0700 |
---|---|---|
committer | AJ Christensen <aj@opscode.com> | 2009-08-10 15:43:20 +1200 |
commit | 1dc31638dcc4271b9e2cbf47a6ce032c77ac9d7b (patch) | |
tree | e55b8cfd1423399abe9939df6c680d1ba03341df /chef/lib | |
parent | 30f31903d992ae17c628bce08162a9d35466f0fb (diff) | |
download | chef-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')
-rw-r--r-- | chef/lib/chef/node/attribute.rb | 29 |
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) |