Class: Puppet::Pops::Types::PArrayType
Constant Summary
collapse
- DEFAULT =
PArrayType.new(nil)
- EMPTY =
PArrayType.new(PUnitType::DEFAULT, ZERO_SIZE)
Puppet::Pops::Types::PCollectionType::DEFAULT_SIZE, Puppet::Pops::Types::PCollectionType::NOT_EMPTY_SIZE, Puppet::Pops::Types::PCollectionType::ZERO_SIZE
Instance Attribute Summary collapse
#size_type
Class Method Summary
collapse
Instance Method Summary
collapse
#has_empty_range?, #iterable?, #size_range
Methods inherited from PAnyType
#==, #assignable?, #callable?, #callable_with?, #check_self_recursion, create, #create, #iterable?, #kind_of_callable?, #loader, #name, #new_function, #really_instance?, #roundtrip_with_string?, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_pcore_type, create_ptype, register_ptypes
#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type
Constructor Details
#initialize(element_type, size_type = nil) ⇒ PArrayType
Returns a new instance of PArrayType.
2436
2437
2438
2439
2440
2441
2442
2443
|
# File 'lib/puppet/pops/types/types.rb', line 2436
def initialize(element_type, size_type = nil)
super(size_type)
if !size_type.nil? && size_type.from == 0 && size_type.to == 0
@element_type = PUnitType::DEFAULT
else
@element_type = element_type.nil? ? PAnyType::DEFAULT : element_type
end
end
|
Instance Attribute Details
#element_type ⇒ Object
2434
2435
2436
|
# File 'lib/puppet/pops/types/types.rb', line 2434
def element_type
@element_type
end
|
Class Method Details
.new_function(type) ⇒ Object
Returns a new function that produces an Array
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
|
# File 'lib/puppet/pops/types/types.rb', line 2503
def self.new_function(type)
@new_function ||= Puppet::Functions.create_loaded_function(:new_array, type.loader) do
dispatch :from_args do
param 'Any', :from
optional_param 'Boolean', :wrap
end
def from_args(from, wrap = false)
case from
when NilClass
if wrap
[nil]
else
throw :undefined_value
end
when Array
from
when Hash
wrap ? [from] : from.to_a
when PBinaryType::Binary
wrap ? [from] : from.binary_buffer.bytes.to_a
else
if wrap
[from]
else
if PIterableType::DEFAULT.instance?(from)
Iterable.on(from).to_a
else
t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Array")
end
end
end
end
end
end
|
.register_ptype(loader, ir) ⇒ Object
2425
2426
2427
2428
2429
2430
2431
2432
|
# File 'lib/puppet/pops/types/types.rb', line 2425
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'CollectionType',
'element_type' => {
KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
KEY_VALUE => PAnyType::DEFAULT
}
)
end
|
Instance Method Details
#accept(visitor, guard) ⇒ Object
2445
2446
2447
2448
|
# File 'lib/puppet/pops/types/types.rb', line 2445
def accept(visitor, guard)
super
@element_type.accept(visitor, guard)
end
|
#callable_args?(callable, guard = nil) ⇒ Boolean
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
2451
2452
2453
2454
2455
2456
|
# File 'lib/puppet/pops/types/types.rb', line 2451
def callable_args?(callable, guard = nil)
param_t = callable.param_types
block_t = callable.block_type
(param_t.nil? || param_t.assignable?(self, guard)) && (block_t.nil? || block_t.assignable?(PUndefType::DEFAULT, guard))
end
|
#eql?(o) ⇒ Boolean
2467
2468
2469
|
# File 'lib/puppet/pops/types/types.rb', line 2467
def eql?(o)
super && @element_type == o.element_type
end
|
#generalize ⇒ Object
2458
2459
2460
2461
2462
2463
2464
2465
|
# File 'lib/puppet/pops/types/types.rb', line 2458
def generalize
if PAnyType::DEFAULT.eql?(@element_type)
DEFAULT
else
ge_type = @element_type.generalize
@size_type.nil? && @element_type.equal?(ge_type) ? self : self.class.new(ge_type, nil)
end
end
|
2471
2472
2473
|
# File 'lib/puppet/pops/types/types.rb', line 2471
def hash
super ^ @element_type.hash
end
|
#instance?(o, guard = nil) ⇒ Boolean
2489
2490
2491
2492
2493
2494
2495
|
# File 'lib/puppet/pops/types/types.rb', line 2489
def instance?(o, guard = nil)
return false unless o.instance_of?(Array)
return false unless o.all? {|element| @element_type.instance?(element, guard) }
size_t = size_type
size_t.nil? || size_t.instance?(o.size, guard)
end
|
#iterable_type(guard = nil) ⇒ Object
2497
2498
2499
|
# File 'lib/puppet/pops/types/types.rb', line 2497
def iterable_type(guard = nil)
PAnyType::DEFAULT.eql?(@element_type) ? PIterableType::DEFAULT : PIterableType.new(@element_type)
end
|
#normalize(guard = nil) ⇒ Object
2475
2476
2477
2478
2479
2480
2481
2482
|
# File 'lib/puppet/pops/types/types.rb', line 2475
def normalize(guard = nil)
if PAnyType::DEFAULT.eql?(@element_type)
DEFAULT
else
ne_type = @element_type.normalize(guard)
@element_type.equal?(ne_type) ? self : self.class.new(ne_type, @size_type)
end
end
|
#resolve(loader) ⇒ Object
2484
2485
2486
2487
|
# File 'lib/puppet/pops/types/types.rb', line 2484
def resolve(loader)
relement_type = @element_type.resolve(loader)
relement_type.equal?(@element_type) ? self : self.class.new(relement_type, @size_type)
end
|