Module: Poise::Helpers::LWRPPolyfill::Resource::ClassMethods
- Included in:
- Poise::Helpers::LWRPPolyfill::Resource
- Defined in:
- lib/poise/helpers/lwrp_polyfill.rb
Overview
Instance Method Summary collapse
- #actions(*names) ⇒ Object
-
#attribute(name, opts = {})
(also: #property)
Create a resource property (née attribute) on this resource class.
- #default_action(name = nil) ⇒ Object
- #included(klass) ⇒ Object
Instance Method Details
#actions ⇒ Array<Symbol> #actions(*names) ⇒ Array<Symbol>
90 91 92 93 |
# 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 = {}) Also known as: property
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.
108 109 110 111 112 113 114 115 116 |
# 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 |
#default_action ⇒ Array<Symbol> #default_action(name) ⇒ Array<Symbol>
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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) ⇒ Object
121 122 123 124 |
# File 'lib/poise/helpers/lwrp_polyfill.rb', line 121 def included(klass) super klass.extend(ClassMethods) end |