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, #collate, #desc

Constructor Details

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

Returns a new instance of Ordering.



1842
1843
1844
1845
1846
# File 'lib/active_record/refined/ast.rb', line 1842

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

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



1840
1841
1842
# File 'lib/active_record/refined/ast.rb', line 1840

def direction
  @direction
end

#nullsObject (readonly)

Returns the value of attribute nulls.



1840
1841
1842
# File 'lib/active_record/refined/ast.rb', line 1840

def nulls
  @nulls
end

#operandObject (readonly)

Returns the value of attribute operand.



1840
1841
1842
# File 'lib/active_record/refined/ast.rb', line 1840

def operand
  @operand
end

Instance Method Details

#nulls_firstAST::Ordering

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

Returns:



1854
1855
1856
# File 'lib/active_record/refined/ast.rb', line 1854

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

#nulls_lastAST::Ordering

NULLS LAST.

Returns:



1860
1861
1862
# File 'lib/active_record/refined/ast.rb', line 1860

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

#to_arel(table, model) ⇒ Object



1864
1865
1866
1867
# File 'lib/active_record/refined/ast.rb', line 1864

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