Module: Poise::Utils::ResourceProviderMixin
- Included in:
- Poise, Helpers::Inversion, Helpers::LWRPPolyfill
- Defined in:
- lib/poise/utils/resource_provider_mixin.rb
Overview
A mixin to dispatch other mixins with resource and provider implementations. The module this is included in must have Resource and Provider sub-modules.
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 # Use klass::Resource to look up relative to the original module. inner_klass.class_exec { include klass::Resource } elsif inner_klass < Chef::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 |