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

Constructor Details

#initialize(locator, offset, length, type_expr, query, operations = _pcore_type['operations'].value) ⇒ CollectExpression

Returns a new instance of CollectExpression.



1691
1692
1693
1694
1695
1696
1697
# File 'lib/puppet/pops/model/ast.rb', line 1691

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)



1689
1690
1691
# File 'lib/puppet/pops/model/ast.rb', line 1689

def operations
  @operations
end

#queryObject (readonly)



1688
1689
1690
# File 'lib/puppet/pops/model/ast.rb', line 1688

def query
  @query
end

#type_exprObject (readonly)



1687
1688
1689
# File 'lib/puppet/pops/model/ast.rb', line 1687

def type_expr
  @type_expr
end

Class Method Details

._pcore_typeObject



1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
# File 'lib/puppet/pops/model/ast.rb', line 1647

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



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

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



1665
1666
1667
1668
1669
1670
1671
1672
1673
# File 'lib/puppet/pops/model/ast.rb', line 1665

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



1661
1662
1663
# File 'lib/puppet/pops/model/ast.rb', line 1661

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



1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
# File 'lib/puppet/pops/model/ast.rb', line 1713

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:



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

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

#_pcore_init_hashObject



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

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)


1730
1731
1732
1733
1734
1735
# File 'lib/puppet/pops/model/ast.rb', line 1730

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