module Poise::Helpers::Inversion::Resource

Resource implementation for {Poise::Helpers::Inversion}. @see Poise::Helpers::Inversion

Public Instance Methods

options(provider=nil, val=nil) click to toggle source

@overload options(val=nil)

Set or return provider options for all providers.
@param val [Hash] Provider options to set.
@return [Hash]
@example
  my_resource 'thing_one' do
    options depends: 'thing_two'
  end

@overload options(provider, val=nil)

Set or return provider options for a specific provider.
@param provider [Symbol] Provider to set for.
@param val [Hash] Provider options to set.
@return [Hash]
@example
  my_resource 'thing_one' do
    options :my_provider, depends: 'thing_two'
  end
# File lib/poise/helpers/inversion.rb, line 60
def options(provider=nil, val=nil)
  key = :options
  if !val && provider.is_a?(Hash)
    val = provider
  elsif provider
    key = :"options_#{provider}"
  end
  set_or_return(key, val ? Mash.new(val) : val, kind_of: Hash, default: lazy { Mash.new })
end
provider(val=nil) click to toggle source

Allow setting the provider directly using the same names as the attribute settings.

@param val [String, Symbol, Class, nil] Value to set the provider to. @return [Class] @example

my_resource 'thing_one' do
  provider :my_provider
end
Calls superclass method
# File lib/poise/helpers/inversion.rb, line 79
def provider(val=nil)
  if val && !val.is_a?(Class)
    resource_names = [resource_name]
    # If subclass_providers! might be in play, check for those names too.
    resource_names.concat(self.class.subclass_resource_equivalents) if self.class.respond_to?(:subclass_resource_equivalents)
    # Silly ruby tricks to find the first provider that exists and no more.
    provider_class = resource_names.lazy.map {|name| Poise::Helpers::Inversion.provider_for(name, node, val) }.select {|x| x }.first
    Poise.debug("[#{self}] Checking for an inversion provider for #{val}: #{provider_class && provider_class.name}")
    val = provider_class if provider_class
  end
  super
end
provider_no_auto(val=nil) click to toggle source

Set or return the array of provider names to be blocked from auto-resolution.

@param val [String, Array<String>] Value to set. @return [Array<String>]

# File lib/poise/helpers/inversion.rb, line 97
def provider_no_auto(val=nil)
  # Coerce to an array.
  val = Array(val).map(&:to_s) if val
  set_or_return(:provider_no_auto, val, kind_of: Array, default: [])
end