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, #create, #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.



1536
1537
1538
1539
1540
1541
1542
1543
# File 'lib/puppet/pops/types/types.rb', line 1536

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)



1534
1535
1536
# File 'lib/puppet/pops/types/types.rb', line 1534

def pattern
  @pattern
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1527
1528
1529
1530
1531
1532
1533
# File 'lib/puppet/pops/types/types.rb', line 1527

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



1553
1554
1555
# File 'lib/puppet/pops/types/types.rb', line 1553

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

#hashObject



1549
1550
1551
# File 'lib/puppet/pops/types/types.rb', line 1549

def hash
  @pattern.hash
end

#regexpObject



1545
1546
1547
# File 'lib/puppet/pops/types/types.rb', line 1545

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