Class: Chef::ResourceResolver

Inherits:
Object
  • Object
show all
Includes:
Mixin::ConvertToClassName, Deprecated
Defined in:
lib/chef/resource_resolver.rb

Defined Under Namespace

Modules: Deprecated

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ConvertToClassName

#constantize, #convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #normalize_snake_case_name, #snake_case_basename

Methods included from Deprecated

#resources

Constructor Details

#initialize(node, resource_name, canonical: nil) ⇒ ResourceResolver

Create a resolver.

Parameters:

  • node (Chef::Node)

    The node against which to resolve. ‘nil` causes platform filters to be ignored.

  • resource_name (Symbol)

    The resource DSL name (e.g. ‘:file`).

  • canonical (Boolean) (defaults to: nil)

    ‘true` or `false` to match canonical or non-canonical values only. `nil` to ignore canonicality. Default: `nil`



76
77
78
79
80
# File 'lib/chef/resource_resolver.rb', line 76

def initialize(node, resource_name, canonical: nil)
  @node = node
  @resource_name = resource_name.to_sym
  @canonical = canonical
end

Instance Attribute Details

#actionObject (readonly)

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.



62
63
64
# File 'lib/chef/resource_resolver.rb', line 62

def action
  @action
end

#canonicalObject (readonly)

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.



64
65
66
# File 'lib/chef/resource_resolver.rb', line 64

def canonical
  @canonical
end

#nodeObject (readonly)

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.



53
54
55
# File 'lib/chef/resource_resolver.rb', line 53

def node
  @node
end

#resource_nameObject (readonly)

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.



55
56
57
# File 'lib/chef/resource_resolver.rb', line 55

def resource_name
  @resource_name
end

Class Method Details

.includes_handler?(resource_name, resource_class) ⇒ Boolean

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.

Whether the given handler attempts to provide the resource class at all.

Returns:

  • (Boolean)


119
120
121
# File 'lib/chef/resource_resolver.rb', line 119

def self.includes_handler?(resource_name, resource_class)
  handler_map.list(nil, resource_name).include?(resource_class)
end

.list(resource_name, node: nil, canonical: nil) ⇒ Object

Resolve a list of all resources that implement the given DSL (in order of preference).

Parameters:

  • resource_name (Symbol)

    The resource DSL name (e.g. ‘:file`).

  • node (Chef::Node) (defaults to: nil)

    The node against which to resolve. ‘nil` causes platform filters to be ignored.

  • canonical (Boolean) (defaults to: nil)

    ‘true` or `false` to match canonical or non-canonical values only. `nil` to ignore canonicality.



46
47
48
# File 'lib/chef/resource_resolver.rb', line 46

def self.list(resource_name, node: nil, canonical: nil)
  new(node, resource_name, canonical: canonical).list
end

.resolve(resource_name, node: nil, canonical: nil) ⇒ Object

Resolve a resource by name.

Parameters:

  • resource_name (Symbol)

    The resource DSL name (e.g. ‘:file`).

  • node (Chef::Node) (defaults to: nil)

    The node against which to resolve. ‘nil` causes platform filters to be ignored.



32
33
34
# File 'lib/chef/resource_resolver.rb', line 32

def self.resolve(resource_name, node: nil, canonical: nil)
  new(node, resource_name, canonical: canonical).resolve
end

Instance Method Details

#listObject

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.



99
100
101
102
# File 'lib/chef/resource_resolver.rb', line 99

def list
  Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}"
  prioritized_handlers
end

#provided_by?(resource_class) ⇒ Boolean

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.

Whether this DSL is provided by the given resource_class.

Does NOT call provides? on the resource (it is assumed this is being called from provides?).

Returns:

  • (Boolean)


111
112
113
# File 'lib/chef/resource_resolver.rb', line 111

def provided_by?(resource_class)
  potential_handlers.include?(resource_class)
end

#resolveObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/chef/resource_resolver.rb', line 83

def resolve
  # log this so we know what resources will work for the generic resource on the node (early cut)
  Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}"

  handler = prioritized_handlers.first

  if handler
    Chef::Log.debug "Resource for #{resource_name} is #{handler}"
  else
    Chef::Log.debug "Dynamic resource resolver FAILED to resolve a resource for #{resource_name}"
  end

  handler
end

#resourceObject

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.



57
58
59
60
# File 'lib/chef/resource_resolver.rb', line 57

def resource
  Chef.log_deprecation("Chef::ResourceResolver.resource deprecated.  Use resource_name instead.")
  resource_name
end