Class: Puppet::Pops::Types::PRuntimeType
Constant Summary
collapse
- TYPE_NAME_OR_PATTERN =
PVariantType.new([PStringType::NON_EMPTY, PTupleType.new([PRegexpType::DEFAULT, PStringType::NON_EMPTY])])
- DEFAULT =
PRuntimeType.new(nil, nil)
- RUBY =
PRuntimeType.new(:ruby, nil)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, #create, create, #generalize, #kind_of_callable?, #loader, #name, new_function, #new_function, #normalize, #really_instance?, #resolve, #roundtrip_with_string?, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_pcore_type, create_ptype, register_ptypes
Methods included from Visitable
#accept
#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type, #to_s
Constructor Details
#initialize(runtime, name_or_pattern) ⇒ PRuntimeType
Creates a new instance of a Runtime type
Instance Attribute Details
#name_or_pattern ⇒ Object
21
22
23
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 21
def name_or_pattern
@name_or_pattern
end
|
21
22
23
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 21
def runtime
@runtime
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
Instance Method Details
#class_or_module ⇒ 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.
69
70
71
72
73
74
75
76
77
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 69
def class_or_module
raise "Only ruby classes or modules can be produced by this runtime, got '#{runtime}" unless runtime == :ruby
raise 'A pattern based Runtime type cannot produce a class or module' if @name_or_pattern.is_a?(Array)
com = ClassLoader.provide(self)
raise "The name #{@name_or_pattern} does not represent a ruby class or module" if com.nil?
com
end
|
#eql?(o) ⇒ Boolean
40
41
42
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 40
def eql?(o)
self.class == o.class && @runtime == o.runtime && @name_or_pattern == o.name_or_pattern
end
|
#from_puppet_name(puppet_name) ⇒ 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.
80
81
82
83
84
85
86
87
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 80
def from_puppet_name(puppet_name)
if @name_or_pattern.is_a?(Array)
substituted = puppet_name.sub(*@name_or_pattern)
substituted == puppet_name ? nil : PRuntimeType.new(@runtime, substituted)
else
nil
end
end
|
36
37
38
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 36
def hash
@runtime.hash ^ @name_or_pattern.hash
end
|
#instance?(o, guard = nil) ⇒ Boolean
44
45
46
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 44
def instance?(o, guard = nil)
assignable?(TypeCalculator.infer(o), guard)
end
|
#iterable?(guard = nil) ⇒ Boolean
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 48
def iterable?(guard = nil)
if @runtime == :ruby && !runtime_type_name.nil?
begin
c = ClassLoader.provide(self)
return c < Iterable unless c.nil?
rescue ArgumentError
end
end
false
end
|
#iterable_type(guard = nil) ⇒ Object
59
60
61
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 59
def iterable_type(guard = nil)
iterable?(guard) ? PIterableType.new(self) : nil
end
|
#runtime_type_name ⇒ 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
65
66
|
# File 'lib/puppet/pops/types/p_runtime_type.rb', line 64
def runtime_type_name
@name_or_pattern.is_a?(String) ? @name_or_pattern : nil
end
|