module Poise::Helpers::LWRPPolyfill::Resource::ClassMethods
Public Instance Methods
actions(*names)
click to toggle source
@overload actions()
Get all actions allowed for this resource class. This includes any actions allowed on parent classes. @return [Array<Symbol>]
@overload actions(*names)
Set actions as allowed for this resource class. These must correspond with action methods in the provider class(es). @param names [Array<Symbol>] One or more actions to set. @return [Array<Symbol>] @example class MyApp < Chef::Resource include Poise actions(:install, :uninstall) end
# File lib/poise/helpers/lwrp_polyfill.rb, line 90 def actions(*names) @actions ||= ( respond_to?(:superclass) && superclass.respond_to?(:actions) && superclass.actions.dup ) || ( respond_to?(:superclass) && superclass != Chef::Resource && superclass.respond_to?(:allowed_actions) && superclass.allowed_actions.dup ) || [] (@actions << names).tap {|actions| actions.flatten!; actions.uniq! } end
attribute(name, opts={})
click to toggle source
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.
@param name [Symbol] Name of the property. @param opts [Hash<Symbol, Object>] Validation options and flags. @return [void] @example
class MyApp < Chef::Resource include Poise attribute(:path, name_attribute: true) attribute(:port, kind_of: Integer, default: 8080) end
# File lib/poise/helpers/lwrp_polyfill.rb, line 108 def attribute(name, opts={}) # Freeze the default value. This is done upstream too in Chef 12.5+. opts[:default].freeze if opts && opts[:default] # Ruby 1.8 can go to hell. define_method(name) do |arg=nil, &block| arg = block if arg.nil? # Try to allow passing either. set_or_return(name, arg, opts) end end
Also aliased as: property
default_action(name=nil)
click to toggle source
@overload default_action
()
Get the default action for this resource class. If no explicit default is set, the first action in the list will be used. @see #actions @return [Array<Symbol>]
@overload default_action
(name)
Set the default action for this resource class. If this action is not already allowed, it will be added. @note It is idiomatic to use {#actions} instead, with the first action specified being the default. @param name [Symbol, Array<Symbol>] Name of the action(s). @return [Array<Symbol>] @example class MyApp < Chef::Resource include Poise default_action(:install) end
# File lib/poise/helpers/lwrp_polyfill.rb, line 59 def default_action(name=nil) if name name = Array(name).flatten.map(&:to_sym) @default_action = name actions(*name) end if @default_action @default_action elsif respond_to?(:superclass) && superclass != Chef::Resource && superclass.respond_to?(:default_action) && superclass.default_action && Array(superclass.default_action) != %i{nothing} superclass.default_action elsif first_non_nothing = actions.find {|action| action != :nothing } [first_non_nothing] else %i{nothing} end end
included(klass)
click to toggle source
Calls superclass method
# File lib/poise/helpers/lwrp_polyfill.rb, line 121 def included(klass) super klass.extend(ClassMethods) end