summaryrefslogtreecommitdiff
path: root/lib/chef/node_map.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-05 14:01:01 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-08 09:01:55 -0700
commitc65de79dbd662d895c8a10ef496d7eb9c69376c2 (patch)
treec0d171b5e87bd103660369a7497972e695379d1b /lib/chef/node_map.rb
parent01f575ce28a55dcdc7b3945c5f49ebb652a1fff3 (diff)
downloadchef-c65de79dbd662d895c8a10ef496d7eb9c69376c2.tar.gz
Overwrite resource_name with provides
Diffstat (limited to 'lib/chef/node_map.rb')
-rw-r--r--lib/chef/node_map.rb35
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index 4aed6f94e4..18f55da835 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -68,14 +68,13 @@ class Chef
# Get a value from the NodeMap via applying the node to the filters that
# were set on the key.
#
- # @param node [Chef::Node] The Chef::Node object for the run
+ # @param node [Chef::Node] The Chef::Node object for the run, or `nil` to
+ # ignore all filters.
# @param key [Object] Key to look up
- # @param canonical [Boolean] Whether to look up only the canonically provided
- # DSL (i.e. look up resource_name)
#
# @return [Object] Value
#
- def get(node, key, canonical: nil)
+ def get(node, key)
# FIXME: real exception
raise "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil?
list(node, key, canonical: canonical).first
@@ -85,26 +84,34 @@ class Chef
# List all matches for the given node and key from the NodeMap, from
# most-recently added to oldest.
#
- # @param node [Chef::Node] The Chef::Node object for the run
+ # @param node [Chef::Node] The Chef::Node object for the run, or `nil` to
+ # ignore all filters.
# @param key [Object] Key to look up
- # @param canonical [Boolean] Whether to look up only the canonically provided
- # DSL (i.e. look up resource_name)
#
# @return [Object] Value
#
- def list(node, key, canonical: nil)
+ def list(node, key)
# FIXME: real exception
raise "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil?
return [] unless @map.has_key?(key)
@map[key].select do |matcher|
- filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block]) &&
- (!canonical || matcher[:canonical])
+ !node || (filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block]))
end.map { |matcher| matcher[:value] }
end
+ # Seriously, don't use this, it's nearly certain to change on you
+ # @return remaining
# @api private
- def delete_if(key, &block)
- @map[key].delete_if(&block)
+ def delete_canonical(key)
+ remaining = @map[key]
+ if remaining
+ remaining.delete_if { |matcher| matcher[:canonical] }
+ if remaining.empty?
+ @map.delete(key)
+ remaining = nil
+ end
+ end
+ remaining
end
private
@@ -142,7 +149,7 @@ class Chef
# spend any time here.
return true if !filters[attribute]
filter_values = Array(filters[attribute])
- value = node ? node[attribute] : nil
+ value = node[attribute]
# Split the blacklist and whitelist
blacklist, whitelist = filter_values.partition { |v| v.is_a?(String) && v.start_with?('!') }
@@ -159,7 +166,7 @@ class Chef
# spend any time here.
return true if !filters[attribute]
filter_values = Array(filters[attribute])
- value = node ? node[attribute] : nil
+ value = node[attribute]
filter_values.empty? ||
Array(filter_values).any? do |v|