aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/ordering.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra/ordering.rb')
-rw-r--r--lib/arel/algebra/ordering.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/arel/algebra/ordering.rb b/lib/arel/algebra/ordering.rb
index 984327aaf7..8ed3e1e6e6 100644
--- a/lib/arel/algebra/ordering.rb
+++ b/lib/arel/algebra/ordering.rb
@@ -13,10 +13,23 @@ module Arel
def == other
super || (self.class === other && attribute == other.attribute)
end
+
+ def eval(row1, row2)
+ (attribute.eval(row1) <=> attribute.eval(row2)) * direction
+ end
+
+ def to_sql(formatter = Sql::OrderClause.new(relation))
+ formatter.ordering self
+ end
end
class Ascending < Ordering
+ def direction; 1 end
+ def direction_sql; 'ASC' end
end
+
class Descending < Ordering
+ def direction_sql; 'DESC' end
+ def direction; -1 end
end
end