Class: Puppet::ResourceApi::TypeDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/resource_api/type_definition.rb

Overview

Provides accessor methods for the type being provided

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ TypeDefinition

Returns a new instance of TypeDefinition.

Raises:

  • (Puppet::DevError)


5
6
7
8
# File 'lib/puppet/resource_api/type_definition.rb', line 5

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

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



3
4
5
# File 'lib/puppet/resource_api/type_definition.rb', line 3

def definition
  @definition
end

Instance Method Details

#attributesObject



10
11
12
# File 'lib/puppet/resource_api/type_definition.rb', line 10

def attributes
  @definition[:attributes]
end

#ensurable?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/puppet/resource_api/type_definition.rb', line 14

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

#feature?(feature) ⇒ Boolean

rubocop complains when this is named has_feature?

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/puppet/resource_api/type_definition.rb', line 25

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

#namevarsObject



18
19
20
21
22
# File 'lib/puppet/resource_api/type_definition.rb', line 18

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