class Puppet::Pops::Types::PEnumType
A string type describing the set of strings having one of the given values @api public
Constants
- DEFAULT
Attributes
case_insensitive[R]
values[R]
Public Class Methods
new(values, case_insensitive = false)
click to toggle source
# File lib/puppet/pops/types/types.rb 767 def initialize(values, case_insensitive = false) 768 @values = values.uniq.sort.freeze 769 @case_insensitive = case_insensitive 770 end
register_ptype(loader, ir)
click to toggle source
# File lib/puppet/pops/types/types.rb 759 def self.register_ptype(loader, ir) 760 create_ptype(loader, ir, 'ScalarDataType', 761 'values' => PArrayType.new(PStringType::NON_EMPTY), 762 'case_insensitive' => { 'type' => PBooleanType::DEFAULT, 'value' => false }) 763 end
Public Instance Methods
case_insensitive?()
click to toggle source
# File lib/puppet/pops/types/types.rb 772 def case_insensitive? 773 @case_insensitive 774 end
each(&block)
click to toggle source
Returns Enumerator if no block is given, otherwise, calls the given block with each of the strings for this enum
# File lib/puppet/pops/types/types.rb 778 def each(&block) 779 r = Iterable.on(self) 780 block_given? ? r.each(&block) : r 781 end
eql?(o)
click to toggle source
# File lib/puppet/pops/types/types.rb 806 def eql?(o) 807 self.class == o.class && @values == o.values && @case_insensitive == o.case_insensitive? 808 end
generalize()
click to toggle source
# File lib/puppet/pops/types/types.rb 783 def generalize 784 # General form of an Enum is a String 785 if @values.empty? 786 PStringType::DEFAULT 787 else 788 range = @values.map(&:size).minmax 789 PStringType.new(PIntegerType.new(range.min, range.max)) 790 end 791 end
hash()
click to toggle source
# File lib/puppet/pops/types/types.rb 802 def hash 803 @values.hash ^ @case_insensitive.hash 804 end
instance?(o, guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 810 def instance?(o, guard = nil) 811 if o.is_a?(String) 812 @case_insensitive ? @values.any? { |p| p.casecmp(o) == 0 } : @values.any? { |p| p == o } 813 else 814 false 815 end 816 end
iterable?(guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 793 def iterable?(guard = nil) 794 true 795 end
iterable_type(guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 797 def iterable_type(guard = nil) 798 # An instance of an Enum is a String 799 PStringType::ITERABLE_TYPE 800 end
Protected Instance Methods
_assignable?(o, guard)
click to toggle source
@api private
# File lib/puppet/pops/types/types.rb 823 def _assignable?(o, guard) 824 return true if self == o 825 svalues = values 826 if svalues.empty? 827 return true if o.is_a?(PStringType) || o.is_a?(PEnumType) || o.is_a?(PPatternType) 828 end 829 case o 830 when PStringType 831 # if the contained string is found in the set of enums 832 instance?(o.value, guard) 833 when PEnumType 834 !o.values.empty? && (case_insensitive? || !o.case_insensitive?) && o.values.all? { |s| instance?(s, guard) } 835 else 836 false 837 end 838 end