Class: Arel::Order
- Defined in:
- lib/arel/algebra/relations/operations/order.rb,
lib/arel/engines/memory/relations/operations.rb
Instance Attribute Summary
Attributes inherited from Compound
Attributes included from Relation
Instance Method Summary collapse
- #eval ⇒ Object
-
#initialize(relation, *orderings, &block) ⇒ Order
constructor
A new instance of Order.
-
#orders ⇒ Object
TESTME.
Methods inherited from Compound
#attributes, #build_query, #engine, #eql?, #hash, requires, #unoperated_rows
Methods included from Relation
#bind, #call, #christener, #compiler, #exclusion_predicate_sql, #externalizable?, #externalize, #inclusion_predicate_sql, #join?, #primary_key, #session, #to_sql
Methods included from Relation::DefaultOperations
#attributes, #groupings, #havings, #inserts, #joins, #locked, #projections, #skipped, #sources, #taken, #wheres
Methods included from Relation::AttributeAccessable
#[], #find_attribute_matching_attribute, #find_attribute_matching_name, #position_of
Methods included from Relation::Operable
#alias, #join, #lock, #outer_join
Methods included from Relation::Operable::Writable
Methods included from Relation::Enumerable
Constructor Details
#initialize(relation, *orderings, &block) ⇒ Order
Returns a new instance of Order.
7 8 9 10 11 |
# File 'lib/arel/algebra/relations/operations/order.rb', line 7 def initialize(relation, *orderings, &block) @relation = relation @orderings = (orderings + arguments_from_block(relation, &block)) \ .collect { |o| o.bind(relation) } end |
Instance Method Details
#eval ⇒ Object
9 10 11 12 13 14 |
# File 'lib/arel/engines/memory/relations/operations.rb', line 9 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 |
#orders ⇒ Object
TESTME
14 15 16 17 |
# File 'lib/arel/algebra/relations/operations/order.rb', line 14 def orders # QUESTION - do we still need relation.orders ? (orderings + relation.orders).collect { |o| o.bind(self) }.collect { |o| o.to_ordering } end |