Module: Babik::QuerySet::Sortable

Included in:
AbstractBase
Defined in:
lib/babik/queryset/mixins/sortable.rb

Overview

Sort functionality of QuerySet

Instance Method Summary collapse

Instance Method Details

#disorder!QuerySet

Remove the order on this QuerySet according to an order

Returns:

  • (QuerySet)

    reference to this QuerySet.



19
20
21
22
# File 'lib/babik/queryset/mixins/sortable.rb', line 19

def disorder!
  @_order = nil
  self
end

#invert_order!QuerySet

Invert the order e.g.

first_name ASC, last_name ASC, created_at DESC => invert => first_name DESC, last_name DESC, created_at ASC

Returns:

  • (QuerySet)

    reference to this QuerySet.



36
37
38
39
# File 'lib/babik/queryset/mixins/sortable.rb', line 36

def invert_order!
  @_order.invert!
  self
end

#order!(*order) ⇒ QuerySet

Alias for order_by

Parameters:

  • order (Array, String, Hash)

    ordering that will be applied to the QuerySet.

Returns:

  • (QuerySet)

    reference to this QuerySet.

See Also:

  • #order_by


28
29
30
# File 'lib/babik/queryset/mixins/sortable.rb', line 28

def order!(*order)
  order_by!(*order)
end

#order_by!(*order) ⇒ QuerySet

Sort QuerySet according to an order

Parameters:

  • order (Array, String, Hash)

    ordering that will be applied to the QuerySet. See Order#order_by.

Returns:

  • (QuerySet)

    reference to this QuerySet.



12
13
14
15
# File 'lib/babik/queryset/mixins/sortable.rb', line 12

def order_by!(*order)
  @_order = Babik::QuerySet::Order.new(@model, *order)
  self
end

#ordered?Boolean

Inform if there is an order for this QuerySet

Returns:

  • (Boolean)

    True if this QuerySet is ordered, false otherwise.



43
44
45
46
# File 'lib/babik/queryset/mixins/sortable.rb', line 43

def ordered?
  return true if @_order
  false
end