Class: Squeel::Visitors::OrderVisitor

Inherits:
Visitor
  • Object
show all
Includes:
PredicateVisitation
Defined in:
lib/squeel/visitors/order_visitor.rb

Constant Summary

Constants included from PredicateVisitation

PredicateVisitation::EXPAND_BELONGS_TO_METHODS, PredicateVisitation::FALSE_SQL, PredicateVisitation::TRUE_SQL

Constants inherited from Visitor

Visitor::DISPATCH

Instance Attribute Summary

Attributes inherited from Visitor

#context

Instance Method Summary collapse

Methods included from PredicateVisitation

#arel_predicate_for, #attribute_in_array, #attribute_not_in_array, #quote_for_node, #visit_Squeel_Nodes_Predicate, #visit_Squeel_Nodes_Sifter

Methods inherited from Visitor

#accept, #accept!, #can_visit?, can_visit?, #hash_context_shifted?, #implies_hash_context_shift?, #initialize, #quote, #quoted?, #symbolify, #visit, #visit!, #visit_ActiveRecord_Base, #visit_ActiveRecord_Relation, #visit_Arel_Nodes_Node, #visit_Array, #visit_Array!, #visit_Hash, #visit_Hash!, #visit_Squeel_Nodes_And, #visit_Squeel_Nodes_As, #visit_Squeel_Nodes_Function, #visit_Squeel_Nodes_Grouping, #visit_Squeel_Nodes_KeyPath, #visit_Squeel_Nodes_KeyPath!, #visit_Squeel_Nodes_Literal, #visit_Squeel_Nodes_Not, #visit_Squeel_Nodes_Operation, #visit_Squeel_Nodes_Or, #visit_Squeel_Nodes_Stub, #visit_Symbol, #visit_passthrough, #visit_with_hash_context_shift, #visit_with_hash_context_shift!, #visit_without_hash_context_shift

Constructor Details

This class inherits a constructor from Squeel::Visitors::Visitor

Instance Method Details

#visit_Squeel_Nodes_Order(o, parent) ⇒ Arel::Nodes::Ordering (private)

Visit an Order node.

Parameters:

  • o (Nodes::Order)

    The order node to visit

  • parent

    The node's parent within the context

Returns:

  • (Arel::Nodes::Ordering)

    An ascending or desending ordering


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/squeel/visitors/order_visitor.rb', line 13

def visit_Squeel_Nodes_Order(o, parent)
  if defined?(Arel::Nodes::Descending)
    if o.descending?
      Arel::Nodes::Descending.new(visit(o.expr, parent))
    else
      Arel::Nodes::Ascending.new(visit(o.expr, parent))
    end
  else
    visit(o.expr, parent).send(o.descending? ? :desc : :asc)
  end
end