class Puppet::Pops::Types::PRegexpType

@api public

Constants

DEFAULT

Attributes

pattern[R]

Public Class Methods

append_flags_group(rx_string, options) click to toggle source
     # File lib/puppet/pops/types/types.rb
1711 def self.append_flags_group(rx_string, options)
1712   if options == 0
1713     rx_string
1714   else
1715     bld = '(?'
1716     bld << 'i' if (options & Regexp::IGNORECASE) != 0
1717     bld << 'm' if (options & Regexp::MULTILINE) != 0
1718     bld << 'x' if (options & Regexp::EXTENDED) != 0
1719     unless options == (Regexp::IGNORECASE | Regexp::MULTILINE | Regexp::EXTENDED)
1720       bld << '-'
1721       bld << 'i' if (options & Regexp::IGNORECASE) == 0
1722       bld << 'm' if (options & Regexp::MULTILINE) == 0
1723       bld << 'x' if (options & Regexp::EXTENDED) == 0
1724     end
1725     bld << ':' << rx_string << ')'
1726     bld.freeze
1727   end
1728 end
new(pattern) click to toggle source
     # File lib/puppet/pops/types/types.rb
1730 def initialize(pattern)
1731   if pattern.is_a?(Regexp)
1732     @regexp = pattern
1733     @pattern = PRegexpType.regexp_to_s(pattern)
1734   else
1735     @pattern = pattern
1736   end
1737 end
new_function(type) click to toggle source

Returns a new function that produces a Regexp instance

     # File lib/puppet/pops/types/types.rb
1684 def self.new_function(type)
1685   @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1686     dispatch :from_string do
1687       param 'String', :pattern
1688       optional_param 'Boolean', :escape
1689     end
1690 
1691     def from_string(pattern, escape = false)
1692       Regexp.new(escape ? Regexp.escape(pattern) : pattern)
1693     end
1694   end
1695 end
regexp_to_s(regexp) click to toggle source

@param regexp [Regexp] the regular expression @return [String] the Regexp as a string without escaped slash

     # File lib/puppet/pops/types/types.rb
1707 def self.regexp_to_s(regexp)
1708   append_flags_group(regexp.source, regexp.options)
1709 end
regexp_to_s_with_delimiters(regexp) click to toggle source

@param regexp [Regexp] the regular expression @return [String] the Regexp as a slash delimited string with slashes escaped

     # File lib/puppet/pops/types/types.rb
1701 def self.regexp_to_s_with_delimiters(regexp)
1702   regexp.options == 0 ? regexp.inspect : "/#{regexp}/"
1703 end
register_ptype(loader, ir) click to toggle source
     # File lib/puppet/pops/types/types.rb
1673 def self.register_ptype(loader, ir)
1674   create_ptype(loader, ir, 'ScalarType',
1675     'pattern' => {
1676       KEY_TYPE => PVariantType.new([PUndefType::DEFAULT, PStringType::DEFAULT, PRegexpType::DEFAULT]),
1677       KEY_VALUE => nil
1678     })
1679 end

Public Instance Methods

eql?(o) click to toggle source
     # File lib/puppet/pops/types/types.rb
1747 def eql?(o)
1748   self.class == o.class && @pattern == o.pattern
1749 end
from_string(pattern, escape = false) click to toggle source
     # File lib/puppet/pops/types/types.rb
1691 def from_string(pattern, escape = false)
1692   Regexp.new(escape ? Regexp.escape(pattern) : pattern)
1693 end
hash() click to toggle source
     # File lib/puppet/pops/types/types.rb
1743 def hash
1744   @pattern.hash
1745 end
instance?(o, guard=nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
1751 def instance?(o, guard=nil)
1752   o.is_a?(Regexp) && @pattern.nil? || regexp == o
1753 end
regexp() click to toggle source
     # File lib/puppet/pops/types/types.rb
1739 def regexp
1740   @regexp ||= Regexp.new(@pattern || '')
1741 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

     # File lib/puppet/pops/types/types.rb
1761 def _assignable?(o, guard)
1762   o.is_a?(PRegexpType) && (@pattern.nil? || @pattern == o.pattern)
1763 end