Class: Puppet::Pops::Model::NamedDefinition

Inherits:
Definition 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

Constructor Details

#initialize(locator, offset, length, name, parameters = _pcore_type['parameters'].value, body = nil) ⇒ NamedDefinition

Returns a new instance of NamedDefinition.



1896
1897
1898
1899
1900
1901
1902
# File 'lib/puppet/pops/model/ast.rb', line 1896

def initialize(locator, offset, length, name, parameters = _pcore_type['parameters'].value, body = nil)
  super(locator, offset, length)
  @hash = @hash ^ name.hash ^ parameters.hash ^ body.hash
  @name = name
  @parameters = parameters
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)



1894
1895
1896
# File 'lib/puppet/pops/model/ast.rb', line 1894

def body
  @body
end

#nameObject (readonly)



1892
1893
1894
# File 'lib/puppet/pops/model/ast.rb', line 1892

def name
  @name
end

#parametersObject (readonly)



1893
1894
1895
# File 'lib/puppet/pops/model/ast.rb', line 1893

def parameters
  @parameters
end

Class Method Details

._pcore_typeObject



1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
# File 'lib/puppet/pops/model/ast.rb', line 1849

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::NamedDefinition', {
    'parent' => Definition._pcore_type,
    'attributes' => {
      'name' => Types::PStringType::DEFAULT,
      'parameters' => {
        'type' => Types::PArrayType.new(Parameter._pcore_type),
        'value' => []
      },
      'body' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      }
    }
  })
end

.create(locator, offset, length, name, parameters = _pcore_type['parameters'].value, body = nil) ⇒ Object



1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
# File 'lib/puppet/pops/model/ast.rb', line 1880

def self.create(locator, offset, length, name, parameters = _pcore_type['parameters'].value, body = 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::NamedDefinition[name]', attrs['name'].type, name)
  ta.assert_instance_of('Puppet::AST::NamedDefinition[parameters]', attrs['parameters'].type, parameters)
  ta.assert_instance_of('Puppet::AST::NamedDefinition[body]', attrs['body'].type, body)
  new(locator, offset, length, name, parameters, body)
end

.from_asserted_hash(init_hash) ⇒ Object



1870
1871
1872
1873
1874
1875
1876
1877
1878
# File 'lib/puppet/pops/model/ast.rb', line 1870

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['name'],
    init_hash.fetch('parameters') { _pcore_type['parameters'].value },
    init_hash['body'])
end

.from_hash(init_hash) ⇒ Object



1866
1867
1868
# File 'lib/puppet/pops/model/ast.rb', line 1866

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
# File 'lib/puppet/pops/model/ast.rb', line 1917

def _pcore_all_contents(path, &block)
  path << self
  @parameters.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  unless @body.nil?
    block.call(@body, path)
    @body._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:



1912
1913
1914
1915
# File 'lib/puppet/pops/model/ast.rb', line 1912

def _pcore_contents
  @parameters.each { |value| yield(value) }
  yield(@body) unless @body.nil?
end

#_pcore_init_hashObject



1904
1905
1906
1907
1908
1909
1910
# File 'lib/puppet/pops/model/ast.rb', line 1904

def _pcore_init_hash
  result = super
  result['name'] = @name
  result['parameters'] = @parameters unless _pcore_type['parameters'].default_value?(@parameters)
  result['body'] = @body unless @body == nil
  result
end

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

Returns:

  • (Boolean)


1930
1931
1932
1933
1934
1935
# File 'lib/puppet/pops/model/ast.rb', line 1930

def eql?(o)
  super &&
  @name.eql?(o.name) &&
  @parameters.eql?(o.parameters) &&
  @body.eql?(o.body)
end