Method: Chef::Provider.include_resource_dsl_module

Defined in:
lib/chef/provider.rb

.include_resource_dsl_module(resource) ⇒ 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.

Create the resource DSL module that forwards resource methods to new_resource



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/chef/provider.rb', line 424

def self.include_resource_dsl_module(resource)
  if include_resource_dsl? && !defined?(@included_resource_dsl_module)
    provider_class = self
    @included_resource_dsl_module = Module.new do
      extend Forwardable
      define_singleton_method(:to_s) { "forwarder module for #{provider_class}" }
      define_singleton_method(:inspect) { to_s }
      # this magic, stated simply, is that any instance method declared directly on
      # the resource we are building, will be accessible from the action_class(provider)
      # instance.  methods declared on Chef::Resource and properties are not inherited.
      dsl_methods =
        resource.class.public_instance_methods +
        resource.class.protected_instance_methods -
        provider_class.instance_methods -
        resource.class.properties.keys -
        resource.class.properties.keys.map { |k| "#{k}=".to_sym } -
        Chef::Resource.instance_methods
      def_delegators(:new_resource, *dsl_methods)
    end
    include @included_resource_dsl_module
  end
end