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

Methods inherited from TypedModelObject

_pcore_type, create_ptype, register_ptypes

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type

Constructor Details

#initialize(size_type) ⇒ PCollectionType

Returns a new instance of PCollectionType.



1240
1241
1242
# File 'lib/puppet/pops/types/types.rb', line 1240

def initialize(size_type)
  @size_type = size_type
end

Instance Attribute Details

#size_typeObject (readonly)



1238
1239
1240
# File 'lib/puppet/pops/types/types.rb', line 1238

def size_type
  @size_type
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1229
1230
1231
1232
1233
1234
1235
1236
# File 'lib/puppet/pops/types/types.rb', line 1229

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

Instance Method Details

#accept(visitor, guard) ⇒ Object



1244
1245
1246
1247
# File 'lib/puppet/pops/types/types.rb', line 1244

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


1284
1285
1286
# File 'lib/puppet/pops/types/types.rb', line 1284

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

#generalizeObject



1249
1250
1251
# File 'lib/puppet/pops/types/types.rb', line 1249

def generalize
  DEFAULT
end

#has_empty_range?Boolean

Returns:

  • (Boolean)


1271
1272
1273
1274
# File 'lib/puppet/pops/types/types.rb', line 1271

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

#hashObject



1276
1277
1278
# File 'lib/puppet/pops/types/types.rb', line 1276

def hash
  @size_type.hash
end

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

Returns:

  • (Boolean)


1257
1258
1259
1260
1261
1262
1263
1264
# File 'lib/puppet/pops/types/types.rb', line 1257

def instance?(o, guard = nil)
  # The inferred type of a class derived from Array or Hash is either Runtime or Object. It's not assignable to the Collection type.
  if o.instance_of?(Array) || o.instance_of?(Hash)
    @size_type.nil? || @size_type.instance?(o.size)
  else
    false
  end
end

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


1280
1281
1282
# File 'lib/puppet/pops/types/types.rb', line 1280

def iterable?(guard = nil)
  true
end

#normalize(guard = nil) ⇒ Object



1253
1254
1255
# File 'lib/puppet/pops/types/types.rb', line 1253

def normalize(guard = nil)
  DEFAULT
end

#size_rangeObject

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



1267
1268
1269
# File 'lib/puppet/pops/types/types.rb', line 1267

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