Class: Puppet::Pops::Types::PTypeAliasType Private
- Inherits:
-
PAnyType
- Object
- TypedModelObject
- PAnyType
- Puppet::Pops::Types::PTypeAliasType
- Defined in:
- lib/puppet/pops/types/types.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Describes a named alias for another Type. The alias is created with a name and an unresolved type expression. The type expression may in turn contain other aliases (including the alias that contains it) which means that an alias might contain self recursion. Whether or not that is the case is computed and remembered when the alias is resolved since guarding against self recursive constructs is relatively expensive.
Instance Attribute Summary collapse
- #name ⇒ Object readonly private
Instance Method Summary collapse
- #accept(visitor, guard) ⇒ Object private
- #callable_args?(callable, guard) ⇒ Boolean private
- #eql?(o) ⇒ Boolean private
- #hash ⇒ Object private
-
#initialize(name, type_expr, resolved_type = nil) ⇒ PTypeAliasType
constructor
private
A new instance of PTypeAliasType.
- #instance?(o) ⇒ Boolean private
- #iterable?(guard = nil) ⇒ Boolean private
- #iterable_type(guard = nil) ⇒ Object private
- #kind_of_callable?(optional = true, guard = nil) ⇒ Boolean private
-
#resolve(type_parser, loader) ⇒ PTypeAliasType
private
Called from the TypeParser once it has found a type using the Loader.
-
#resolved_type ⇒ PAnyType
private
Returns the resolved type.
- #self_recursion? ⇒ Boolean private
Methods inherited from PAnyType
#==, #assignable?, #callable?, #generalize, #normalize, #simple_name, #to_alias_expanded_s, #to_s
Constructor Details
#initialize(name, type_expr, resolved_type = nil) ⇒ PTypeAliasType
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 a new instance of PTypeAliasType.
2244 2245 2246 2247 2248 2249 |
# File 'lib/puppet/pops/types/types.rb', line 2244 def initialize(name, type_expr, resolved_type = nil) @name = name @type_expr = type_expr @resolved_type = resolved_type @self_recursion = false end |
Instance Attribute Details
#name ⇒ Object (readonly)
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.
2239 2240 2241 |
# File 'lib/puppet/pops/types/types.rb', line 2239 def name @name end |
Instance Method Details
#accept(visitor, guard) ⇒ 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.
2320 2321 2322 2323 2324 2325 |
# File 'lib/puppet/pops/types/types.rb', line 2320 def accept(visitor, guard) guarded_recursion(guard, nil) do |g| super resolved_type.accept(visitor, g) end end |
#callable_args?(callable, guard) ⇒ Boolean
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.
2261 2262 2263 |
# File 'lib/puppet/pops/types/types.rb', line 2261 def callable_args?(callable, guard) guarded_recursion(guard, false) { |g| resolved_type.callable_args?(callable, g) } end |
#eql?(o) ⇒ Boolean
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.
2316 2317 2318 |
# File 'lib/puppet/pops/types/types.rb', line 2316 def eql?(o) super && o.name == @name end |
#hash ⇒ 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.
2282 2283 2284 |
# File 'lib/puppet/pops/types/types.rb', line 2282 def hash @name.hash end |
#instance?(o) ⇒ Boolean
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.
2269 2270 2271 2272 |
# File 'lib/puppet/pops/types/types.rb', line 2269 def instance?(o) # No value can ever be recursive so no guard is needed here resolved_type.instance?(o) end |
#iterable?(guard = nil) ⇒ Boolean
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.
2274 2275 2276 |
# File 'lib/puppet/pops/types/types.rb', line 2274 def iterable?(guard = nil) guarded_recursion(guard, false) { |g| resolved_type.iterable?(g) } end |
#iterable_type(guard = nil) ⇒ 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.
2278 2279 2280 |
# File 'lib/puppet/pops/types/types.rb', line 2278 def iterable_type(guard = nil) guarded_recursion(guard, nil) { |g| resolved_type.iterable_type(g) } end |
#kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
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.
2265 2266 2267 |
# File 'lib/puppet/pops/types/types.rb', line 2265 def kind_of_callable?(optional=true, guard = nil) guarded_recursion(guard, false) { |g| resolved_type.kind_of_callable?(optional, g) } end |
#resolve(type_parser, loader) ⇒ PTypeAliasType
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.
Called from the TypeParser once it has found a type using the Loader. The TypeParser will interpret the contained expression and the resolved type is remembered. This method also checks and remembers if the resolve type contains self recursion.
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 |
# File 'lib/puppet/pops/types/types.rb', line 2294 def resolve(type_parser, loader) if @resolved_type.nil? # resolved to PTypeReferenceType::DEFAULT during resolve to avoid endless recursion @resolved_type = PTypeReferenceType::DEFAULT @self_recursion = true # assumed while it being found out below begin @resolved_type = type_parser.interpret(@type_expr, loader).normalize # Find out if this type is recursive. A recursive type has performance implications # on several methods and this knowledge is used to avoid that for non-recursive # types. guard = RecursionGuard.new accept(NoopTypeAcceptor::INSTANCE, guard) @self_recursion = guard.recursive_this?(self) rescue @resolved_type = nil raise end end self end |
#resolved_type ⇒ PAnyType
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 resolved type. The type must have been resolved by a call prior to calls to this method or an error will be raised.
2256 2257 2258 2259 |
# File 'lib/puppet/pops/types/types.rb', line 2256 def resolved_type raise Puppet::Error, "Reference to unresolved type #{@name}" unless @resolved_type @resolved_type end |
#self_recursion? ⇒ Boolean
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.
2327 2328 2329 |
# File 'lib/puppet/pops/types/types.rb', line 2327 def self_recursion? @self_recursion end |