Class: Puppet::Pops::Types::PStringType
Constant Summary
collapse
- DEFAULT =
PStringType.new(nil)
- NON_EMPTY =
PStringType.new(PIntegerType.new(1))
- 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?, #check_self_recursion, #kind_of_callable?, #name, #new_function, #normalize, #really_instance?, #resolve, #simple_name, #to_alias_expanded_s, #to_s
Constructor Details
#initialize(size_type, values = EMPTY_ARRAY) ⇒ PStringType
Returns a new instance of PStringType.
1172
1173
1174
1175
|
# File 'lib/puppet/pops/types/types.rb', line 1172
def initialize(size_type, values = EMPTY_ARRAY)
@size_type = size_type
@values = values.sort.freeze
end
|
Instance Attribute Details
#size_type ⇒ Object
1170
1171
1172
|
# File 'lib/puppet/pops/types/types.rb', line 1170
def size_type
@size_type
end
|
1170
1171
1172
|
# File 'lib/puppet/pops/types/types.rb', line 1170
def values
@values
end
|
Class Method Details
.new_function(_, loader) ⇒ Object
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
|
# File 'lib/puppet/pops/types/types.rb', line 1211
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
|
Instance Method Details
#accept(visitor, guard) ⇒ Object
1177
1178
1179
1180
|
# File 'lib/puppet/pops/types/types.rb', line 1177
def accept(visitor, guard)
super
@size_type.accept(visitor, guard) unless @size_type.nil?
end
|
#eql?(o) ⇒ Boolean
1198
1199
1200
|
# File 'lib/puppet/pops/types/types.rb', line 1198
def eql?(o)
self.class == o.class && @size_type == o.size_type && @values == o.values
end
|
#generalize ⇒ Object
1182
1183
1184
|
# File 'lib/puppet/pops/types/types.rb', line 1182
def generalize
DEFAULT
end
|
1186
1187
1188
|
# File 'lib/puppet/pops/types/types.rb', line 1186
def hash
@size_type.hash ^ @values.hash
end
|
#instance?(o, guard = nil) ⇒ Boolean
1202
1203
1204
1205
1206
1207
1208
1209
|
# File 'lib/puppet/pops/types/types.rb', line 1202
def instance?(o, guard = nil)
if o.is_a?(String) && (@size_type.nil? || @size_type.instance?(o.size, guard))
@values.empty? || @values.include?(o)
else
false
end
end
|
#iterable?(guard = nil) ⇒ Boolean
1190
1191
1192
|
# File 'lib/puppet/pops/types/types.rb', line 1190
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
1194
1195
1196
|
# File 'lib/puppet/pops/types/types.rb', line 1194
def iterable_type(guard = nil)
ITERABLE_TYPE
end
|