diff options
author | Richard Manyanza <rm@dsc.co.tz> | 2014-03-17 21:49:04 +0300 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-10-22 14:22:09 -0700 |
commit | cb1bcb1f08816f551f96e713624718f58da3c9b3 (patch) | |
tree | 93458a3b13ea008f596249aa7ae8b1975bd0c1f9 /lib/chef/provider_resolver.rb | |
parent | 4db0ef42910d03209c7bb4b69f14e565c8c758ae (diff) | |
download | chef-cb1bcb1f08816f551f96e713624718f58da3c9b3.tar.gz |
Initial sketch for provider resolver
Diffstat (limited to 'lib/chef/provider_resolver.rb')
-rw-r--r-- | lib/chef/provider_resolver.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/chef/provider_resolver.rb b/lib/chef/provider_resolver.rb new file mode 100644 index 0000000000..91b85e3aa0 --- /dev/null +++ b/lib/chef/provider_resolver.rb @@ -0,0 +1,57 @@ +# +# Author:: Richard Manyanza (<liseki@nyikacraftsmen.com>) +# Copyright:: Copyright (c) 2014 Richard Manyanza. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class Chef + class ProviderResolver + + attr_reader :node + attr_reader :providers + + def initialize(node) + @node = node + @providers = [] + @loaded = false + end + + def load(reload = false) + return if loaded? && !reload + + @providers = [] if reload + + Chef::Provider.each do |provider| + @providers << provider if provider.supports_platform?(@node[:platform]) + end + + @loaded = true + end + + def loaded? + !!@loaded + end + + def resolve(resource) + self.load if !loaded? + + providers = @providers.find_all do |provider| + provider.enabled?(node) && provider.implements?(resource) + end + + resource.evaluate_providers(providers) + end + end +end |