Class: Chef::NodeMap
Constant Summary collapse
- VALID_OPTS =
[ :on_platform, :on_platforms, :platform, :os, :platform_family, ]
- DEPRECATED_OPTS =
[ :on_platform, :on_platforms, ]
Instance Method Summary collapse
-
#get(node, key) ⇒ Object
Get a value from the NodeMap via applying the node to the filters that were set on the key.
-
#initialize ⇒ NodeMap
constructor
Create a new NodeMap.
-
#set(key, value, filters = {}) {|node| ... } ⇒ NodeMap
Set a key/value pair on the map with a filter.
Constructor Details
#initialize ⇒ NodeMap
Create a new NodeMap
37 38 39 |
# File 'lib/chef/node_map.rb', line 37 def initialize @map = {} end |
Instance Method Details
#get(node, key) ⇒ Object
Get a value from the NodeMap via applying the node to the filters that were set on the key.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/node_map.rb', line 68 def get(node, key) # FIXME: real exception raise "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) return nil unless @map.has_key?(key) @map[key].each do |matcher| if filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block]) return matcher[:value] end end nil end |
#set(key, value, filters = {}) {|node| ... } ⇒ NodeMap
Set a key/value pair on the map with a filter. The filter must be true when applied to the node in order to retrieve the value.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chef/node_map.rb', line 50 def set(key, value, filters = {}, &block) validate_filter!(filters) deprecate_filter!(filters) @map[key] ||= [] # we match on the first value we find, so we want to unshift so that the # last setter wins # FIXME: need a test for this behavior @map[key].unshift({ filters: filters, block: block, value: value }) self end |