Class: Puppet::Pops::Types::PEnumType

Inherits:
PScalarType show all
Defined in:
lib/puppet/pops/types/types.rb

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

#instance?

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #generalize, #instance?, #kind_of_callable?, #name, #new_function, new_function, #normalize, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_ptype, create_ptype, register_ptypes

Methods included from Visitable

#accept

Methods included from PuppetObject

#_ptype

Constructor Details

#initialize(values) ⇒ PEnumType

Returns a new instance of PEnumType.



693
694
695
# File 'lib/puppet/pops/types/types.rb', line 693

def initialize(values)
  @values = values.uniq.sort.freeze
end

Instance Attribute Details

#valuesObject (readonly)



691
692
693
# File 'lib/puppet/pops/types/types.rb', line 691

def values
  @values
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



687
688
689
# File 'lib/puppet/pops/types/types.rb', line 687

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'ScalarType', '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



699
700
701
702
# File 'lib/puppet/pops/types/types.rb', line 699

def each(&block)
  r = Iterable.on(self)
  block_given? ? r.each(&block) : r
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


717
718
719
# File 'lib/puppet/pops/types/types.rb', line 717

def eql?(o)
  self.class == o.class && @values == o.values
end

#hashObject



713
714
715
# File 'lib/puppet/pops/types/types.rb', line 713

def hash
  @values.hash
end

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


704
705
706
# File 'lib/puppet/pops/types/types.rb', line 704

def iterable?(guard = nil)
  true
end

#iterable_type(guard = nil) ⇒ Object



708
709
710
711
# File 'lib/puppet/pops/types/types.rb', line 708

def iterable_type(guard = nil)
  # An instance of an Enum is a String
  PStringType::ITERABLE_TYPE
end