summaryrefslogtreecommitdiff
path: root/lib/chef/provider.rb
diff options
context:
space:
mode:
authorRichard Manyanza <rm@dsc.co.tz>2014-03-17 21:49:04 +0300
committerLamont Granquist <lamont@scriptkiddie.org>2014-10-22 14:22:09 -0700
commitcb1bcb1f08816f551f96e713624718f58da3c9b3 (patch)
tree93458a3b13ea008f596249aa7ae8b1975bd0c1f9 /lib/chef/provider.rb
parent4db0ef42910d03209c7bb4b69f14e565c8c758ae (diff)
downloadchef-cb1bcb1f08816f551f96e713624718f58da3c9b3.tar.gz
Initial sketch for provider resolver
Diffstat (limited to 'lib/chef/provider.rb')
-rw-r--r--lib/chef/provider.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index bdfe826944..7cfdf7cbe5 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -28,6 +28,54 @@ class Chef
include Chef::Mixin::WhyRun
include Chef::Mixin::ShellOut
+
+ class << self
+ include Enumerable
+
+ @@providers = []
+
+ attr_reader :implementations
+ attr_reader :supported_platforms
+
+ def inherited(klass)
+ @@providers << klass
+ end
+
+ def providers
+ @@providers
+ end
+
+ def each
+ providers.each { |provider| yield provider }
+ providers
+ end
+
+ def implements(*resources)
+ options = resources.last.is_a?(Hash) ? resources.pop : {}
+
+ @implementations = resources.map { |resource| resource.to_sym }
+ @supported_platforms = Array(options[:on_platforms] || :all)
+ end
+
+ def implements?(resource)
+ klass_name = resource.class.to_s.split('::').last
+ resource_name = klass_name.gsub(/([a-z0-9])([A-Z])/, '\1_\2').downcase
+
+ implementations && implementations.include?(resource_name.to_sym)
+ end
+
+ def supports_platform?(platform)
+ supported_platforms && (
+ supported_platforms.include?(:all) ||
+ supported_platforms.include?(platform.to_sym))
+ end
+
+ def enabled?(node)
+ true
+ end
+ end
+
+
attr_accessor :new_resource
attr_accessor :current_resource
attr_accessor :run_context