Sha256: c1b9d3aee8d9c8a36260af1fb35206d38f057b096888ae5f5c681b14e37dd0d9

Contents?: true

Size: 943 Bytes

Versions: 1

Compression:

Stored size: 943 Bytes

Contents

# Provides accessor methods for the type being provided
class Puppet::ResourceApi::TypeDefinition
  attr_reader :definition

  def initialize(definition)
    raise Puppet::DevError, 'TypeDefinition requires definition to be a Hash' unless definition.is_a?(Hash)
    @definition = definition
  end

  def attributes
    @definition[:attributes]
  end

  def ensurable?
    @definition[:attributes].key?(:ensure)
  end

  def namevars
    @namevars ||= @definition[:attributes].select { |_name, options|
      options.key?(:behaviour) && options[:behaviour] == :namevar
    }.keys
  end

  # rubocop complains when this is named has_feature?
  def feature?(feature)
    supported = (definition[:features] && definition[:features].include?(feature))
    if supported
      Puppet.debug("#{definition[:name]} supports `#{feature}`")
    else
      Puppet.debug("#{definition[:name]} does not support `#{feature}`")
    end
    supported
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-resource_api-1.3.0 lib/puppet/resource_api/type_definition.rb