Class: Neo4j::Core::Query::PartitionedClauses

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/neo4j/core/query.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clauses) ⇒ PartitionedClauses

Returns a new instance of PartitionedClauses.



436
437
438
439
# File 'lib/neo4j/core/query.rb', line 436

def initialize(clauses)
  @clauses = clauses
  @partitioning = [[]]
end

Class Method Details

.clause_is_order_or_limit?(clause) ⇒ Boolean

Returns:

  • (Boolean)


490
491
492
493
# File 'lib/neo4j/core/query.rb', line 490

def clause_is_order_or_limit?(clause)
  clause.is_a?(::Neo4j::Core::QueryClauses::OrderClause) ||
    clause.is_a?(::Neo4j::Core::QueryClauses::LimitClause)
end

Instance Method Details

#eachObject



443
444
445
446
447
# File 'lib/neo4j/core/query.rb', line 443

def each
  generate_partitioning!

  @partitioning.each { |partition| yield partition }
end

#generate_partitioning!Object



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/neo4j/core/query.rb', line 449

def generate_partitioning!
  @partitioning = [[]]

  @clauses.each do |clause|
    if clause.nil? && !fresh_partition?
      @partitioning << []
    elsif clause_is_order_or_limit_directly_following_with_or_order?(clause)
      second_to_last << clause
    elsif clause_is_with_following_order_or_limit?(clause)
      second_to_last << clause
      second_to_last.sort_by! { |c| c.is_a?(::Neo4j::Core::QueryClauses::OrderClause) ? 1 : 0 }
    else
      @partitioning.last << clause
    end
  end
end