module Poise::Helpers::Subresources::Child::ClassMethods
Public Instance Methods
included(klass)
click to toggle source
@api private
Calls superclass method
# File lib/poise/helpers/subresources/child.rb, line 266 def included(klass) super klass.extend(ClassMethods) end
parent_attribute(name, type: Chef::Resource, optional: false, auto: true, default: nil)
click to toggle source
Create a new kind of parent link.
@since 2.0.0 @param name [Symbol] Name of the relationship. This becomes a method
name on the resource instance.
@param type [Class] Class of the parent. @param optional [Boolean] If the parent is optional. @param auto [Boolean] If the parent is auto-detected. @return [void]
# File lib/poise/helpers/subresources/child.rb, line 240 def parent_attribute(name, type: Chef::Resource, optional: false, auto: true, default: nil) name = :"parent_#{name}" (@parent_attributes ||= {})[name] = type define_method(name) do |*args| _parent(name, type, optional, auto, default, *args) end end
parent_attributes()
click to toggle source
Return the name of all parent relationships on this class.
@since 2.0.0 @return [Hash<Symbol, Class>]
# File lib/poise/helpers/subresources/child.rb, line 252 def parent_attributes {}.tap do |attrs| # Grab superclass's attributes if possible. attrs.update(Poise::Utils.ancestor_send(self, :parent_attributes, default: {})) # Local default parent. attrs[:parent] = parent_type # Extra locally defined parents. attrs.update(@parent_attributes) if @parent_attributes # Remove anything with the type set to true. attrs.reject! {|name, type| type == true } end end
parent_auto(val=nil)
click to toggle source
@overload parent_auto
()
Get the auto-detect mode for the default parent link on this resource. @return [Boolean]
@overload parent_auto
(val)
Set the auto-detect mode for the default parent link on this resource. @param val [Boolean] Mode to set. @return [Boolean]
# File lib/poise/helpers/subresources/child.rb, line 200 def parent_auto(val=nil) unless val.nil? @parent_auto = val end if @parent_auto.nil? Poise::Utils.ancestor_send(self, :parent_auto, default: true) else @parent_auto end end
parent_default(*args)
click to toggle source
@overload parent_default
()
Get the default value for the default parent link on this resource. @since 2.3.0 @return [Object, Chef::DelayedEvaluator]
@overload parent_default
(val)
Set the default value for the default parent link on this resource. @since 2.3.0 @param val [Object, Chef::DelayedEvaluator] Default value to set. @return [Object, Chef::DelayedEvaluator]
# File lib/poise/helpers/subresources/child.rb, line 220 def parent_default(*args) unless args.empty? @parent_default = args.first end if defined?(@parent_default) @parent_default else Poise::Utils.ancestor_send(self, :parent_default) end end
parent_optional(val=nil)
click to toggle source
@overload parent_optional
()
Get the optional mode for the default parent link on this resource. @return [Boolean]
@overload parent_optional
(val)
Set the optional mode for the default parent link on this resource. @param val [Boolean] Mode to set. @return [Boolean]
# File lib/poise/helpers/subresources/child.rb, line 182 def parent_optional(val=nil) unless val.nil? @parent_optional = val end if @parent_optional.nil? Poise::Utils.ancestor_send(self, :parent_optional, default: false) else @parent_optional end end
parent_type(type=nil)
click to toggle source
@overload parent_type
()
Get the class of the default parent link on this resource. @return [Class, Symbol]
@overload parent_type
(type)
Set the class of the default parent link on this resource. @param type [Class, Symbol] Class to set. @return [Class, Symbol]
# File lib/poise/helpers/subresources/child.rb, line 164 def parent_type(type=nil) if type raise Poise::Error.new("Parent type must be a class, symbol, or true, got #{type.inspect}") unless type.is_a?(Class) || type.is_a?(Symbol) || type == true # Setting to true shouldn't actually do anything if a type was already set. @parent_type = type unless type == true && !@parent_type.nil? end # First ancestor_send looks for a non-true && non-default value, # second one is to check for default vs true if no real value is found. @parent_type || Poise::Utils.ancestor_send(self, :parent_type, ignore: [Chef::Resource, true]) || Poise::Utils.ancestor_send(self, :parent_type, default: Chef::Resource) end