Class: Puppet::Pops::Types::PCollectionType
Constant Summary
collapse
- DEFAULT_SIZE =
PIntegerType.new(0)
- ZERO_SIZE =
PIntegerType.new(0, 0)
- NOT_EMPTY_SIZE =
PIntegerType.new(1)
- DEFAULT =
PCollectionType.new(nil)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from PAnyType
#==, #assignable?, #callable?, #callable_args?, #check_self_recursion, #kind_of_callable?, #name, #new_function, new_function, #really_instance?, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_ptype, create_ptype, register_ptypes
#_ptype
Constructor Details
#initialize(element_type, size_type = nil) ⇒ PCollectionType
Returns a new instance of PCollectionType.
1165
1166
1167
1168
1169
1170
1171
1172
|
# File 'lib/puppet/pops/types/types.rb', line 1165
def initialize(element_type, size_type = nil)
@size_type = size_type
if !size_type.nil? && size_type.from == 0 && size_type.to == 0
@element_type = PUnitType::DEFAULT
else
@element_type = element_type
end
end
|
Instance Attribute Details
#element_type ⇒ Object
1163
1164
1165
|
# File 'lib/puppet/pops/types/types.rb', line 1163
def element_type
@element_type
end
|
#size_type ⇒ Object
1163
1164
1165
|
# File 'lib/puppet/pops/types/types.rb', line 1163
def size_type
@size_type
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
1154
1155
1156
1157
1158
1159
1160
1161
|
# File 'lib/puppet/pops/types/types.rb', line 1154
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'AnyType',
'element_type' => {
KEY_TYPE => POptionalType.new(PType::DEFAULT),
KEY_VALUE => nil
}
)
end
|
Instance Method Details
#accept(visitor, guard) ⇒ Object
1174
1175
1176
1177
1178
|
# File 'lib/puppet/pops/types/types.rb', line 1174
def accept(visitor, guard)
super
@size_type.accept(visitor, guard) unless @size_type.nil?
@element_type.accept(visitor, guard) unless @element_type.nil?
end
|
#eql?(o) ⇒ Boolean
1230
1231
1232
|
# File 'lib/puppet/pops/types/types.rb', line 1230
def eql?(o)
self.class == o.class && @element_type == o.element_type && @size_type == o.size_type
end
|
#generalize ⇒ Object
1180
1181
1182
1183
1184
1185
1186
1187
|
# File 'lib/puppet/pops/types/types.rb', line 1180
def generalize
if @element_type.nil?
DEFAULT
else
ge_type = @element_type.generalize
@size_type.nil? && @element_type.equal?(ge_type) ? self : self.class.new(ge_type, nil)
end
end
|
#has_empty_range? ⇒ Boolean
1213
1214
1215
1216
|
# File 'lib/puppet/pops/types/types.rb', line 1213
def has_empty_range?
from, to = size_range
from == 0 && to == 0
end
|
1218
1219
1220
|
# File 'lib/puppet/pops/types/types.rb', line 1218
def hash
@element_type.hash ^ @size_type.hash
end
|
#instance?(o, guard = nil) ⇒ Boolean
1198
1199
1200
|
# File 'lib/puppet/pops/types/types.rb', line 1198
def instance?(o, guard = nil)
assignable?(TypeCalculator.infer(o), guard)
end
|
#iterable?(guard = nil) ⇒ Boolean
1222
1223
1224
|
# File 'lib/puppet/pops/types/types.rb', line 1222
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
1226
1227
1228
|
# File 'lib/puppet/pops/types/types.rb', line 1226
def iterable_type(guard = nil)
@element_type.nil? ? PIterableType::DEFAULT : PIterableType.new(@element_type)
end
|
#normalize(guard = nil) ⇒ Object
1189
1190
1191
1192
1193
1194
1195
1196
|
# File 'lib/puppet/pops/types/types.rb', line 1189
def normalize(guard = nil)
if @element_type.nil?
DEFAULT
else
ne_type = @element_type.normalize(guard)
@element_type.equal?(ne_type) ? self : self.class.new(ne_type, @size_type)
end
end
|
#resolve(type_parser, loader) ⇒ Object
1202
1203
1204
1205
1206
|
# File 'lib/puppet/pops/types/types.rb', line 1202
def resolve(type_parser, loader)
relement_type = @element_type
relement_type = relement_type.resolve(type_parser, loader) unless relement_type.nil?
relement_type.equal?(@element_type) ? self : self.class.new(relement_type, @size_type)
end
|
#size_range ⇒ Object
Returns an array with from (min) size to (max) size
1209
1210
1211
|
# File 'lib/puppet/pops/types/types.rb', line 1209
def size_range
(@size_type || DEFAULT_SIZE).range
end
|