class Puppet::ResourceApi::TypeDefinition
RSAPI Resource Type
Public Class Methods
new(definition)
click to toggle source
Calls superclass method
Puppet::ResourceApi::BaseTypeDefinition::new
# File lib/puppet/resource_api/type_definition.rb, line 10 def initialize(definition) super(definition, :attributes) end
Public Instance Methods
create_attribute_in(type, attribute_name, param_or_property, parent, options)
click to toggle source
This call creates a new parameter or property with all work-arounds or customizations required by the Resource API applied. Under the hood, this maps to the relevant DSL methods in Puppet::Type. See puppet.com/docs/puppet/6.0/custom_types.html#reference-5883 for details.
type: the Resource API Type the attribute is being created in attribute_name: the name of the attribute being created param_or_property: Whether to call the :newparam or :newproperty method parent: The type of attribute to create: Property
, ReadOnly, or Parameter
options: The hash of attribute options, including type, desc, default, and behaviour
Calls superclass method
# File lib/puppet/resource_api/type_definition.rb, line 55 def create_attribute_in(type, attribute_name, param_or_property, parent, options) type.send(param_or_property, attribute_name.to_sym, parent: parent) do if options[:desc] desc "#{options[:desc]} (a #{options[:type]})" end # The initialize method is called when puppet core starts building up # type objects. The core passes in a hash of shape { resource: # #<Puppet::Type::TypeName> }. We use this to pass through the # required configuration data to the parent (see # Puppet::ResourceApi::Property, Puppet::ResourceApi::Parameter and # Puppet::ResourceApi::ReadOnlyParameter). define_method(:initialize) do |resource_hash| super(type.name, self.class.data_type, attribute_name, resource_hash, type) end # get pops data type object for this parameter or property define_singleton_method(:data_type) do @rsapi_data_type ||= Puppet::ResourceApi::DataTypeHandling.parse_puppet_type( attribute_name, options[:type], ) end # from ValueCreator call create_values which makes alias values and # default values for properties and params Puppet::ResourceApi::ValueCreator.create_values( self, data_type, param_or_property, options, ) end end
ensurable?()
click to toggle source
# File lib/puppet/resource_api/type_definition.rb, line 14 def ensurable? attributes.key?(:ensure) end
feature?(feature)
click to toggle source
rubocop complains when this is named has_feature?
# File lib/puppet/resource_api/type_definition.rb, line 19 def feature?(feature) definition[:features]&.include?(feature) end
title_patterns()
click to toggle source
# File lib/puppet/resource_api/type_definition.rb, line 23 def title_patterns definition[:title_patterns] ||= [] end
validate_schema(definition, attr_key)
click to toggle source
Calls superclass method
Puppet::ResourceApi::BaseTypeDefinition#validate_schema
# File lib/puppet/resource_api/type_definition.rb, line 27 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 custom_insync 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