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 PScalarType

#instance?

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #generalize, #instance?, #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.



1507
1508
1509
1510
1511
1512
1513
1514
# File 'lib/puppet/pops/types/types.rb', line 1507

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)



1505
1506
1507
# File 'lib/puppet/pops/types/types.rb', line 1505

def pattern
  @pattern
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1498
1499
1500
1501
1502
1503
1504
# File 'lib/puppet/pops/types/types.rb', line 1498

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)


1524
1525
1526
# File 'lib/puppet/pops/types/types.rb', line 1524

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

#hashObject



1520
1521
1522
# File 'lib/puppet/pops/types/types.rb', line 1520

def hash
  @pattern.hash
end

#regexpObject



1516
1517
1518
# File 'lib/puppet/pops/types/types.rb', line 1516

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