forked from brynary/arel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from ernie/reverse_ordering
Allow reversal of orderings
- Loading branch information
Showing
15 changed files
with
135 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ def initialize expr | |
Not | ||
Offset | ||
On | ||
Ordering | ||
Top | ||
Lock | ||
DistinctOn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'helper' | ||
|
||
module Arel | ||
module Nodes | ||
class TestAscending < MiniTest::Unit::TestCase | ||
def test_construct | ||
ascending = Ascending.new 'zomg' | ||
assert_equal 'zomg', ascending.expr | ||
end | ||
|
||
def test_reverse | ||
ascending = Ascending.new 'zomg' | ||
descending = ascending.reverse | ||
assert_kind_of Descending, descending | ||
assert_equal ascending.expr, descending.expr | ||
end | ||
|
||
def test_direction | ||
ascending = Ascending.new 'zomg' | ||
assert_equal :asc, ascending.direction | ||
end | ||
|
||
def test_ascending? | ||
ascending = Ascending.new 'zomg' | ||
assert ascending.ascending? | ||
end | ||
|
||
def test_descending? | ||
ascending = Ascending.new 'zomg' | ||
assert !ascending.descending? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'helper' | ||
|
||
module Arel | ||
module Nodes | ||
class TestDescending < MiniTest::Unit::TestCase | ||
def test_construct | ||
descending = Descending.new 'zomg' | ||
assert_equal 'zomg', descending.expr | ||
end | ||
|
||
def test_reverse | ||
descending = Descending.new 'zomg' | ||
ascending = descending.reverse | ||
assert_kind_of Ascending, ascending | ||
assert_equal descending.expr, ascending.expr | ||
end | ||
|
||
def test_direction | ||
descending = Descending.new 'zomg' | ||
assert_equal :desc, descending.direction | ||
end | ||
|
||
def test_ascending? | ||
descending = Descending.new 'zomg' | ||
assert !descending.ascending? | ||
end | ||
|
||
def test_descending? | ||
descending = Descending.new 'zomg' | ||
assert descending.descending? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
645afa0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a new version 2.1.2 here. As Rails tests are failing. for reverse. Rails with Arel master works fine.
645afa0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1