Class: ActiveGraph::Core::Query::PartitionedClauses
- Inherits:
-
Object
- Object
- ActiveGraph::Core::Query::PartitionedClauses
- Includes:
- Enumerable
- Defined in:
- lib/active_graph/core/query.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
- #generate_partitioning! ⇒ Object
-
#initialize(clauses) ⇒ PartitionedClauses
constructor
A new instance of PartitionedClauses.
Constructor Details
#initialize(clauses) ⇒ PartitionedClauses
Returns a new instance of PartitionedClauses.
414 415 416 417 |
# File 'lib/active_graph/core/query.rb', line 414 def initialize(clauses) @clauses = clauses @partitioning = [[]] end |
Class Method Details
.clause_is_order_or_limit?(clause) ⇒ Boolean
468 469 470 471 |
# File 'lib/active_graph/core/query.rb', line 468 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
#each ⇒ Object
421 422 423 424 425 |
# File 'lib/active_graph/core/query.rb', line 421 def each generate_partitioning! @partitioning.each { |partition| yield partition } end |
#generate_partitioning! ⇒ Object
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/active_graph/core/query.rb', line 427 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 |