Sha256: 7f15206210bcbd039c9fda2b726ca87a06117265bff28b1b3cbc75b3672aff45
Contents?: true
Size: 1.46 KB
Versions: 6
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true module Mongoid module Orderable module Mixins module Listable def in_list?(field = nil) persisted? && !orderable_position(field).nil? end # Returns items above the current document. # Items with a position lower than this document's position. def previous_items(field = nil) field ||= default_orderable_field orderable_scope(field).lt(orderable_field(field) => send(field)) end alias prev_items previous_items # Returns items below the current document. # Items with a position greater than this document's position. def next_items(field = nil) field ||= default_orderable_field orderable_scope(field).gt(orderable_field(field) => send(field)) end # Returns the previous item in the list def previous_item(field = nil) field ||= default_orderable_field orderable_scope(field).where(orderable_field(field) => send(field) - 1).first end alias prev_item previous_item # Returns the next item in the list def next_item(field = nil) field ||= default_orderable_field orderable_scope(field).where(orderable_field(field) => send(field) + 1).first end def first?(field = nil) in_list?(field) && orderable_position(field) == orderable_top(field) end def last?(field = nil) in_list?(field) && orderable_position(field) == orderable_bottom(field) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems