aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations/order.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/relations/order.rb')
-rw-r--r--lib/arel/relations/order.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/arel/relations/order.rb b/lib/arel/relations/order.rb
new file mode 100644
index 0000000000..91526da02c
--- /dev/null
+++ b/lib/arel/relations/order.rb
@@ -0,0 +1,21 @@
+module Arel
+ class Order < Compound
+ attr_reader :ordering
+
+ def initialize(relation, *orders)
+ ordering = orders.pop
+ @relation = orders.empty?? relation : Order.new(relation, *orders)
+ @ordering = ordering.bind(@relation)
+ end
+
+ def ==(other)
+ self.class == other.class and
+ relation == other.relation and
+ ordering == other.ordering
+ end
+
+ def orders
+ relation.orders + [ordering]
+ end
+ end
+end \ No newline at end of file