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

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.actions(*names) ⇒ Object

Since:

  • 1.0.0



48
49
50
51
52
# File 'lib/poise/helpers/lwrp_polyfill.rb', line 48

def actions(*names)
  @actions ||= ( respond_to?(:superclass) && superclass.respond_to?(:actions) ? superclass.actions.dup : [] )
  (@actions << names).flatten!.uniq!
  @actions
end

.attribute(name, opts) ⇒ Object

Since:

  • 1.0.0



54
55
56
57
58
59
60
# File 'lib/poise/helpers/lwrp_polyfill.rb', line 54

def attribute(name, opts)
  # 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(name = nil) ⇒ Object

Since:

  • 1.0.0



40
41
42
43
44
45
46
# File 'lib/poise/helpers/lwrp_polyfill.rb', line 40

def default_action(name=nil)
  if name
    @default_action = name
    actions(name)
  end
  @default_action || ( respond_to?(:superclass) && superclass.respond_to?(:default_action) && superclass.default_action ) || actions.first || :nothing
end

Instance Method Details

#initialize(*args) ⇒ Object

Since:

  • 1.0.0



31
32
33
34
35
36
# File 'lib/poise/helpers/lwrp_polyfill.rb', line 31

def initialize(*args)
  super
  # Try to not stomp on stuff if already set in a parent
  @action = self.class.default_action if @action == :nothing
  (@allowed_actions << self.class.actions).flatten!.uniq!
end