Class: Squeel::Nodes::Order
- Inherits:
-
Object
- Object
- Squeel::Nodes::Order
- Defined in:
- lib/squeel/nodes/order.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#expr ⇒ Object
readonly
Returns the value of attribute expr.
Instance Method Summary collapse
- #asc ⇒ Object
- #ascending? ⇒ Boolean
- #desc ⇒ Object
- #descending? ⇒ Boolean
-
#initialize(expr, direction = 1) ⇒ Order
constructor
A new instance of Order.
- #reverse! ⇒ Object
Constructor Details
#initialize(expr, direction = 1) ⇒ Order
Returns a new instance of Order.
6 7 8 9 |
# File 'lib/squeel/nodes/order.rb', line 6 def initialize(expr, direction = 1) raise ArgumentError, "Direction #{direction} is not valid. Must be -1 or 1." unless [-1,1].include? direction @expr, @direction = expr, direction end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
4 5 6 |
# File 'lib/squeel/nodes/order.rb', line 4 def direction @direction end |
#expr ⇒ Object (readonly)
Returns the value of attribute expr.
4 5 6 |
# File 'lib/squeel/nodes/order.rb', line 4 def expr @expr end |
Instance Method Details
#asc ⇒ Object
11 12 13 14 |
# File 'lib/squeel/nodes/order.rb', line 11 def asc @direction = 1 self end |
#ascending? ⇒ Boolean
21 22 23 |
# File 'lib/squeel/nodes/order.rb', line 21 def ascending? @direction == 1 end |
#desc ⇒ Object
16 17 18 19 |
# File 'lib/squeel/nodes/order.rb', line 16 def desc @direction = -1 self end |
#descending? ⇒ Boolean
25 26 27 |
# File 'lib/squeel/nodes/order.rb', line 25 def descending? @direction == -1 end |
#reverse! ⇒ Object
29 30 31 32 |
# File 'lib/squeel/nodes/order.rb', line 29 def reverse! @direction = - @direction self end |