Class: ActiveGraph::Core::Query::PartitionedClauses

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clauses) ⇒ PartitionedClauses

Returns a new instance of PartitionedClauses.


417
418
419
420
# File 'lib/active_graph/core/query.rb', line 417

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

Class Method Details

.clause_is_order_or_limit?(clause) ⇒ Boolean

Returns:

  • (Boolean)

471
472
473
474
# File 'lib/active_graph/core/query.rb', line 471

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

Instance Method Details

#eachObject


424
425
426
427
428
# File 'lib/active_graph/core/query.rb', line 424

def each
  generate_partitioning!

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

#generate_partitioning!Object


430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/active_graph/core/query.rb', line 430

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?(::ActiveGraph::Core::QueryClauses::OrderClause) ? 1 : 0 }
    else
      @partitioning.last << clause
    end
  end
end