Class: ActiveRecord::Refined::AST::Ordering

Inherits:
Node
  • Object
show all
Defined in:
lib/active_record/refined/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(operand, direction, nulls = nil) ⇒ Ordering

Returns a new instance of Ordering.



1005
1006
1007
1008
1009
# File 'lib/active_record/refined/ast.rb', line 1005

def initialize(operand, direction, nulls = nil)
  @operand = operand
  @direction = direction
  @nulls = nulls
end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



1003
1004
1005
# File 'lib/active_record/refined/ast.rb', line 1003

def direction
  @direction
end

#nullsObject (readonly)

Returns the value of attribute nulls.



1003
1004
1005
# File 'lib/active_record/refined/ast.rb', line 1003

def nulls
  @nulls
end

#operandObject (readonly)

Returns the value of attribute operand.



1003
1004
1005
# File 'lib/active_record/refined/ast.rb', line 1003

def operand
  @operand
end

Instance Method Details

#nulls_firstObject

MySQL has no NULLS FIRST/LAST, but Arel emulates it there with a leading IS NULL ordering, so these are portable.



1013
1014
1015
# File 'lib/active_record/refined/ast.rb', line 1013

def nulls_first
  Ordering.new(operand, direction, :nulls_first)
end

#nulls_lastObject



1017
1018
1019
# File 'lib/active_record/refined/ast.rb', line 1017

def nulls_last
  Ordering.new(operand, direction, :nulls_last)
end

#to_arel(table, model) ⇒ Object



1021
1022
1023
1024
# File 'lib/active_record/refined/ast.rb', line 1021

def to_arel(table, model)
  ordering = to_arel_operand(operand, table, model).public_send(direction)
  nulls ? ordering.public_send(nulls) : ordering
end