Class: Puppet::Pops::Types::PRegexpType

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

Overview

API:

  • public

Constant Summary collapse

DEFAULT =

API:

  • public

PRegexpType.new(nil)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PScalarType

#roundtrip_with_string?

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, #create, create, #generalize, #iterable?, #iterable_type, #kind_of_callable?, #name, #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 Visitable

#accept

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type

Constructor Details

#initialize(pattern) ⇒ PRegexpType

Returns a new instance of PRegexpType.

API:

  • public



1574
1575
1576
1577
1578
1579
1580
1581
# File 'lib/puppet/pops/types/types.rb', line 1574

def initialize(pattern)
  if pattern.is_a?(Regexp)
    @regexp = pattern
    @pattern = pattern.options == 0 ? pattern.source : pattern.to_s
  else
    @pattern = pattern
  end
end

Instance Attribute Details

#patternObject (readonly)

API:

  • public



1572
1573
1574
# File 'lib/puppet/pops/types/types.rb', line 1572

def pattern
  @pattern
end

Class Method Details

.new_function(_, loader) ⇒ Object

Returns a new function that produces a Regexp instance

API:

  • public



1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
# File 'lib/puppet/pops/types/types.rb', line 1560

def self.new_function(_, loader)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_float, loader) do
    dispatch :from_string do
      param 'String', :pattern
    end

    def from_string(pattern)
      Regexp.new(pattern)
    end
  end
end

.register_ptype(loader, ir) ⇒ Object

API:

  • public



1549
1550
1551
1552
1553
1554
1555
# File 'lib/puppet/pops/types/types.rb', line 1549

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'ScalarType',
    'pattern' => {
      KEY_TYPE => PVariantType.new([PUndefType::DEFAULT, PStringType::DEFAULT, PRegexpType::DEFAULT]),
      KEY_VALUE => nil
    })
end

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

API:

  • public



1591
1592
1593
# File 'lib/puppet/pops/types/types.rb', line 1591

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

#hashObject

API:

  • public



1587
1588
1589
# File 'lib/puppet/pops/types/types.rb', line 1587

def hash
  @pattern.hash
end

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

Returns:

API:

  • public



1595
1596
1597
# File 'lib/puppet/pops/types/types.rb', line 1595

def instance?(o, guard=nil)
  o.is_a?(Regexp) && (@pattern.nil? || @pattern == (o.options == 0 ? o.source : o.to_s))
end

#regexpObject

API:

  • public



1583
1584
1585
# File 'lib/puppet/pops/types/types.rb', line 1583

def regexp
  @regexp ||= Regexp.new(@pattern || '')
end