module Poise::Helpers::Fused

Resource mixin to create “fused” resources where the resource and provider are implemented in the same class.

@since 2.0.0 @example

class Chef::Resource::MyResource < Chef::Resource
  include Poise(fused: true)
  attribute(:path, kind_of: String)
  attribute(:message, kind_of: String)
  action(:run) do
    file new_resource.path do
      content new_resource.message
    end
  end
end

Public Instance Methods

is_a?(klass) click to toggle source

Hack is_a? so that the DSL will consider this a Provider for the purposes of attaching enclosing_provider.

@api private @param klass [Class] @return [Boolean]

Calls superclass method
# File lib/poise/helpers/fused.rb, line 44
def is_a?(klass)
  if klass == Chef::Provider
    # Lies, damn lies, and Ruby code.
    true
  else
    super
  end
end
provider_for_action(action) click to toggle source

Hack provider_for_action so that the resource is also the provider.

@api private @param action [Symbol] @return [Chef::Provider]

Calls superclass method
# File lib/poise/helpers/fused.rb, line 58
def provider_for_action(action)
  provider(self.class.fused_provider_class) unless provider
  super
end