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, #to_s

Constructor Details

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

Returns a new instance of NamedDefinition


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

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)


1902
1903
1904
# File 'lib/puppet/pops/model/ast.rb', line 1902

def body
  @body
end

#nameObject (readonly)


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

def name
  @name
end

#parametersObject (readonly)


1901
1902
1903
# File 'lib/puppet/pops/model/ast.rb', line 1901

def parameters
  @parameters
end

Class Method Details

._pcore_typeObject


1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
# File 'lib/puppet/pops/model/ast.rb', line 1857

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


1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
# File 'lib/puppet/pops/model/ast.rb', line 1888

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


1878
1879
1880
1881
1882
1883
1884
1885
1886
# File 'lib/puppet/pops/model/ast.rb', line 1878

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


1874
1875
1876
# File 'lib/puppet/pops/model/ast.rb', line 1874

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


1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
# File 'lib/puppet/pops/model/ast.rb', line 1925

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:


1920
1921
1922
1923
# File 'lib/puppet/pops/model/ast.rb', line 1920

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

#_pcore_init_hashObject


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

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: ==


1938
1939
1940
1941
1942
1943
# File 'lib/puppet/pops/model/ast.rb', line 1938

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