Class: Puppet::Pops::Types::PPatternType

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

Overview

Represents a subtype of String that narrows the string to those matching the patterns If specified without a pattern it is basically the same as the String type.

Constant Summary collapse

DEFAULT =
PPatternType.new(EMPTY_ARRAY)

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, #generalize, #iterable?, #iterable_type, #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 PuppetObject

#_ptype

Constructor Details

#initialize(patterns) ⇒ PPatternType

Returns a new instance of PPatternType.



1608
1609
1610
# File 'lib/puppet/pops/types/types.rb', line 1608

def initialize(patterns)
  @patterns = patterns.freeze
end

Instance Attribute Details

#patternsObject (readonly)



1606
1607
1608
# File 'lib/puppet/pops/types/types.rb', line 1606

def patterns
  @patterns
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1602
1603
1604
# File 'lib/puppet/pops/types/types.rb', line 1602

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'ScalarType', 'patterns' => PArrayType.new(PRegexpType::DEFAULT))
end

Instance Method Details

#accept(visitor, guard) ⇒ Object



1612
1613
1614
1615
# File 'lib/puppet/pops/types/types.rb', line 1612

def accept(visitor, guard)
  super
  @patterns.each { |p| p.accept(visitor, guard) }
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


1621
1622
1623
# File 'lib/puppet/pops/types/types.rb', line 1621

def eql?(o)
  self.class == o.class && @patterns.size == o.patterns.size && (@patterns - o.patterns).empty?
end

#hashObject



1617
1618
1619
# File 'lib/puppet/pops/types/types.rb', line 1617

def hash
  @patterns.hash
end

#instance?(o, guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


1625
1626
1627
# File 'lib/puppet/pops/types/types.rb', line 1625

def instance?(o, guard = nil)
  o.is_a?(String) && (@patterns.empty? || @patterns.any? { |p| p.regexp.match(o) })
end