Module: ActiveRecord::Acts::List::InstanceMethods
- Defined in:
- lib/active_record/acts/list.rb
Overview
All the methods available to a record that has had acts_as_list
specified. Each method works by assuming the object to be the item in the list, so chapter.move_lower
would move that chapter lower in the list of all chapters. Likewise, chapter.first?
would return true if that chapter is the first in the list of all chapters.
Instance Method Summary collapse
- #decrement_position ⇒ Object
- #first? ⇒ Boolean
- #higher_item ⇒ Object
- #increment_position ⇒ Object
- #insert_at(position = 1) ⇒ Object
- #last? ⇒ Boolean
- #lower_item ⇒ Object
- #move_higher ⇒ Object
- #move_lower ⇒ Object
- #move_to_bottom ⇒ Object
- #move_to_top ⇒ Object
- #remove_from_list ⇒ Object
Instance Method Details
#decrement_position ⇒ Object
118 119 120 |
# File 'lib/active_record/acts/list.rb', line 118 def decrement_position update_attribute position_column, self.send(position_column).to_i - 1 end |
#first? ⇒ Boolean
122 123 124 |
# File 'lib/active_record/acts/list.rb', line 122 def first? self.send(position_column) == 1 end |
#higher_item ⇒ Object
130 131 132 133 134 |
# File 'lib/active_record/acts/list.rb', line 130 def higher_item self.class.find_first( "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" ) end |
#increment_position ⇒ Object
114 115 116 |
# File 'lib/active_record/acts/list.rb', line 114 def increment_position update_attribute position_column, self.send(position_column).to_i + 1 end |
#insert_at(position = 1) ⇒ Object
74 75 76 |
# File 'lib/active_record/acts/list.rb', line 74 def insert_at(position = 1) position == 1 ? add_to_list_top : insert_at_position(position) end |
#last? ⇒ Boolean
126 127 128 |
# File 'lib/active_record/acts/list.rb', line 126 def last? self.send(position_column) == bottom_position_in_list end |
#lower_item ⇒ Object
136 137 138 139 140 |
# File 'lib/active_record/acts/list.rb', line 136 def lower_item self.class.find_first( "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" ) end |
#move_higher ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/active_record/acts/list.rb', line 87 def move_higher return unless higher_item self.class.transaction do higher_item.increment_position decrement_position end end |
#move_lower ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/active_record/acts/list.rb', line 78 def move_lower return unless lower_item self.class.transaction do lower_item.decrement_position increment_position end end |
#move_to_bottom ⇒ Object
96 97 98 99 100 101 |
# File 'lib/active_record/acts/list.rb', line 96 def move_to_bottom self.class.transaction do decrement_positions_on_lower_items assume_bottom_position end end |
#move_to_top ⇒ Object
103 104 105 106 107 108 |
# File 'lib/active_record/acts/list.rb', line 103 def move_to_top self.class.transaction do increment_positions_on_higher_items assume_top_position end end |
#remove_from_list ⇒ Object
110 111 112 |
# File 'lib/active_record/acts/list.rb', line 110 def remove_from_list decrement_positions_on_lower_items end |