module Babik::QuerySet::Bounded

Every QuerySet is bounded by its first and last items

Public Instance Methods

earliest(*order) click to toggle source

Return the first element given some order @param order [Array, String, Hash] ordering that will be applied to the QuerySet.

See {Babik::QuerySet::Sortable#order_by}.

@return [ActiveRecord::Base] First element according to the order.

# File lib/babik/queryset/mixins/bounded.rb, line 12
def earliest(*order)
  self.order_by(*order).first
end
first() click to toggle source

Return the first element of the QuerySet. @return [ActiveRecord::Base] First element of the QuerySet.

# File lib/babik/queryset/mixins/bounded.rb, line 18
def first
  self.all.first
end
last() click to toggle source

Return the last element of the QuerySet. @return [ActiveRecord::Base] Last element of the QuerySet.

# File lib/babik/queryset/mixins/bounded.rb, line 24
def last
  self.invert_order.all.first
end
latest(*order) click to toggle source

Return the last element given some order @param order [Array, String, Hash] ordering that will be applied to the QuerySet.

See {Babik::QuerySet::Sortable#order_by}.

@return [ActiveRecord::Base] Last element according to the order.

# File lib/babik/queryset/mixins/bounded.rb, line 32
def latest(*order)
  self.order_by(*order).last
end