aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/ordering.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-26 13:32:25 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-26 13:32:25 -0700
commit3f1ab2b977d921ed7f6cd4ec2e9204b8ad22148e (patch)
tree181e0dc74c82d9d2f566978a4f33c3dc76112f1b /lib/arel/algebra/ordering.rb
parent87b2f70fe143ec2abab5f3831ade706b3cf8707e (diff)
downloadrails-3f1ab2b977d921ed7f6cd4ec2e9204b8ad22148e.tar.gz
rails-3f1ab2b977d921ed7f6cd4ec2e9204b8ad22148e.tar.bz2
rails-3f1ab2b977d921ed7f6cd4ec2e9204b8ad22148e.zip
removing more duplication
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