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

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

Constant Summary collapse

DEFAULT =
PRegexpType.new(nil)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PAnyType

#==, #accept, #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 Visitable

#accept

Methods included from PuppetObject

#_ptype

Constructor Details

#initialize(pattern) ⇒ PRegexpType

Returns a new instance of PRegexpType.



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

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)



1558
1559
1560
# File 'lib/puppet/pops/types/types.rb', line 1558

def pattern
  @pattern
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



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

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:

  • (Boolean)


1577
1578
1579
# File 'lib/puppet/pops/types/types.rb', line 1577

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

#hashObject



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

def hash
  @pattern.hash
end

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

Returns:

  • (Boolean)


1581
1582
1583
# File 'lib/puppet/pops/types/types.rb', line 1581

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

#regexpObject



1569
1570
1571
# File 'lib/puppet/pops/types/types.rb', line 1569

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