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


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

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)


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

def operations
  @operations
end

#queryObject (readonly)


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

def query
  @query
end

#type_exprObject (readonly)


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

def type_expr
  @type_expr
end

Class Method Details

._pcore_typeObject


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

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


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

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


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

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


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

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


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

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:


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

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

#_pcore_init_hashObject


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

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


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

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