Class: Puppet::Pops::Types::PEnumType
Overview
A string type describing the set of strings having one of the given values
Constant Summary
collapse
- DEFAULT =
PEnumType.new(EMPTY_ARRAY)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from PScalarType
#roundtrip_with_string?
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, #create, create, #kind_of_callable?, #name, #new_function, new_function, #normalize, #really_instance?, #resolve, #roundtrip_with_string?, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_pcore_type, create_ptype, register_ptypes
Methods included from Visitable
#accept
#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type
Constructor Details
#initialize(values) ⇒ PEnumType
Returns a new instance of PEnumType.
715
716
717
|
# File 'lib/puppet/pops/types/types.rb', line 715
def initialize(values)
@values = values.uniq.sort.freeze
end
|
Instance Attribute Details
713
714
715
|
# File 'lib/puppet/pops/types/types.rb', line 713
def values
@values
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
709
710
711
|
# File 'lib/puppet/pops/types/types.rb', line 709
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'ScalarDataType', 'values' => PArrayType.new(PStringType::NON_EMPTY))
end
|
Instance Method Details
#each(&block) ⇒ Object
Returns Enumerator if no block is given, otherwise, calls the given block with each of the strings for this enum
721
722
723
724
|
# File 'lib/puppet/pops/types/types.rb', line 721
def each(&block)
r = Iterable.on(self)
block_given? ? r.each(&block) : r
end
|
#eql?(o) ⇒ Boolean
749
750
751
|
# File 'lib/puppet/pops/types/types.rb', line 749
def eql?(o)
self.class == o.class && @values == o.values
end
|
745
746
747
|
# File 'lib/puppet/pops/types/types.rb', line 745
def hash
@values.hash
end
|
#instance?(o, guard = nil) ⇒ Boolean
753
754
755
|
# File 'lib/puppet/pops/types/types.rb', line 753
def instance?(o, guard = nil)
o.is_a?(String) && @values.any? { |p| p == o }
end
|
#iterable?(guard = nil) ⇒ Boolean
736
737
738
|
# File 'lib/puppet/pops/types/types.rb', line 736
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
740
741
742
743
|
# File 'lib/puppet/pops/types/types.rb', line 740
def iterable_type(guard = nil)
PStringType::ITERABLE_TYPE
end
|