Class: Puppet::Pops::Types::TypeFormatter
- Defined in:
- lib/puppet/pops/types/type_formatter.rb
Class Method Summary collapse
-
.singleton ⇒ TypeCalculator
private
The singleton instance.
-
.string(t) ⇒ String
Produces a String representation of the given type.
Instance Method Summary collapse
-
#alias_expanded_string(t) ⇒ Object
Produces a string representing the type where type aliases have been expanded.
-
#debug_string(t) ⇒ Object
Produces a debug string representing the type (possibly with more information that the regular string format).
- #hash_entry_PStructElement(t) ⇒ Object private
-
#string(t) ⇒ Object
Produces a string representing the type.
- #string_Module(t) ⇒ Object private
- #string_NilClass(t) ⇒ Object private
- #string_PAnyType(t) ⇒ Object private
- #string_PArrayType(t) ⇒ Object private
- #string_PBooleanType(t) ⇒ Object private
- #string_PCallableType(t) ⇒ Object private
- #string_PCatalogEntryType(t) ⇒ Object private
- #string_PCollectionType(t) ⇒ Object private
- #string_PDataType(t) ⇒ Object private
- #string_PDefaultType(t) ⇒ Object private
- #string_PEnumType(t) ⇒ Object private
- #string_PFloatType(t) ⇒ Object private
- #string_PHashType(t) ⇒ Object private
- #string_PHostClassType(t) ⇒ Object private
- #string_PIntegerType(t) ⇒ Object private
- #string_PIterableType(t) ⇒ Object private
- #string_PIteratorType(t) ⇒ Object private
- #string_PNotUndefType(t) ⇒ Object private
- #string_PNumericType(t) ⇒ Object private
- #string_POptionalType(t) ⇒ Object private
- #string_PPatternType(t) ⇒ Object private
- #string_PRegexpType(t) ⇒ Object private
- #string_PResourceType(t) ⇒ Object private
- #string_PRuntimeType(t) ⇒ Object private
- #string_PScalarType(t) ⇒ Object private
- #string_PStringType(t) ⇒ Object private
- #string_PStructType(t) ⇒ Object private
- #string_PTupleType(t) ⇒ Object private
- #string_PType(t) ⇒ Object private
- #string_PTypeAliasType(t) ⇒ Object private
- #string_PTypeReferenceType(t) ⇒ Object private
- #string_PUndefType(t) ⇒ Object private
- #string_PUnitType(t) ⇒ Object private
- #string_PVariantType(t) ⇒ Object private
- #string_String(t) ⇒ Object private
- #string_Symbol(t) ⇒ Object private
-
#to_s ⇒ Object
Debugging to_s to reduce the amount of output.
Class Method Details
.singleton ⇒ TypeCalculator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the singleton instance.
23 24 25 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 23 def self.singleton @singleton end |
.string(t) ⇒ String
Produces a String representation of the given type.
16 17 18 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 16 def self.string(t) @singleton.string(t) end |
Instance Method Details
#alias_expanded_string(t) ⇒ Object
Produces a string representing the type where type aliases have been expanded
37 38 39 40 41 42 43 44 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 37 def (t) @expand_aliases = true begin string(t) ensure @expand_aliases = false end end |
#debug_string(t) ⇒ Object
Produces a debug string representing the type (possibly with more information that the regular string format)
49 50 51 52 53 54 55 56 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 49 def debug_string(t) @debug = true begin string(t) ensure @debug = false end end |
#hash_entry_PStructElement(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 176 def hash_entry_PStructElement(t) k = t.key_type value_optional = t.value_type.assignable?(PUndefType::DEFAULT) key_string = if k.is_a?(POptionalType) # Output as literal String value_optional ? "'#{t.name}'" : string(k) else value_optional ? "NotUndef['#{t.name}']" : "'#{t.name}'" end [key_string, string(t.value_type)] end |
#string(t) ⇒ Object
Produces a string representing the type
30 31 32 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 30 def string(t) @@string_visitor.visit_this_0(self, t) end |
#string_Module(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 59 def string_Module(t) string(TypeCalculator.singleton.type(t)) end |
#string_NilClass(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 64 def string_NilClass(t) ; '?' ; end |
#string_PAnyType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 73 def string_PAnyType(t) ; 'Any' ; end |
#string_PArrayType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
210 211 212 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 210 def string_PArrayType(t) append_array('Array', t == PArrayType::DATA ? EMPTY_ARRAY : [string(t.element_type)] + range_array_part(t.size_type)) end |
#string_PBooleanType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 82 def string_PBooleanType(t) ; 'Boolean' ; end |
#string_PCallableType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 148 def string_PCallableType(t) elements = EMPTY_ARRAY unless t.param_types.nil? # translate to string, and skip Unit types elements = t.param_types.types.map {|t2| string(t2) unless t2.class == PUnitType }.compact if t.param_types.types.empty? elements += ['0', '0'] else elements += range_array_part(t.param_types.size_type) end # Add block T last (after min, max) if present) # unless t.block_type.nil? elements << string(t.block_type) end end append_array('Callable', elements) end |
#string_PCatalogEntryType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
220 221 222 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 220 def string_PCatalogEntryType(t) 'CatalogEntry' end |
#string_PCollectionType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
195 196 197 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 195 def string_PCollectionType(t) append_array('Collection', range_array_part(t.size_type)) end |
#string_PDataType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 88 def string_PDataType(t) ; 'Data' ; end |
#string_PDefaultType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 79 def string_PDefaultType(t) ; 'Default' ; end |
#string_PEnumType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
131 132 133 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 131 def string_PEnumType(t) append_array('Enum', t.values.map {|s| "'#{s}'" }) end |
#string_PFloatType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 114 def string_PFloatType(t) append_array('Float', range_array_part(t)) end |
#string_PHashType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
215 216 217 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 215 def string_PHashType(t) append_array('Hash', t == PHashType::DATA ? EMPTY_ARRAY : [string(t.key_type), string(t.element_type)] + range_array_part(t.size_type)) end |
#string_PHostClassType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
225 226 227 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 225 def string_PHostClassType(t) append_array('Class', t.class_name.nil? ? EMPTY_ARRAY : [t.class_name]) end |
#string_PIntegerType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 95 96 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 94 def string_PIntegerType(t) append_array('Integer', range_array_part(t)) end |
#string_PIterableType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 104 def string_PIterableType(t) append_array('Iterable', t.element_type.nil? ? EMPTY_ARRAY : [string(t.element_type)]) end |
#string_PIteratorType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
109 110 111 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 109 def string_PIteratorType(t) append_array('Iterator', t.element_type.nil? ? EMPTY_ARRAY : [string(t.element_type)]) end |
#string_PNotUndefType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 239 def string_PNotUndefType(t) contained_type = t.type if contained_type.nil? || contained_type.class == PAnyType args = EMPTY_ARRAY else if contained_type.is_a?(PStringType) && contained_type.values.size == 1 args = [ "'#{contained_type.values[0]}'" ] else args = [ string(contained_type) ] end end append_array('NotUndef', args) end |
#string_PNumericType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 91 def string_PNumericType(t) ; 'Numeric' ; end |
#string_POptionalType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 254 def string_POptionalType(t) optional_type = t.optional_type if optional_type.nil? args = EMPTY_ARRAY else if optional_type.is_a?(PStringType) && optional_type.values.size == 1 args = [ "'#{optional_type.values[0]}'" ] else args = [ string(optional_type) ] end end append_array('Optional', args) end |
#string_PPatternType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
190 191 192 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 190 def string_PPatternType(t) append_array('Pattern', t.patterns.map {|s| "#{s.regexp.inspect}" }) end |
#string_PRegexpType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 119 def string_PRegexpType(t) append_array('Regexp', t.pattern.nil? ? EMPTY_ARRAY : [t.regexp.inspect]) end |
#string_PResourceType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
230 231 232 233 234 235 236 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 230 def string_PResourceType(t) if t.type_name append_array(capitalize_segments(t.type_name), t.title.nil? ? EMPTY_ARRAY : ["'#{t.title}'"]) else 'Resource' end end |
#string_PRuntimeType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
205 206 207 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 205 def string_PRuntimeType(t) append_array('Runtime', [string(t.runtime), string(t.runtime_type_name)]) end |
#string_PScalarType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
85 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 85 def string_PScalarType(t) ; 'Scalar' ; end |
#string_PStringType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
124 125 126 127 128 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 124 def string_PStringType(t) elements = range_array_part(t.size_type) elements += t.values.map {|s| "'#{s}'" } if @debug append_array('String', elements) end |
#string_PStructType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
170 171 172 173 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 170 def string_PStructType(t) args = t.elements.empty? ? EMPTY_ARRAY : [append_hash('', t.elements.map {|e| hash_entry_PStructElement(e)})] append_array('Struct', args) end |
#string_PTupleType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
141 142 143 144 145 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 141 def string_PTupleType(t) type_strings = t.types.map {|t2| string(t2) } type_strings += range_array_part(t.size_type) unless type_strings.empty? append_array('Tuple', type_strings) end |
#string_PType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 99 def string_PType(t) append_array('Type', t.type.nil? ? EMPTY_ARRAY : [string(t.type)]) end |
#string_PTypeAliasType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
269 270 271 272 273 274 275 276 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 269 def string_PTypeAliasType(t) = @expand_aliases if && t.self_recursion? @guard ||= RecursionGuard.new = (@guard.add_this(t) & RecursionGuard::SELF_RECURSION_IN_THIS) == 0 end ? "#{t.name} = #{string(t.resolved_type)}" : t.name end |
#string_PTypeReferenceType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
279 280 281 282 283 284 285 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 279 def string_PTypeReferenceType(t) if t.parameters.empty? t.name else append_array(t.name.clone, t.parameters.map {|p| string(p) }) end end |
#string_PUndefType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 76 def string_PUndefType(t) ; 'Undef' ; end |
#string_PUnitType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
200 201 202 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 200 def string_PUnitType(t) 'Unit' end |
#string_PVariantType(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
136 137 138 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 136 def string_PVariantType(t) append_array('Variant', t.types.map {|t2| string(t2) }) end |
#string_String(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 67 def string_String(t) ; t.inspect ; end |
#string_Symbol(t) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 70 def string_Symbol(t) ; t.to_s ; end |
#to_s ⇒ Object
Debugging to_s to reduce the amount of output
288 289 290 |
# File 'lib/puppet/pops/types/type_formatter.rb', line 288 def to_s '[a TypeFormatter]' end |