module Garcon::Resource::Blender::ClassMethods

Public Instance Methods

action(name, &block) click to toggle source

Define a provider action. The block should contain the usual provider code.

@param name [Symbol]

Name of the action.

@param block [Proc]

Action implementation.
# File lib/garcon/chef/resource/blender.rb, line 81
def action(name, &block)
  blender_actions[name.to_sym] = block
  actions(name.to_sym) if respond_to?(:actions)
end
blender_actions() click to toggle source

Storage accessor for blended action blocks. Maps action name to proc.

@return [Hash<Symbol, Proc>]

@api private

# File lib/garcon/chef/resource/blender.rb, line 91
def blender_actions
  (@blender_actions ||= {})
end
blender_provider_class() click to toggle source

Create a provider class for the blender actions in this resource. Inherits from the blender provider class of the resource’s superclass if present.

@return [Class]

@api private

# File lib/garcon/chef/resource/blender.rb, line 102
def blender_provider_class
  @blender_provider_class ||= begin
    provider_superclass = begin
      self.superclass.blender_provider_class
    rescue NoMethodError
      Chef::Provider
    end
    actions = blender_actions
    class_name = self.name
    Class.new(provider_superclass) do
      include Garcon
      define_singleton_method(:name) { class_name + ' (blender)' }
      actions.each do |action, block|
        define_method(:"action_#{action}", &block)
      end
    end
  end
end
included(descendant) click to toggle source

Hook called when module is included, extends a descendant with class and instance methods.

@param [Module] descendant

The module or class including Garcon::Resource::Blender

@return [self]

@api private

Calls superclass method Garcon::included
# File lib/garcon/chef/resource/blender.rb, line 130
def included(descendant)
  super
  descendant.extend ClassMethods
end