Module: Acts::AsOrderable::InstanceMethods
- Defined in:
- lib/acts_as_orderable.rb
Overview
Istance methods
Instance Method Summary collapse
- #move_down(steps = 1) ⇒ Object
- #move_up(steps = 1) ⇒ Object
-
#next ⇒ Object
Fetches previous element - if there’s no previous elements - return nil.
-
#previous ⇒ Object
Fetches previous element - if there’s no previous elements - return nil.
Instance Method Details
#move_down(steps = 1) ⇒ Object
64 65 66 |
# File 'lib/acts_as_orderable.rb', line 64 def move_down(steps = 1) move(-steps) end |
#move_up(steps = 1) ⇒ Object
60 61 62 |
# File 'lib/acts_as_orderable.rb', line 60 def move_up(steps = 1) move(steps) end |
#next ⇒ Object
Fetches previous element - if there’s no previous elements - return nil
56 57 58 |
# File 'lib/acts_as_orderable.rb', line 56 def next self.class.where("element_order > #{self.element_order} #{search_node_query}").order("element_order ASC").limit(1).first end |
#previous ⇒ Object
Fetches previous element - if there’s no previous elements - return nil
51 52 53 |
# File 'lib/acts_as_orderable.rb', line 51 def previous self.class.where("element_order < #{self.element_order} #{search_node_query}").order("element_order DESC").limit(1).first end |