Module: Poise::Helpers::LWRPPolyfill::Resource

Extended by:
ClassMethods
Included in:
ChefspecMatchers
Defined in:
lib/poise/helpers/lwrp_polyfill.rb

Overview

Provide default_action and actions like LWRPBase but better equipped for subclassing.

Since:

  • 1.0.0

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

#actionsArray<Symbol> #actions(*names) ⇒ Array<Symbol> Originally defined in module ClassMethods

Overloads:

  • #actionsArray<Symbol>

    Get all actions allowed for this resource class. This includes any actions allowed on parent classes.

    Returns:

    • (Array<Symbol>)
  • #actions(*names) ⇒ Array<Symbol>

    Set actions as allowed for this resource class. These must correspond with action methods in the provider class(es).

    Examples:

    class MyApp < Chef::Resource
      include Poise
      actions(:install, :uninstall)
    end

    Parameters:

    • names (Array<Symbol>)

      One or more actions to set.

    Returns:

    • (Array<Symbol>)

Since:

  • 1.0.0

.attribute(name, opts = {}) Also known as: property Originally defined in module ClassMethods

This method returns an undefined value.

Create a resource property (née attribute) on this resource class. This follows the same usage as the helper of the same name in Chef LWRPs.

Examples:

class MyApp < Chef::Resource
  include Poise
  attribute(:path, name_attribute: true)
  attribute(:port, kind_of: Integer, default: 8080)
end

Parameters:

  • name (Symbol)

    Name of the property.

  • opts (Hash<Symbol, Object>) (defaults to: {})

    Validation options and flags.

Since:

  • 1.0.0

#default_actionArray<Symbol> #default_action(name) ⇒ Array<Symbol> Originally defined in module ClassMethods

Overloads:

  • #default_actionArray<Symbol>

    Get the default action for this resource class. If no explicit default is set, the first action in the list will be used.

    Returns:

    • (Array<Symbol>)

    See Also:

  • #default_action(name) ⇒ Array<Symbol>
    Note:

    It is idiomatic to use #actions instead, with the first action specified being the default.

    Set the default action for this resource class. If this action is not already allowed, it will be added.

    Examples:

    class MyApp < Chef::Resource
      include Poise
      default_action(:install)
    end

    Parameters:

    • name (Symbol, Array<Symbol>)

      Name of the action(s).

    Returns:

    • (Array<Symbol>)

Since:

  • 1.0.0

.included(klass) ⇒ Object Originally defined in module ClassMethods

Since:

  • 1.0.0

Instance Method Details

#initialize(*args) ⇒ Object

Since:

  • 1.0.0



33
34
35
36
37
38
39
# File 'lib/poise/helpers/lwrp_polyfill.rb', line 33

def initialize(*args)
  super
  # Try to not stomp on stuff if already set in a parent. Coerce @action
  # to an array because this behavior may change in the future in Chef.
  @action = self.class.default_action if Array(@action) == [:nothing]
  (@allowed_actions << self.class.actions).flatten!.uniq!
end