summaryrefslogtreecommitdiff
path: root/lib/chef/mixin/provides.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/mixin/provides.rb')
-rw-r--r--lib/chef/mixin/provides.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/chef/mixin/provides.rb b/lib/chef/mixin/provides.rb
new file mode 100644
index 0000000000..e5bb2c2005
--- /dev/null
+++ b/lib/chef/mixin/provides.rb
@@ -0,0 +1,32 @@
+
+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
+
+ # provides a node on the resource (early binding)
+ def provides?(node, resource_name)
+ node_map.get(node, resource_name)
+ end
+ end
+ end
+end