Class: Puppet::Pops::Model::Parameter

Inherits:
Positioned show all
Defined in:
lib/puppet/pops/model/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Positioned

#length, #locator, #offset

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Positioned

#file, #line, #pos

Methods inherited from PopsObject

#to_s

Methods included from Types::PuppetObject

#_pcore_type, #to_s

Constructor Details

#initialize(locator, offset, length, name, value = nil, type_expr = nil, captures_rest = nil) ⇒ Parameter

Returns a new instance of Parameter


1802
1803
1804
1805
1806
1807
1808
1809
# File 'lib/puppet/pops/model/ast.rb', line 1802

def initialize(locator, offset, length, name, value = nil, type_expr = nil, captures_rest = nil)
  super(locator, offset, length)
  @hash = @hash ^ name.hash ^ value.hash ^ type_expr.hash ^ captures_rest.hash
  @name = name
  @value = value
  @type_expr = type_expr
  @captures_rest = captures_rest
end

Instance Attribute Details

#captures_restObject (readonly)


1800
1801
1802
# File 'lib/puppet/pops/model/ast.rb', line 1800

def captures_rest
  @captures_rest
end

#nameObject (readonly)


1797
1798
1799
# File 'lib/puppet/pops/model/ast.rb', line 1797

def name
  @name
end

#type_exprObject (readonly)


1799
1800
1801
# File 'lib/puppet/pops/model/ast.rb', line 1799

def type_expr
  @type_expr
end

#valueObject (readonly)


1798
1799
1800
# File 'lib/puppet/pops/model/ast.rb', line 1798

def value
  @value
end

Class Method Details

._pcore_typeObject


1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
# File 'lib/puppet/pops/model/ast.rb', line 1748

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::Parameter', {
    'parent' => Positioned._pcore_type,
    'attributes' => {
      'name' => Types::PStringType::DEFAULT,
      'value' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      },
      'type_expr' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      },
      'captures_rest' => {
        'type' => Types::POptionalType.new(Types::PBooleanType::DEFAULT),
        'value' => nil
      }
    }
  })
end

.create(locator, offset, length, name, value = nil, type_expr = nil, captures_rest = nil) ⇒ Object


1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
# File 'lib/puppet/pops/model/ast.rb', line 1784

def self.create(locator, offset, length, name, value = nil, type_expr = nil, captures_rest = nil)
  ta = Types::TypeAsserter
  attrs = _pcore_type.attributes(true)
  ta.assert_instance_of('Puppet::AST::Positioned[locator]', attrs['locator'].type, locator)
  ta.assert_instance_of('Puppet::AST::Positioned[offset]', attrs['offset'].type, offset)
  ta.assert_instance_of('Puppet::AST::Positioned[length]', attrs['length'].type, length)
  ta.assert_instance_of('Puppet::AST::Parameter[name]', attrs['name'].type, name)
  ta.assert_instance_of('Puppet::AST::Parameter[value]', attrs['value'].type, value)
  ta.assert_instance_of('Puppet::AST::Parameter[type_expr]', attrs['type_expr'].type, type_expr)
  ta.assert_instance_of('Puppet::AST::Parameter[captures_rest]', attrs['captures_rest'].type, captures_rest)
  new(locator, offset, length, name, value, type_expr, captures_rest)
end

.from_asserted_hash(init_hash) ⇒ Object


1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
# File 'lib/puppet/pops/model/ast.rb', line 1773

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['name'],
    init_hash['value'],
    init_hash['type_expr'],
    init_hash['captures_rest'])
end

.from_hash(init_hash) ⇒ Object


1769
1770
1771
# File 'lib/puppet/pops/model/ast.rb', line 1769

def self.from_hash(init_hash)
  from_asserted_hash(Types::TypeAsserter.assert_instance_of('Puppet::AST::Parameter initializer', _pcore_type.init_hash_type, init_hash))
end

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
# File 'lib/puppet/pops/model/ast.rb', line 1825

def _pcore_all_contents(path, &block)
  path << self
  unless @value.nil?
    block.call(@value, path)
    @value._pcore_all_contents(path, &block)
  end
  unless @type_expr.nil?
    block.call(@type_expr, path)
    @type_expr._pcore_all_contents(path, &block)
  end
  path.pop
end

#_pcore_contents {|@value| ... } ⇒ Object

Yields:


1820
1821
1822
1823
# File 'lib/puppet/pops/model/ast.rb', line 1820

def _pcore_contents
  yield(@value) unless @value.nil?
  yield(@type_expr) unless @type_expr.nil?
end

#_pcore_init_hashObject


1811
1812
1813
1814
1815
1816
1817
1818
# File 'lib/puppet/pops/model/ast.rb', line 1811

def _pcore_init_hash
  result = super
  result['name'] = @name
  result['value'] = @value unless @value == nil
  result['type_expr'] = @type_expr unless @type_expr == nil
  result['captures_rest'] = @captures_rest unless @captures_rest == nil
  result
end

#eql?(o) ⇒ Boolean Also known as: ==


1838
1839
1840
1841
1842
1843
1844
# File 'lib/puppet/pops/model/ast.rb', line 1838

def eql?(o)
  super &&
  @name.eql?(o.name) &&
  @value.eql?(o.value) &&
  @type_expr.eql?(o.type_expr) &&
  @captures_rest.eql?(o.captures_rest)
end