module ChefCompat::CopiedFromChef::Chef::Resource::ActionClass

Public Class Methods

include_resource_dsl(include_resource_dsl) click to toggle source
# File files/lib/chef_compat/copied_from_chef.rb, line 23
def self.include_resource_dsl(include_resource_dsl)
end
included(other) click to toggle source
# File files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb, line 74
def self.included(other)
  other.extend(ClassMethods)
  other.use_inline_resources
  other.include_resource_dsl true
end
use_inline_resources() click to toggle source
# File files/lib/chef_compat/copied_from_chef.rb, line 21
def self.use_inline_resources
end

Public Instance Methods

load_current_resource() click to toggle source

If load_current_value! is defined on the resource, use that.

# File files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb, line 42
def load_current_resource
  if new_resource.respond_to?(:load_current_value!)
    # dup the resource and then reset desired-state properties.
    current_resource = new_resource.dup

    # We clear desired state in the copy, because it is supposed to be actual state.
    # We keep identity properties and non-desired-state, which are assumed to be
    # "control" values like `recurse: true`
    current_resource.class.properties.each do |name, property|
      if property.desired_state? && !property.identity? && !property.name_property?
        property.reset(current_resource)
      end
    end

    # Call the actual load_current_value! method. If it raises
    # CurrentValueDoesNotExist, set current_resource to `nil`.
    begin
      # If the user specifies load_current_value do |desired_resource|, we
      # pass in the desired resource as well as the current one.
      if current_resource.method(:load_current_value!).arity > 0
        current_resource.load_current_value!(new_resource)
      else
        current_resource.load_current_value!
      end
    rescue Chef::Exceptions::CurrentValueDoesNotExist
      current_resource = nil
    end
  end

  @current_resource = current_resource
end
to_s() click to toggle source
# File files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb, line 35
def to_s
  "#{new_resource || "<no resource>"} action #{action ? action.inspect : "<no action>"}"
end