Class: Squeel::Nodes::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/squeel/nodes/order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expr, direction = 1) ⇒ Order

Returns a new instance of Order.

Raises:

  • (ArgumentError)


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

#directionObject (readonly)

Returns the value of attribute direction.



4
5
6
# File 'lib/squeel/nodes/order.rb', line 4

def direction
  @direction
end

#exprObject (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

#ascObject



11
12
13
14
# File 'lib/squeel/nodes/order.rb', line 11

def asc
  @direction = 1
  self
end

#ascending?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/squeel/nodes/order.rb', line 21

def ascending?
  @direction == 1
end

#descObject



16
17
18
19
# File 'lib/squeel/nodes/order.rb', line 16

def desc
  @direction = -1
  self
end

#descending?Boolean

Returns:

  • (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