Class: Puppet::Pops::Model::CollectExpression

Inherits:
Expression 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, type_expr, query, operations = _pcore_type['operations'].value) ⇒ CollectExpression

Returns a new instance of CollectExpression.



1700
1701
1702
1703
1704
1705
1706
# File 'lib/puppet/pops/model/ast.rb', line 1700

def initialize(locator, offset, length, type_expr, query, operations = _pcore_type['operations'].value)
  super(locator, offset, length)
  @hash = @hash ^ type_expr.hash ^ query.hash ^ operations.hash
  @type_expr = type_expr
  @query = query
  @operations = operations
end

Instance Attribute Details

#operationsObject (readonly)



1698
1699
1700
# File 'lib/puppet/pops/model/ast.rb', line 1698

def operations
  @operations
end

#queryObject (readonly)



1697
1698
1699
# File 'lib/puppet/pops/model/ast.rb', line 1697

def query
  @query
end

#type_exprObject (readonly)



1696
1697
1698
# File 'lib/puppet/pops/model/ast.rb', line 1696

def type_expr
  @type_expr
end

Class Method Details

._pcore_typeObject



1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
# File 'lib/puppet/pops/model/ast.rb', line 1656

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::CollectExpression', {
    'parent' => Expression._pcore_type,
    'attributes' => {
      'type_expr' => Expression._pcore_type,
      'query' => QueryExpression._pcore_type,
      'operations' => {
        'type' => Types::PArrayType.new(AbstractAttributeOperation._pcore_type),
        'value' => []
      }
    }
  })
end

.create(locator, offset, length, type_expr, query, operations = _pcore_type['operations'].value) ⇒ Object



1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
# File 'lib/puppet/pops/model/ast.rb', line 1684

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

.from_asserted_hash(init_hash) ⇒ Object



1674
1675
1676
1677
1678
1679
1680
1681
1682
# File 'lib/puppet/pops/model/ast.rb', line 1674

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['type_expr'],
    init_hash['query'],
    init_hash.fetch('operations') { _pcore_type['operations'].value })
end

.from_hash(init_hash) ⇒ Object



1670
1671
1672
# File 'lib/puppet/pops/model/ast.rb', line 1670

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
# File 'lib/puppet/pops/model/ast.rb', line 1722

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

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

Yields:



1716
1717
1718
1719
1720
# File 'lib/puppet/pops/model/ast.rb', line 1716

def _pcore_contents
  yield(@type_expr) unless @type_expr.nil?
  yield(@query) unless @query.nil?
  @operations.each { |value| yield(value) }
end

#_pcore_init_hashObject



1708
1709
1710
1711
1712
1713
1714
# File 'lib/puppet/pops/model/ast.rb', line 1708

def _pcore_init_hash
  result = super
  result['type_expr'] = @type_expr
  result['query'] = @query
  result['operations'] = @operations unless _pcore_type['operations'].default_value?(@operations)
  result
end

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

Returns:

  • (Boolean)


1739
1740
1741
1742
1743
1744
# File 'lib/puppet/pops/model/ast.rb', line 1739

def eql?(o)
  super &&
  @type_expr.eql?(o.type_expr) &&
  @query.eql?(o.query) &&
  @operations.eql?(o.operations)
end