Module: Poise::Helpers::Subresources::Child::ClassMethods

Included in:
Poise::Helpers::Subresources::Child
Defined in:
lib/poise/helpers/subresources/child.rb

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#parent_attribute(name, type: Chef::Resource, optional: false, auto: true)

This method returns an undefined value.

Create a new kind of parent link.

Parameters:

  • name (Symbol)

    Name of the relationship. This becomes a method name on the resource instance.

  • type (Class) (defaults to: Chef::Resource)

    Class of the parent.

  • optional (Boolean) (defaults to: false)

    If the parent is optional.

  • auto (Boolean) (defaults to: true)

    If the parent is auto-detected.

Since:

  • 2.0.0



181
182
183
184
185
186
187
# File 'lib/poise/helpers/subresources/child.rb', line 181

def parent_attribute(name, type: Chef::Resource, optional: false, auto: true)
  name = :"parent_#{name}"
  (@parent_attributes ||= {})[name] = type
  define_method(name) do |val=nil|
    _parent(name, type, optional, auto, val)
  end
end

#parent_attributesHash<Symbol, Class>

Return the name of all parent relationships on this class.

Returns:

  • (Hash<Symbol, Class>)

Since:

  • 2.0.0



193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/poise/helpers/subresources/child.rb', line 193

def parent_attributes
  {}.tap do |attrs|
    # Grab superclass's attributes if possible.
    attrs.update(superclass.parent_attributes) if superclass.respond_to?(:parent_attributes)
    # 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_autoBoolean #parent_auto(val) ⇒ Boolean

Overloads:

  • #parent_autoBoolean

    Get the auto-detect mode for the default parent link on this resource.

    Returns:

    • (Boolean)
  • #parent_auto(val) ⇒ Boolean

    Set the auto-detect mode for the default parent link on this resource.

    Parameters:

    • val (Boolean)

      Mode to set.

    Returns:

    • (Boolean)

Since:

  • 1.0.0



161
162
163
164
165
166
167
168
169
170
# File 'lib/poise/helpers/subresources/child.rb', line 161

def parent_auto(val=nil)
  unless val.nil?
    @parent_auto = val
  end
  if @parent_auto.nil?
    superclass.respond_to?(:parent_auto) ? superclass.parent_auto : true
  else
    @parent_auto
  end
end

#parent_optionalBoolean #parent_optional(val) ⇒ Boolean

Overloads:

  • #parent_optionalBoolean

    Get the optional mode for the default parent link on this resource.

    Returns:

    • (Boolean)
  • #parent_optional(val) ⇒ Boolean

    Set the optional mode for the default parent link on this resource.

    Parameters:

    • val (Boolean)

      Mode to set.

    Returns:

    • (Boolean)

Since:

  • 1.0.0



143
144
145
146
147
148
149
150
151
152
# File 'lib/poise/helpers/subresources/child.rb', line 143

def parent_optional(val=nil)
  unless val.nil?
    @parent_optional = val
  end
  if @parent_optional.nil?
    superclass.respond_to?(:parent_optional) ? superclass.parent_optional : false
  else
    @parent_optional
  end
end

#parent_typeClass, Symbol #parent_type(type) ⇒ Class, Symbol

Overloads:

  • #parent_typeClass, Symbol

    Get the class of the default parent link on this resource.

    Returns:

    • (Class, Symbol)
  • #parent_type(type) ⇒ Class, Symbol

    Set the class of the default parent link on this resource.

    Parameters:

    • type (Class, Symbol)

      Class to set.

    Returns:

    • (Class, Symbol)

Since:

  • 1.0.0



128
129
130
131
132
133
134
# File 'lib/poise/helpers/subresources/child.rb', line 128

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
    @parent_type = type
  end
  @parent_type || (superclass.respond_to?(:parent_type) ? superclass.parent_type : Chef::Resource)
end