summaryrefslogtreecommitdiff
path: root/lib/chef/mixin/provides.rb
blob: c39c53a1901a4414c2d8eb9ee86723feb0ee2aad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

require 'chef/mixin/descendants_tracker'

class Chef
  module Mixin
    module Provides
      include Chef::Mixin::DescendantsTracker

      def node_map
        @node_map ||= Chef::NodeMap.new
      end

      def provides(short_name, opts={}, &block)
        if !short_name.kind_of?(Symbol)
          # YAGNI: this is probably completely unnecessary and can be removed?
          Chef::Log.deprecation "Passing a non-Symbol to Chef::Resource#provides will be removed"
          if short_name.kind_of?(String)
            short_name.downcase!
            short_name.gsub!(/\s/, "_")
          end
          short_name = short_name.to_sym
        end
        node_map.set(short_name, true, opts, &block)
      end

      # Check whether this resource provides the resource_name DSL for the given
      # node
      def provides?(node, resource_name)
        resource_name = resource_name.resource_name if resource_name.is_a?(Chef::Resource)
        node_map.get(node, resource_name)
      end

      # Get the list of recipe DSL this resource is responsible for on the given
      # node.
      def provided_as(node)
        node_map.list(node)
      end
    end
  end
end