Class: Puppet::Pops::Types::PStringType
Constant Summary
collapse
- DEFAULT =
PStringType.new(nil)
- NON_EMPTY =
PStringType.new(PCollectionType::NOT_EMPTY_SIZE)
- ITERABLE_TYPE =
Iterates over each character of the string
PIterableType.new(PStringType.new(PIntegerType.new(1,1)))
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, #kind_of_callable?, #name, #new_function, #normalize, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_ptype, create_ptype, register_ptypes
#_ptype
Constructor Details
#initialize(size_type_or_value, deprecated_multi_args = EMPTY_ARRAY) ⇒ PStringType
Returns a new instance of PStringType.
1386
1387
1388
1389
1390
1391
1392
1393
1394
|
# File 'lib/puppet/pops/types/types.rb', line 1386
def initialize(size_type_or_value, deprecated_multi_args = EMPTY_ARRAY)
unless deprecated_multi_args.empty?
if Puppet[:strict] != :off
Puppet.warn_once(:deprecatation, "PStringType#initialize_multi_args", "Passing more than one argument to PStringType#initialize is deprecated")
end
size_type_or_value = deprecated_multi_args[0]
end
@size_type_or_value = size_type_or_value
end
|
Instance Attribute Details
#size_type_or_value ⇒ Object
1384
1385
1386
|
# File 'lib/puppet/pops/types/types.rb', line 1384
def size_type_or_value
@size_type_or_value
end
|
Class Method Details
.new_function(_, loader) ⇒ Object
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
|
# File 'lib/puppet/pops/types/types.rb', line 1466
def self.new_function(_, loader)
@new_function ||= Puppet::Functions.create_loaded_function(:new_string, loader) do
local_types do
type 'Format = Pattern[/^%([\s\+\-#0\[\{<\(\|]*)([1-9][0-9]*)?(?:\.([0-9]+))?([a-zA-Z])/]'
type 'ContainerFormat = Struct[{
Optional[format] => String,
Optional[separator] => String,
Optional[separator2] => String,
Optional[string_formats] => Hash[Type, Format]
}]'
type 'TypeMap = Hash[Type, Variant[Format, ContainerFormat]]'
type 'Convertible = Any'
type 'Formats = Variant[Default, String[1], TypeMap]'
end
dispatch :from_args do
param 'Convertible', :from
optional_param 'Formats', :string_formats
end
def from_args(from, formats = :default)
StringConverter.singleton.convert(from, formats)
end
end
end
|
.register_ptype(loader, ir) ⇒ Object
Instance Method Details
#accept(visitor, guard) ⇒ Object
1396
1397
1398
1399
|
# File 'lib/puppet/pops/types/types.rb', line 1396
def accept(visitor, guard)
super
@size_type_or_value.accept(visitor, guard) if @size_type_or_value.is_a?(PIntegerType)
end
|
#derived_size_type ⇒ Object
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
|
# File 'lib/puppet/pops/types/types.rb', line 1455
def derived_size_type
if @size_type_or_value.is_a?(PIntegerType)
@size_type_or_value
elsif @size_type_or_value.is_a?(String)
sz = @size_type_or_value.size
PIntegerType.new(sz, sz)
else
PCollectionType::DEFAULT_SIZE
end
end
|
#eql?(o) ⇒ Boolean
1417
1418
1419
|
# File 'lib/puppet/pops/types/types.rb', line 1417
def eql?(o)
self.class == o.class && @size_type_or_value == o.size_type_or_value
end
|
#generalize ⇒ Object
1401
1402
1403
|
# File 'lib/puppet/pops/types/types.rb', line 1401
def generalize
DEFAULT
end
|
1405
1406
1407
|
# File 'lib/puppet/pops/types/types.rb', line 1405
def hash
@size_type_or_value.hash
end
|
#instance?(o, guard = nil) ⇒ Boolean
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
|
# File 'lib/puppet/pops/types/types.rb', line 1421
def instance?(o, guard = nil)
if o.is_a?(String)
if @size_type_or_value.is_a?(PIntegerType)
@size_type_or_value.instance?(o.size, guard)
else
@size_type_or_value.nil? ? true : o == value
end
else
false
end
end
|
#iterable?(guard = nil) ⇒ Boolean
1409
1410
1411
|
# File 'lib/puppet/pops/types/types.rb', line 1409
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
1413
1414
1415
|
# File 'lib/puppet/pops/types/types.rb', line 1413
def iterable_type(guard = nil)
ITERABLE_TYPE
end
|
#size_type ⇒ Object
1447
1448
1449
|
# File 'lib/puppet/pops/types/types.rb', line 1447
def size_type
@size_type_or_value.is_a?(PIntegerType) ? @size_type_or_value : nil
end
|
1434
1435
1436
|
# File 'lib/puppet/pops/types/types.rb', line 1434
def value
@size_type_or_value.is_a?(PIntegerType) ? nil : @size_type_or_value
end
|
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.
1440
1441
1442
1443
1444
1445
|
# File 'lib/puppet/pops/types/types.rb', line 1440
def values
if Puppet[:strict] != :off
Puppet.warn_once(:deprecatation, "PStringType#values", "Method PStringType#values is deprecated. Use #value instead")
end
@value.is_a?(String) ? [@value] : EMPTY_ARRAY
end
|