Class: Arel::Order

Inherits:
Compound show all
Defined in:
lib/arel/algebra/relations/operations/order.rb

Instance Attribute Summary collapse

Attributes inherited from Compound

#engine, #relation

Attributes included from Relation

#count

Instance Method Summary collapse

Methods inherited from Compound

#attributes, #column_for, #externalizable?, #join?, #joins, #name, #skipped, #sources, #table, #table_alias, #table_sql, #taken, #unoperated_rows

Methods included from Relation

#[], #alias, #attributes, #bind, #call, #christener, #compiler, #delete, #each, #exclusion_predicate_sql, #externalizable?, #externalize, #find_attribute_matching_name, #from, #from_clauses, #group_clauses, #groupings, #having_clauses, #havings, #inclusion_predicate_sql, #insert, #inserts, #join, #join?, #joins, #lock, #locked, #order_clauses, #outer_join, #position_of, #primary_key, #project, #projections, #select_clauses, #session, #skip, #skipped, #sources, #take, #taken, #to_sql, #update, #where, #where_clauses, #wheres

Constructor Details

#initialize(relation, orderings) ⇒ Order

Returns a new instance of Order.



5
6
7
8
# File 'lib/arel/algebra/relations/operations/order.rb', line 5

def initialize(relation, orderings)
  super(relation)
  @orderings = orderings.collect { |o| o.bind(relation) }
end

Instance Attribute Details

#orderingsObject (readonly)

Returns the value of attribute orderings.



3
4
5
# File 'lib/arel/algebra/relations/operations/order.rb', line 3

def orderings
  @orderings
end

Instance Method Details

#evalObject



16
17
18
19
20
21
# File 'lib/arel/algebra/relations/operations/order.rb', line 16

def eval
  unoperated_rows.sort do |row1, row2|
    ordering = orders.detect { |o| o.eval(row1, row2) != 0 } || orders.last
    ordering.eval(row1, row2)
  end
end

#ordersObject

TESTME



11
12
13
14
# File 'lib/arel/algebra/relations/operations/order.rb', line 11

def orders
  # QUESTION - do we still need relation.orders ?
  (orderings + relation.orders).collect { |o| o.bind(self) }.collect { |o| o.to_ordering }
end