Class: Puppet::ResourceApi::TypeDefinition

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

Overview

RSAPI Resource Type

Instance Attribute Summary

Attributes inherited from BaseTypeDefinition

#attributes, #definition

Instance Method Summary collapse

Methods inherited from BaseTypeDefinition

#check_schema, #check_schema_keys, #check_schema_values, #name, #namevars, #notify_schema_errors

Constructor Details

#initialize(definition) ⇒ TypeDefinition

Returns a new instance of TypeDefinition.



8
9
10
# File 'lib/puppet/resource_api/type_definition.rb', line 8

def initialize(definition)
  super(definition, :attributes)
end

Instance Method Details

#ensurable?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/puppet/resource_api/type_definition.rb', line 12

def ensurable?
  attributes.key?(:ensure)
end

#feature?(feature) ⇒ Boolean

rubocop complains when this is named has_feature?

Returns:

  • (Boolean)


17
18
19
# File 'lib/puppet/resource_api/type_definition.rb', line 17

def feature?(feature)
  (definition[:features] && definition[:features].include?(feature))
end

#title_patternsObject



21
22
23
# File 'lib/puppet/resource_api/type_definition.rb', line 21

def title_patterns
  definition[:title_patterns] ||= []
end

#validate_schema(definition, attr_key) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet/resource_api/type_definition.rb', line 25

def validate_schema(definition, attr_key)
  super(definition, attr_key)
  [:title, :provider, :alias, :audit, :before, :consume, :export, :loglevel, :noop, :notify, :require, :schedule, :stage, :subscribe, :tag].each do |name|
    raise Puppet::DevError, 'must not define an attribute called `%{name}`' % { name: name.inspect } if definition[attr_key].key? name
  end
  if definition.key?(:title_patterns) && !definition[:title_patterns].is_a?(Array)
    raise Puppet::DevError, '`:title_patterns` must be an array, not `%{other_type}`' % { other_type: definition[:title_patterns].class }
  end

  Puppet::ResourceApi::DataTypeHandling.validate_ensure(definition)

  definition[:features] ||= []
  supported_features = %w[supports_noop canonicalize remote_resource simple_get_filter].freeze
  unknown_features = definition[:features] - supported_features
  Puppet.warning("Unknown feature detected: #{unknown_features.inspect}") unless unknown_features.empty?
end