module Poise::Utils::ResourceProviderMixin
A mixin to dispatch other mixins with resource and provider implementations. The module this is included in must have Resource
and Provider
sub-modules.
@since 2.0.0 @example
module MyHelper include Poise::Utils::ResourceProviderMixin module Resource # ... end module Provider # ... end end
Public Class Methods
included(klass)
click to toggle source
Calls superclass method
# File lib/poise/utils/resource_provider_mixin.rb, line 37 def self.included(klass) # Warning here be dragons. # Create a new anonymous module, klass will be the module that # actually included ResourceProviderMixin. We want to keep a reference # to that locked down so that we can close over it and use it in the # "real" .included defined below to find the original relative consts. mod = Module.new do # Use define_method instead of def so we can close over klass and mod. define_method(:included) do |inner_klass| # Has to be explicit because super inside define_method. super(inner_klass) # Cargo this .included to things which include us. inner_klass.extend(mod) # Dispatch to submodules, inner_klass is the most recent includer. if inner_klass < Chef::Resource || inner_klass.name.to_s.end_with?('::Resource') # Use klass::Resource to look up relative to the original module. inner_klass.class_exec { include klass::Resource } elsif inner_klass < Chef::Provider || inner_klass.name.to_s.end_with?('::Provider') # As above, klass::Provider. inner_klass.class_exec { include klass::Provider } end end end # Add our .included to the original includer. klass.extend(mod) end