Class: Chef::ProviderResolver
- Inherits:
-
Object
- Object
- Chef::ProviderResolver
- Defined in:
- lib/chef/provider_resolver.rb
Overview
Provider Resolution
Provider resolution is the process of taking a Resource object and an action, and determining the Provider class that should be instantiated to handle the action.
If the resource has its ‘provider` set, that is used.
Otherwise, we take the lists of Providers that have registered as providing the DSL through ‘provides :dsl_name, <filters>` or `Chef.set_resource_priority_array :dsl_name, <filters>`. We filter each list of Providers through:
-
The filters it was registered with (such as ‘os: ’linux’‘ or `platform_family: ’debian’‘)
-
‘provides?(node, resource)`
-
‘supports?(resource, action)`
Anything that passes the filter and returns ‘true` to provides and supports, is considered a match. The first matching Provider in the *most recently registered list* is selected and returned.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #enabled_handlers ⇒ Object
-
#initialize(node, resource, action) ⇒ ProviderResolver
constructor
A new instance of ProviderResolver.
-
#provided_by?(provider_class) ⇒ Boolean
Does NOT call provides? on the resource (it is assumed this is being called from provides?).
- #resolve ⇒ Object
-
#supported_handlers ⇒ Object
private
TODO deprecate this and allow actions to be passed as a filter to ‘provides` so we don’t have to have two separate things.
Constructor Details
#initialize(node, resource, action) ⇒ ProviderResolver
Returns a new instance of ProviderResolver.
53 54 55 56 57 |
# File 'lib/chef/provider_resolver.rb', line 53 def initialize(node, resource, action) @node = node @resource = resource @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
51 52 53 |
# File 'lib/chef/provider_resolver.rb', line 51 def action @action end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
49 50 51 |
# File 'lib/chef/provider_resolver.rb', line 49 def node @node end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
50 51 52 |
# File 'lib/chef/provider_resolver.rb', line 50 def resource @resource end |
Instance Method Details
#enabled_handlers ⇒ Object
72 73 74 |
# File 'lib/chef/provider_resolver.rb', line 72 def enabled_handlers @enabled_handlers ||= potential_handlers.select { |handler| !overrode_provides?(handler) || handler.provides?(node, resource) } end |
#provided_by?(provider_class) ⇒ Boolean
Does NOT call provides? on the resource (it is assumed this is being called from provides?).
68 69 70 |
# File 'lib/chef/provider_resolver.rb', line 68 def provided_by?(provider_class) potential_handlers.include?(provider_class) end |
#resolve ⇒ Object
59 60 61 62 63 64 |
# File 'lib/chef/provider_resolver.rb', line 59 def resolve maybe_explicit_provider(resource) || maybe_custom_resource(resource) || maybe_dynamic_provider_resolution(resource, action) || raise(Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource} on #{node["platform"]} version #{node["platform_version"]}") end |
#supported_handlers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO deprecate this and allow actions to be passed as a filter to ‘provides` so we don’t have to have two separate things.
79 80 81 |
# File 'lib/chef/provider_resolver.rb', line 79 def supported_handlers enabled_handlers.select { |handler| handler.supports?(resource, action) } end |