From 00d1482fefa1cf9c3753b58f4fe9b580c52ae935 Mon Sep 17 00:00:00 2001 From: Samuel Kadolph Date: Fri, 27 May 2011 17:21:40 -0400 Subject: Include Arel::Predicates to Arel::Nodes::Function so you can do table[:id].count.eq(2) --- lib/arel/nodes/function.rb | 1 + lib/arel/nodes/named_function.rb | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/arel/nodes') diff --git a/lib/arel/nodes/function.rb b/lib/arel/nodes/function.rb index 85347fc028..b6f6644678 100644 --- a/lib/arel/nodes/function.rb +++ b/lib/arel/nodes/function.rb @@ -2,6 +2,7 @@ module Arel module Nodes class Function < Arel::Nodes::Node include Arel::Expression + include Arel::Predications attr_accessor :expressions, :alias, :distinct def initialize expr, aliaz = nil diff --git a/lib/arel/nodes/named_function.rb b/lib/arel/nodes/named_function.rb index 5fca33e323..56669bf858 100644 --- a/lib/arel/nodes/named_function.rb +++ b/lib/arel/nodes/named_function.rb @@ -3,8 +3,6 @@ module Arel class NamedFunction < Arel::Nodes::Function attr_accessor :name - include Arel::Predications - def initialize name, expr, aliaz = nil super(expr, aliaz) @name = name -- cgit v1.2.3 From ba3578a22f824da3478b6dceb100deb9f41a56e9 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Tue, 14 Jun 2011 17:43:22 -0400 Subject: Break Ordering into Ascending/Descending nodes, allow reversal --- lib/arel/nodes/ascending.rb | 23 +++++++++++++++++++++++ lib/arel/nodes/descending.rb | 23 +++++++++++++++++++++++ lib/arel/nodes/ordering.rb | 16 +--------------- lib/arel/nodes/unary.rb | 1 + 4 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 lib/arel/nodes/ascending.rb create mode 100644 lib/arel/nodes/descending.rb (limited to 'lib/arel/nodes') diff --git a/lib/arel/nodes/ascending.rb b/lib/arel/nodes/ascending.rb new file mode 100644 index 0000000000..bca00a8339 --- /dev/null +++ b/lib/arel/nodes/ascending.rb @@ -0,0 +1,23 @@ +module Arel + module Nodes + class Ascending < Ordering + + def reverse + Descending.new(expr) + end + + def direction + :asc + end + + def ascending? + true + end + + def descending? + false + end + + end + end +end diff --git a/lib/arel/nodes/descending.rb b/lib/arel/nodes/descending.rb new file mode 100644 index 0000000000..d886bdcb5f --- /dev/null +++ b/lib/arel/nodes/descending.rb @@ -0,0 +1,23 @@ +module Arel + module Nodes + class Descending < Ordering + + def reverse + Ascending.new(expr) + end + + def direction + :desc + end + + def ascending? + false + end + + def descending? + true + end + + end + end +end diff --git a/lib/arel/nodes/ordering.rb b/lib/arel/nodes/ordering.rb index 0a3621cf54..efb4d18ae4 100644 --- a/lib/arel/nodes/ordering.rb +++ b/lib/arel/nodes/ordering.rb @@ -1,20 +1,6 @@ module Arel module Nodes - class Ordering < Arel::Nodes::Binary - alias :expr :left - alias :direction :right - - def initialize expr, direction = :asc - super - end - - def ascending? - direction == :asc - end - - def descending? - direction == :desc - end + class Ordering < Unary end end end diff --git a/lib/arel/nodes/unary.rb b/lib/arel/nodes/unary.rb index 5c4add4792..4688fff623 100644 --- a/lib/arel/nodes/unary.rb +++ b/lib/arel/nodes/unary.rb @@ -18,6 +18,7 @@ module Arel Not Offset On + Ordering Top Lock DistinctOn -- cgit v1.2.3