Class: Puppet::Pops::Types::PStructType
- Inherits:
-
PAnyType
show all
- Includes:
- Enumerable
- Defined in:
- lib/puppet/pops/types/types.rb
Constant Summary
collapse
- DEFAULT =
PStructType.new(EMPTY_ARRAY)
Instance Method Summary
collapse
Methods inherited from PAnyType
#==, #assignable?, #callable?, #callable_args?, #kind_of_callable?, #simple_name, #to_alias_expanded_s, #to_s
Constructor Details
#initialize(elements) ⇒ PStructType
Returns a new instance of PStructType.
1192
1193
1194
|
# File 'lib/puppet/pops/types/types.rb', line 1192
def initialize(elements)
@elements = elements.sort.freeze
end
|
Instance Method Details
#accept(visitor, guard) ⇒ Object
1196
1197
1198
1199
|
# File 'lib/puppet/pops/types/types.rb', line 1196
def accept(visitor, guard)
super
@elements.each { |elem| elem.accept(visitor, guard) }
end
|
1201
1202
1203
1204
1205
1206
1207
|
# File 'lib/puppet/pops/types/types.rb', line 1201
def each
if block_given?
elements.each { |elem| yield elem }
else
elements.to_enum
end
end
|
1254
1255
1256
|
# File 'lib/puppet/pops/types/types.rb', line 1254
def elements
@elements
end
|
#eql?(o) ⇒ Boolean
1250
1251
1252
|
# File 'lib/puppet/pops/types/types.rb', line 1250
def eql?(o)
self.class == o.class && @elements == o.elements
end
|
#generalize ⇒ Object
1209
1210
1211
1212
1213
1214
1215
|
# File 'lib/puppet/pops/types/types.rb', line 1209
def generalize
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :generalize) { |altered| PStructType.new(altered) }
end
end
|
1229
1230
1231
|
# File 'lib/puppet/pops/types/types.rb', line 1229
def hash
@elements.hash
end
|
#hashed_elements ⇒ Object
1225
1226
1227
|
# File 'lib/puppet/pops/types/types.rb', line 1225
def hashed_elements
@hashed ||= @elements.reduce({}) {|memo, e| memo[e.name] = e; memo }
end
|
#instance?(o) ⇒ Boolean
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
|
# File 'lib/puppet/pops/types/types.rb', line 1258
def instance?(o)
return false unless o.is_a?(Hash)
matched = 0
@elements.all? do |e|
key = e.name
v = o[key]
if v.nil? && !o.include?(key)
e.key_type.assignable?(PUndefType::DEFAULT)
else
matched += 1
e.value_type.instance?(v)
end
end && matched == o.size
end
|
#iterable?(guard = nil) ⇒ Boolean
1233
1234
1235
|
# File 'lib/puppet/pops/types/types.rb', line 1233
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
#normalize(guard = nil) ⇒ Object
1217
1218
1219
1220
1221
1222
1223
|
# File 'lib/puppet/pops/types/types.rb', line 1217
def normalize(guard = nil)
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :normalize, guard) { |altered| PStructType.new(altered) }
end
end
|