Module: Babik::QuerySet::Bounded
- Included in:
- AbstractBase
- Defined in:
- lib/babik/queryset/mixins/bounded.rb
Overview
Every QuerySet is bounded by its first and last items
Instance Method Summary collapse
-
#earliest(*order) ⇒ ActiveRecord::Base
Return the first element given some order.
-
#first ⇒ ActiveRecord::Base
Return the first element of the QuerySet.
-
#last ⇒ ActiveRecord::Base
Return the last element of the QuerySet.
-
#latest(*order) ⇒ ActiveRecord::Base
Return the last element given some order.
Instance Method Details
#earliest(*order) ⇒ ActiveRecord::Base
Return the first element given some order
12 13 14 |
# File 'lib/babik/queryset/mixins/bounded.rb', line 12 def earliest(*order) self.order_by(*order).first end |
#first ⇒ ActiveRecord::Base
Return the first element of the QuerySet.
18 19 20 |
# File 'lib/babik/queryset/mixins/bounded.rb', line 18 def first self.all.first end |
#last ⇒ ActiveRecord::Base
Return the last element of the QuerySet.
24 25 26 |
# File 'lib/babik/queryset/mixins/bounded.rb', line 24 def last self.invert_order.all.first end |
#latest(*order) ⇒ ActiveRecord::Base
Return the last element given some order
32 33 34 |
# File 'lib/babik/queryset/mixins/bounded.rb', line 32 def latest(*order) self.order_by(*order).last end |