Class: Puppet::Pops::Types::PCollectionType

Inherits:
PAnyType show all
Defined in:
lib/puppet/pops/types/types.rb

Direct Known Subclasses

PArrayType, PHashType

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, #create, #iterable_type, #kind_of_callable?, #name, new_function, #new_function, #really_instance?, #resolve, simple_name, #simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_ptype, create_ptype, register_ptypes

Methods included from PuppetObject

#_ptype

Constructor Details

#initialize(size_type) ⇒ PCollectionType

Returns a new instance of PCollectionType.



1180
1181
1182
# File 'lib/puppet/pops/types/types.rb', line 1180

def initialize(size_type)
  @size_type = size_type
end

Instance Attribute Details

#size_typeObject (readonly)



1178
1179
1180
# File 'lib/puppet/pops/types/types.rb', line 1178

def size_type
  @size_type
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/puppet/pops/types/types.rb', line 1169

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'AnyType',
    'size_type' => {
      KEY_TYPE => POptionalType.new(PType.new(PIntegerType::DEFAULT)),
      KEY_VALUE => nil
    }
  )
end

Instance Method Details

#accept(visitor, guard) ⇒ Object



1184
1185
1186
1187
# File 'lib/puppet/pops/types/types.rb', line 1184

def accept(visitor, guard)
  super
  @size_type.accept(visitor, guard) unless @size_type.nil?
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


1219
1220
1221
# File 'lib/puppet/pops/types/types.rb', line 1219

def eql?(o)
  self.class == o.class && @size_type == o.size_type
end

#generalizeObject



1189
1190
1191
# File 'lib/puppet/pops/types/types.rb', line 1189

def generalize
  DEFAULT
end

#has_empty_range?Boolean

Returns:

  • (Boolean)


1206
1207
1208
1209
# File 'lib/puppet/pops/types/types.rb', line 1206

def has_empty_range?
  from, to = size_range
  from == 0 && to == 0
end

#hashObject



1211
1212
1213
# File 'lib/puppet/pops/types/types.rb', line 1211

def hash
  @size_type.hash
end

#instance?(o, guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


1197
1198
1199
# File 'lib/puppet/pops/types/types.rb', line 1197

def instance?(o, guard = nil)
  assignable?(TypeCalculator.infer(o), guard)
end

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


1215
1216
1217
# File 'lib/puppet/pops/types/types.rb', line 1215

def iterable?(guard = nil)
  true
end

#normalize(guard = nil) ⇒ Object



1193
1194
1195
# File 'lib/puppet/pops/types/types.rb', line 1193

def normalize(guard = nil)
  DEFAULT
end

#size_rangeObject

Returns an array with from (min) size to (max) size



1202
1203
1204
# File 'lib/puppet/pops/types/types.rb', line 1202

def size_range
  (@size_type || DEFAULT_SIZE).range
end