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 36 def self.get_puppet_type(property) 37 # HACK: the value collection does not expose the underlying value information at all 38 # thus this horribleness to get the underlying values hash 39 regexes = [] 40 strings = [] 41 values = property.value_collection.instance_variable_get('@values') || {} 42 values.each do |_, value| 43 if value.regex? 44 regexes << Puppet::Pops::Types::StringConverter.convert(value.name, '%p') 45 next 46 end 47 48 strings << Puppet::Pops::Types::StringConverter.convert(value.name.to_s, '%p') 49 value.aliases.each do |a| 50 strings << Puppet::Pops::Types::StringConverter.convert(a.to_s, '%p') 51 end 52 end 53 54 # If no string or regexes, default to Any type 55 return 'Any' if strings.empty? && regexes.empty? 56 57 # Calculate a variant of supported values 58 # Note that boolean strings are mapped to Variant[Boolean, Enum['true', 'false']] 59 # because of tech debt... 60 enum = strings.empty? ? nil : "Enum[#{strings.join(', ')}]" 61 pattern = regexes.empty? ? nil : "Pattern[#{regexes.join(', ')}]" 62 boolean = strings.include?('\'true\'') || strings.include?('\'false\'') ? 'Boolean' : nil 63 variant = [boolean, enum, pattern].reject { |t| t.nil? } 64 return variant[0] if variant.size == 1 65 "Variant[#{variant.join(', ')}]" 66 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 20 def initialize(property) 21 @name = Puppet::Pops::Types::StringConverter.convert(property.name.to_s, '%p') 22 @type = self.class.get_puppet_type(property) 23 @doc = property.doc.strip 24 @is_namevar = property.isnamevar? 25 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 29 def is_namevar? 30 @is_namevar 31 end