Class: Puppet::Pops::Model::FunctionDefinition

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

Direct Known Subclasses

PlanDefinition

Instance Attribute Summary collapse

Attributes inherited from NamedDefinition

#body, #name, #parameters

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, return_type = nil) ⇒ FunctionDefinition

Returns a new instance of FunctionDefinition


1990
1991
1992
1993
1994
# File 'lib/puppet/pops/model/ast.rb', line 1990

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

Instance Attribute Details

#return_typeObject (readonly)


1988
1989
1990
# File 'lib/puppet/pops/model/ast.rb', line 1988

def return_type
  @return_type
end

Class Method Details

._pcore_typeObject


1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
# File 'lib/puppet/pops/model/ast.rb', line 1948

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::FunctionDefinition', {
    'parent' => NamedDefinition._pcore_type,
    'attributes' => {
      'return_type' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      }
    }
  })
end

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


1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
# File 'lib/puppet/pops/model/ast.rb', line 1975

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

.from_asserted_hash(init_hash) ⇒ Object


1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
# File 'lib/puppet/pops/model/ast.rb', line 1964

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'],
    init_hash['return_type'])
end

.from_hash(init_hash) ⇒ Object


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

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
# File 'lib/puppet/pops/model/ast.rb', line 2008

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
  unless @return_type.nil?
    block.call(@return_type, path)
    @return_type._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:


2002
2003
2004
2005
2006
# File 'lib/puppet/pops/model/ast.rb', line 2002

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

#_pcore_init_hashObject


1996
1997
1998
1999
2000
# File 'lib/puppet/pops/model/ast.rb', line 1996

def _pcore_init_hash
  result = super
  result['return_type'] = @return_type unless @return_type == nil
  result
end

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


2025
2026
2027
2028
# File 'lib/puppet/pops/model/ast.rb', line 2025

def eql?(o)
  super &&
  @return_type.eql?(o.return_type)
end