class Puppet::Generate::Models::Type::Property

A model for resource type properties and parameters.

Attributes

doc[R]

Gets the doc string of the property.

name[R]

Gets the name of the property as a Puppet string literal.

type[R]

Gets the Puppet type of the property.

Public Class Methods

get_puppet_type(property) click to toggle source

Gets the Puppet type for a property. @param property [Puppet::Property] The Puppet property to get the Puppet type for. @return [String] Returns the string representing the Puppet type.

   # File lib/puppet/generate/models/type/property.rb
35 def self.get_puppet_type(property)
36   # HACK: the value collection does not expose the underlying value information at all
37   #       thus this horribleness to get the underlying values hash
38   regexes = []
39   strings = []
40   values = property.value_collection.instance_variable_get('@values') || {}
41   values.each do |_, value|
42     if value.regex?
43       regexes << Puppet::Pops::Types::StringConverter.convert(value.name, '%p')
44       next
45     end
46 
47     strings << Puppet::Pops::Types::StringConverter.convert(value.name.to_s, '%p')
48     value.aliases.each do |a|
49       strings << Puppet::Pops::Types::StringConverter.convert(a.to_s, '%p')
50     end
51   end
52 
53   # If no string or regexes, default to Any type
54   return 'Any' if strings.empty? && regexes.empty?
55 
56   # Calculate a variant of supported values
57   # Note that boolean strings are mapped to Variant[Boolean, Enum['true', 'false']]
58   # because of tech debt...
59   enum    = strings.empty? ? nil : "Enum[#{strings.join(', ')}]"
60   pattern = regexes.empty? ? nil : "Pattern[#{regexes.join(', ')}]"
61   boolean = strings.include?('\'true\'') || strings.include?('\'false\'') ? 'Boolean' : nil
62   variant = [boolean, enum, pattern].reject { |t| t.nil? }
63   return variant[0] if variant.size == 1
64   "Variant[#{variant.join(', ')}]"
65 end
new(property) click to toggle source

Initializes a property model. @param property [Puppet::Property] The Puppet property to model. @return [void]

   # File lib/puppet/generate/models/type/property.rb
19 def initialize(property)
20   @name = Puppet::Pops::Types::StringConverter.convert(property.name.to_s, '%p')
21   @type = self.class.get_puppet_type(property)
22   @doc = property.doc.strip
23   @is_namevar = property.isnamevar?
24 end

Public Instance Methods

is_namevar?() click to toggle source

Determines if this property is a namevar. @return [Boolean] Returns true if the property is a namevar or false if not.

   # File lib/puppet/generate/models/type/property.rb
28 def is_namevar?
29   @is_namevar
30 end