Class: Puppet::ResourceApi::TransportSchemaDef

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

Overview

RSAPI Transport schema

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, #validate_schema

Constructor Details

#initialize(definition) ⇒ TransportSchemaDef

Returns a new instance of TransportSchemaDef.



47
48
49
# File 'lib/puppet/resource_api/type_definition.rb', line 47

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

Instance Method Details

#notify_schema_errors(message) ⇒ Object

Raises:

  • (Puppet::DevError)


67
68
69
# File 'lib/puppet/resource_api/type_definition.rb', line 67

def notify_schema_errors(message)
  raise Puppet::DevError, message
end

#validate(resource) ⇒ Object

Raises:

  • (Puppet::ResourceError)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/puppet/resource_api/type_definition.rb', line 51

def validate(resource)
  # enforce mandatory attributes
  missing_attrs = []

  attributes.each do |name, _options|
    type = @data_type_cache[attributes[name][:type]]

    if resource[name].nil? && !(type.instance_of? Puppet::Pops::Types::POptionalType)
      missing_attrs << name
    end
  end

  error_msg = "The following mandatory attributes were not provided:\n    *  " + missing_attrs.join(", \n    *  ")
  raise Puppet::ResourceError, error_msg if missing_attrs.any?
end