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, #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.



1200
1201
1202
# File 'lib/puppet/pops/types/types.rb', line 1200

def initialize(size_type)
  @size_type = size_type
end

Instance Attribute Details

#size_typeObject (readonly)



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

def size_type
  @size_type
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1189
1190
1191
1192
1193
1194
1195
1196
# File 'lib/puppet/pops/types/types.rb', line 1189

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



1204
1205
1206
1207
# File 'lib/puppet/pops/types/types.rb', line 1204

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

#eql?(o) ⇒ Boolean



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

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

#generalizeObject



1209
1210
1211
# File 'lib/puppet/pops/types/types.rb', line 1209

def generalize
  DEFAULT
end

#has_empty_range?Boolean



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

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

#hashObject



1235
1236
1237
# File 'lib/puppet/pops/types/types.rb', line 1235

def hash
  @size_type.hash
end

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



1217
1218
1219
1220
1221
1222
1223
# File 'lib/puppet/pops/types/types.rb', line 1217

def instance?(o, guard = nil)
  if o.is_a?(Array) || o.is_a?(Hash)
    @size_type.nil? || @size_type.instance?(o.size)
  else
    false
  end
end

#iterable?(guard = nil) ⇒ Boolean



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

def iterable?(guard = nil)
  true
end

#normalize(guard = nil) ⇒ Object



1213
1214
1215
# File 'lib/puppet/pops/types/types.rb', line 1213

def normalize(guard = nil)
  DEFAULT
end

#size_rangeObject

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



1226
1227
1228
# File 'lib/puppet/pops/types/types.rb', line 1226

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