Class: Puppet::Generate::Models::Type::Property
- Defined in:
- lib/puppet/generate/models/type/property.rb
Overview
A model for resource type properties and parameters.
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Gets the doc string of the property.
-
#name ⇒ Object
readonly
Gets the name of the property as a Puppet string literal.
-
#type ⇒ Object
readonly
Gets the Puppet type of the property.
Class Method Summary collapse
-
.get_puppet_type(property) ⇒ String
Gets the Puppet type for a property.
Instance Method Summary collapse
-
#initialize(property) ⇒ void
constructor
Initializes a property model.
-
#is_namevar? ⇒ Boolean
Determines if this property is a namevar.
Constructor Details
#initialize(property) ⇒ void
Initializes a property model.
21 22 23 24 25 26 |
# File 'lib/puppet/generate/models/type/property.rb', line 21 def initialize(property) @name = Puppet::Pops::Types::StringConverter.convert(property.name.to_s, '%p') @type = self.class.get_puppet_type(property) @doc = property.doc.strip @is_namevar = property.isnamevar? end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Gets the doc string of the property.
16 17 18 |
# File 'lib/puppet/generate/models/type/property.rb', line 16 def doc @doc end |
#name ⇒ Object (readonly)
Gets the name of the property as a Puppet string literal.
10 11 12 |
# File 'lib/puppet/generate/models/type/property.rb', line 10 def name @name end |
#type ⇒ Object (readonly)
Gets the Puppet type of the property.
13 14 15 |
# File 'lib/puppet/generate/models/type/property.rb', line 13 def type @type end |
Class Method Details
.get_puppet_type(property) ⇒ String
Gets the Puppet type for a property.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/puppet/generate/models/type/property.rb', line 37 def self.get_puppet_type(property) # HACK: the value collection does not expose the underlying value information at all # thus this horribleness to get the underlying values hash regexes = [] strings = [] values = property.value_collection.instance_variable_get('@values') || {} values.each do |_, value| if value.regex? regexes << Puppet::Pops::Types::StringConverter.convert(value.name, '%p') next end strings << Puppet::Pops::Types::StringConverter.convert(value.name.to_s, '%p') value.aliases.each do |a| strings << Puppet::Pops::Types::StringConverter.convert(a.to_s, '%p') end end # If no string or regexes, default to Any type return 'Any' if strings.empty? && regexes.empty? # Calculate a variant of supported values # Note that boolean strings are mapped to Variant[Boolean, Enum['true', 'false']] # because of tech debt... enum = strings.empty? ? nil : "Enum[#{strings.join(', ')}]" pattern = regexes.empty? ? nil : "Pattern[#{regexes.join(', ')}]" boolean = strings.include?('\'true\'') || strings.include?('\'false\'') ? 'Boolean' : nil variant = [boolean, enum, pattern].compact return variant[0] if variant.size == 1 "Variant[#{variant.join(', ')}]" end |
Instance Method Details
#is_namevar? ⇒ Boolean
Determines if this property is a namevar.
30 31 32 |
# File 'lib/puppet/generate/models/type/property.rb', line 30 def is_namevar? @is_namevar end |