Class: ActiveRecord::HierarchicalQuery::Orderings
- Inherits:
-
Object
- Object
- ActiveRecord::HierarchicalQuery::Orderings
- Includes:
- Enumerable
- Defined in:
- lib/active_record/hierarchical_query/orderings.rb
Constant Summary collapse
- NATURAL_SORT_TYPES =
Set[ :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :boolean, :itet, :cidr, :ltree ]
Instance Attribute Summary collapse
-
#order_values ⇒ Object
readonly
Returns the value of attribute order_values.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(order_values, table) ⇒ Orderings
constructor
A new instance of Orderings.
-
#row_number_expression ⇒ Arel::Nodes::Node
Returns order expression to be inserted into SELECT clauses of both non-recursive and recursive terms.
Constructor Details
#initialize(order_values, table) ⇒ Orderings
Returns a new instance of Orderings.
16 17 18 19 |
# File 'lib/active_record/hierarchical_query/orderings.rb', line 16 def initialize(order_values, table) @order_values, @table = order_values, table @values = nil # cached orderings end |
Instance Attribute Details
#order_values ⇒ Object (readonly)
Returns the value of attribute order_values.
12 13 14 |
# File 'lib/active_record/hierarchical_query/orderings.rb', line 12 def order_values @order_values end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
12 13 14 |
# File 'lib/active_record/hierarchical_query/orderings.rb', line 12 def table @table end |
Instance Method Details
#each(&block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_record/hierarchical_query/orderings.rb', line 21 def each(&block) return @values.each(&block) if @values return enum_for(__method__) unless block_given? @values = [] order_values.each do |value| Array.wrap(as_orderings(value)).each do |ordering| @values << ordering end end @values.each(&block) end |
#row_number_expression ⇒ Arel::Nodes::Node
Returns order expression to be inserted into SELECT clauses of both non-recursive and recursive terms.
40 41 42 43 44 45 46 |
# File 'lib/active_record/hierarchical_query/orderings.rb', line 40 def row_number_expression if raw_ordering? order_attribute else Arel.sql("ROW_NUMBER() OVER (ORDER BY #{map(&:to_sql).join(', ')})") end end |