Module: ActiveRecord::ActsAs::OrderableTable::InstanceMethods
- Defined in:
- lib/active_record/acts_as/orderable_table.rb
Instance Method Summary collapse
- #acts_ordinal_field ⇒ Object
- #acts_ordinal_value ⇒ Object
- #insert_at(position, ordinals_scope = nil) ⇒ Object
- #starts_from ⇒ Object
Instance Method Details
#acts_ordinal_field ⇒ Object
41 42 43 |
# File 'lib/active_record/acts_as/orderable_table.rb', line 41 def acts_ordinal_field self.class.ordinal_field end |
#acts_ordinal_value ⇒ Object
45 46 47 |
# File 'lib/active_record/acts_as/orderable_table.rb', line 45 def acts_ordinal_value self.send(acts_ordinal_field) end |
#insert_at(position, ordinals_scope = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/active_record/acts_as/orderable_table.rb', line 26 def insert_at(position, ordinals_scope = nil) return if position == acts_ordinal_value # if ordinal haven't changed # if new position is not occupied just take this ordinal unless self.class.where("#{acts_ordinal_field}": position).first update_attributes("#{acts_ordinal_field}": position) return end items = items_scoped(position, ordinals_scope) current_positions = items.map { |item| item.send(acts_ordinal_field) } reordered_positions = reorder_positions(position, current_positions) update_ordinals(items, reordered_positions) end |
#starts_from ⇒ Object
49 50 51 |
# File 'lib/active_record/acts_as/orderable_table.rb', line 49 def starts_from self.class.starts_from end |