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

Inherits:
PScalarDataType 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 PScalarType

#roundtrip_with_string?

Methods inherited from PAnyType

#==, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #generalize, #iterable?, #iterable_type, #kind_of_callable?, #loader, #name, #new_function, new_function, #normalize, #really_instance?, #resolve, #roundtrip_with_string?, simple_name, #simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_pcore_type, create_ptype, register_ptypes

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type, #to_s

Constructor Details

#initialize(patterns) ⇒ PPatternType

Returns a new instance of PPatternType.



1783
1784
1785
# File 'lib/puppet/pops/types/types.rb', line 1783

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

Instance Attribute Details

#patternsObject (readonly)



1781
1782
1783
# File 'lib/puppet/pops/types/types.rb', line 1781

def patterns
  @patterns
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1777
1778
1779
# File 'lib/puppet/pops/types/types.rb', line 1777

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

Instance Method Details

#accept(visitor, guard) ⇒ Object



1787
1788
1789
1790
# File 'lib/puppet/pops/types/types.rb', line 1787

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


1796
1797
1798
# File 'lib/puppet/pops/types/types.rb', line 1796

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

#hashObject



1792
1793
1794
# File 'lib/puppet/pops/types/types.rb', line 1792

def hash
  @patterns.hash
end

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

Returns:

  • (Boolean)


1800
1801
1802
# File 'lib/puppet/pops/types/types.rb', line 1800

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