Method: Poise::Helpers::ResourceName.provides

Defined in:
lib/poise/helpers/resource_name.rb

.provides(name, *args, &block)

This method returns an undefined value.

Set the DSL name for the the resource class.

Examples:

class MyResource < Chef::Resource
  include Poise::Resource::ResourceName
  provides(:my_resource)
end

Parameters:

  • name (Symbol)

    Name of the resource.

Since:

  • 1.0.0



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/poise/helpers/resource_name.rb', line 54

def provides(name, *args, &block)
  # Patch self.constantize so this can cope with anonymous classes.
  # This does require that the anonymous class define self.name though.
  if self.name && respond_to?(:constantize)
    old_constantize = instance_method(:constantize)
    define_singleton_method(:constantize) do |const_name|
      ( const_name == self.name ) ? self : old_constantize.bind(self).call(const_name)
    end
  end
  # Store the name for later.
  @provides_name ||= name
  # Call the original if present. The defined? is for old Chef.
  super(name, *args, &block) if defined?(super)
end