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.



1945
1946
1947
1948
1949
1950
1951
# File 'lib/puppet/pops/model/ast.rb', line 1945

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)



1943
1944
1945
# File 'lib/puppet/pops/model/ast.rb', line 1943

def body
  @body
end

#nameObject (readonly)



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

def name
  @name
end

#parametersObject (readonly)



1942
1943
1944
# File 'lib/puppet/pops/model/ast.rb', line 1942

def parameters
  @parameters
end

Class Method Details

._pcore_typeObject



1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
# File 'lib/puppet/pops/model/ast.rb', line 1896

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



1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
# File 'lib/puppet/pops/model/ast.rb', line 1929

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



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

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



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

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



1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
# File 'lib/puppet/pops/model/ast.rb', line 1966

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:



1961
1962
1963
1964
# File 'lib/puppet/pops/model/ast.rb', line 1961

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

#_pcore_init_hashObject



1953
1954
1955
1956
1957
1958
1959
# File 'lib/puppet/pops/model/ast.rb', line 1953

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)


1979
1980
1981
1982
1983
1984
# File 'lib/puppet/pops/model/ast.rb', line 1979

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